I'm creating a generic grid, but have a problem that the foreign key column cannot use memberName and load datasource from url. Please help me, thanks.
1 Answer, 1 is accepted
0
Mihaela
Telerik team
answered on 22 Jun 2021, 07:26 AM
Hi Nguyen,
At this point, the "ForeignKey" method supports only predicates. However, I have created a feature request with a vote on your behalf asking to implement a String overload:
internal static MemberInfo FindPropertyOrField(this Type type, string memberName, bool staticAccess) { BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly | (staticAccess ? BindingFlags.Static : BindingFlags.Instance); foreach (Type t in type.SelfAndBaseTypes()) { var members = t.GetProperties(flags) .OfType<MemberInfo>() .Concat(t.GetFields(flags).OfType<MemberInfo>()) .Where(m => m.Name.IsCaseInsensitiveEqual(memberName)).ToArray(); if (members.Length != 0) return members[0]; } return null; }
internal static IEnumerable<Type> SelfAndBaseTypes(this Type type) { if (type.IsInterface()) { List<Type> types = new List<Type>(); AddInterface(types, type); return types; } return SelfAndBaseClasses(type); }
internal static IEnumerable<Type> SelfAndBaseClasses(this Type type) { while (type != null) { yield return type; type = type.GetTypeInfo().BaseType; } }
static void AddInterface(List<Type> types, Type type) { if (!types.Contains(type)) { types.Add(type); foreach (Type t in type.GetInterfaces()) AddInterface(types, t); } }