private static void BuildFieldList(Type type, IList <FieldInfo> list, FieldScope scope) { if (type.IsValueType && ((scope & FieldScope.Direct) != 0)) { FieldInfo fieldinfo = type.GetField("Value"); if (fieldinfo != null) { list.Add(fieldinfo); } return; } if (type.BaseType != null && type.BaseType != typeof(object) && type.BaseType != typeof(SEntity)) { BuildFieldList(type.BaseType, list, scope); } FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); FieldInfo[] sorted = new FieldInfo[fields.Length]; if ((scope & FieldScope.Direct) != 0) { foreach (FieldInfo field in fields) { if (field.IsDefined(typeof(DataMemberAttribute), false)) { DataMemberAttribute attr = (DataMemberAttribute)field.GetCustomAttributes(typeof(DataMemberAttribute), false)[0]; sorted[attr.Order] = field; } } foreach (FieldInfo sort in sorted) { if (sort != null) { list.Add(sort); } } } if ((scope & FieldScope.Inverse) != 0) { foreach (FieldInfo field in fields) { if (field.IsDefined(typeof(DataLookupAttribute), false)) { // sort order... list.Add(field); } } } }
private static void BuildFieldList(Type type, IList<FieldInfo> list, FieldScope scope) { if (type.IsValueType && ((scope & FieldScope.Direct)!=0)) { FieldInfo fieldinfo = type.GetField("Value"); if (fieldinfo != null) { list.Add(fieldinfo); } return; } if (type.BaseType != null && type.BaseType != typeof(object) && type.BaseType != typeof(SEntity)) { BuildFieldList(type.BaseType, list, scope); } FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); FieldInfo[] sorted = new FieldInfo[fields.Length]; if ((scope & FieldScope.Direct) != 0) { foreach (FieldInfo field in fields) { if (field.IsDefined(typeof(DataMemberAttribute), false)) { DataMemberAttribute attr = (DataMemberAttribute)field.GetCustomAttributes(typeof(DataMemberAttribute), false)[0]; sorted[attr.Order] = field; } } foreach (FieldInfo sort in sorted) { if (sort != null) { list.Add(sort); } } } if ((scope & FieldScope.Inverse) != 0) { foreach (FieldInfo field in fields) { if (field.IsDefined(typeof(DataLookupAttribute), false)) { // sort order... list.Add(field); } } } }