public static List <MemberEntry <T> > GenerateList <T>(MemberOptions options) { PropertyInfo[] properties = (options & MemberOptions.Properties) == 0 ? new PropertyInfo[0] : typeof(T).GetProperties(bf); FieldInfo[] fields = (options & MemberOptions.Fields) == 0 ? new FieldInfo[0] : typeof(T).GetFields(bf); var members = properties.Where(p => p.GetIndexParameters().Length == 0).Cast <MemberInfo>() .Concat(fields.Cast <MemberInfo>()).OrderBy(e => e.MetadataToken).ToArray(); var result = members.Select(m => new MemberEntry <T>( m.Name, m, options.IsSet(MemberOptions.Getter | MemberOptions.Typed) ? ReflectionTools.CreateGetter <T>(m) : null, options.IsSet(MemberOptions.Getter | MemberOptions.Untyped) ? ReflectionTools.CreateGetterUntyped(typeof(T), m) : null, options.IsSet(MemberOptions.Setters | MemberOptions.Typed) ? ReflectionTools.CreateSetter <T>(m) : null, options.IsSet(MemberOptions.Setters | MemberOptions.Untyped) ? ReflectionTools.CreateSetterUntyped(typeof(T), m) : null )).ToList(); return(result); }
public static List <MemberEntry <T> > GenerateList <T>(MemberOptions options, Type?type = null) { if (type != null && !typeof(T).IsAssignableFrom(type)) { throw new InvalidOperationException($"Type {type} is assignable {typeof(T)}"); } var finalType = type ?? typeof(T); PropertyInfo[] properties = (options & MemberOptions.Properties) == 0 ? new PropertyInfo[0] : typeof(T).GetProperties(bf); FieldInfo[] fields = (options & MemberOptions.Fields) == 0 ? new FieldInfo[0] : typeof(T).GetFields(bf); var members = properties.Where(p => p.GetIndexParameters().Length == 0).Cast <MemberInfo>() .Concat(fields.Cast <MemberInfo>()).OrderBy(e => e.MetadataToken).ToArray(); var result = members.Select(m => new MemberEntry <T>( m.Name, m, options.IsSet(MemberOptions.Getter) ? ReflectionTools.CreateGetter <T, object?>(m) : null, options.IsSet(MemberOptions.Setters) ? ReflectionTools.CreateSetter <T, object?>(m) : null )).ToList(); return(result); }