
/// <summary> /// Binds all dataObjects e.g. IPersonList,IDepartmentList,ItopicList... and creates a visual List of elements to display in the ElementTextBox /// </summary> /// <typeparam name="T">Type of dataObject in the dataObjects List</typeparam> /// <typeparam name="TProperty">value for the Type specifIEd by the TResult paramter</typeparam> /// <param name="dataObjects">entity from database the user wants to show in the ElementTextBox</param> /// <param name="selectordisplayMember">The property like Firstname that is shown as the elements text</param> /// <param name="selectorSortMember">The property like SortID that is used to pre-sort the dataObjects so the elements appear in the order before they were saved</param> public voID BindElements<T,TProperty>(IEnumerable<T> dataObjects,Func<T,TProperty> selectordisplayMember,TProperty> selectorSortMember) { if (dataObjects != null) { var sortedDataObjects = from d in dataObjects orderby selectorSortMember(d) ascending select d; Paragraph para = new Paragraph(); foreach (T item in dataObjects) { TProperty displayMemberValue = selectordisplayMember(item); InlineUIContainer uiContainer = ElementList.CreateElementContainer(displayMemberValue); para.Inlines.Add(uiContainer); } Flowdocument flowDoc = new Flowdocument(para); ElementList.document = flowDoc; } } 这工作:ElementUserControl.BindElements(customers,c => c.CustomerID);
但是当我添加第3个参数时:
ElementUserControl.BindElements(customers,c => c.CustomerID,c => c.sortID);
它不再起作用了?
解决方法 问题在于你引入的歧义,因为第二个和第三个参数都可以推断TProperty.您可能想尝试引入第三个泛型类型参数,以便您拥有适用于您的用例的TdisplayProperty和TSortProperty. 总结以上是内存溢出为你收集整理的无法推断C#中的类型,必须明确设置吗?全部内容,希望文章能够帮你解决无法推断C#中的类型,必须明确设置吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)