'T' does not contain a definition

前端 未结 3 1229
灰色年华
灰色年华 2020-12-17 17:28

Is it possible to do the following (If so I can\'t seem to get it working.. forgoing constraints for the moment)...

If the type (because it\'s ommitted) is inferred,

3条回答
  •  没有蜡笔的小新
    2020-12-17 18:06

    If you can't get make an interface for your type (or a common one between several types):

    private void GetGenericTableContant(ref StringBuilder outputTableContent, T item, Func lineNumberAccessor)
    {
         outputTableContent.Append("" + lineNumberAccessor(item) + "");
    }
    

    Usage:

    GetGenericTableContent(ref outputTableContent, item, x => x.SpreadsheetLineNumbers);
    

    (Or you could just pass the SpreadSheetLineNumbers property if you don't really need the item reference in your method: void GetGenericTableContant(ref StringBuilder outputTableContent, string lineNumbers))

提交回复
热议问题