ExtensionNodeType.FieldData CreateFieldData(MemberInfo member, NodeAttributeAttribute at, out string name, ref ExtensionNodeType.FieldData boundAttributeType) { ExtensionNodeType.FieldData fdata = new ExtensionNodeType.FieldData(); fdata.Member = member; fdata.Required = at.Required; fdata.Localizable = at.Localizable; if (at.Name != null && at.Name.Length > 0) { name = at.Name; } else { name = member.Name; } if (typeof(CustomExtensionAttribute).IsAssignableFrom(fdata.MemberType)) { if (boundAttributeType != null) { throw new InvalidOperationException("Type '" + member.DeclaringType + "' has two members bound to a custom attribute. There can be only one."); } boundAttributeType = fdata; return(null); } return(fdata); }
Dictionary <string, ExtensionNodeType.FieldData> GetMembersMap(Type type, out ExtensionNodeType.FieldData boundAttributeType) { string fname; Dictionary <string, ExtensionNodeType.FieldData> fields = new Dictionary <string, ExtensionNodeType.FieldData> (); boundAttributeType = null; while (type != typeof(object) && type != null) { foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { NodeAttributeAttribute at = (NodeAttributeAttribute)Attribute.GetCustomAttribute(field, typeof(NodeAttributeAttribute), true); if (at != null) { ExtensionNodeType.FieldData fd = CreateFieldData(field, at, out fname, ref boundAttributeType); if (fd != null) { fields [fname] = fd; } } } foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { NodeAttributeAttribute at = (NodeAttributeAttribute)Attribute.GetCustomAttribute(prop, typeof(NodeAttributeAttribute), true); if (at != null) { ExtensionNodeType.FieldData fd = CreateFieldData(prop, at, out fname, ref boundAttributeType); if (fd != null) { fields [fname] = fd; } } } type = type.BaseType; } return(fields); }