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); }
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; }
bool InitializeNodeType(ExtensionNodeType ntype) { RuntimeAddin p = AddinManager.SessionService.GetAddin(ntype.AddinId); if (p == null) { if (!AddinManager.SessionService.IsAddinLoaded(ntype.AddinId)) { if (!AddinManager.SessionService.LoadAddin(null, ntype.AddinId, false)) { return(false); } p = AddinManager.SessionService.GetAddin(ntype.AddinId); if (p == null) { AddinManager.ReportError("Add-in not found", ntype.AddinId, null, false); return(false); } } } // If no type name is provided, use TypeExtensionNode by default if (ntype.TypeName == null || ntype.TypeName.Length == 0) { ntype.Type = typeof(TypeExtensionNode); return(true); } ntype.Type = p.GetType(ntype.TypeName, false); if (ntype.Type == null) { AddinManager.ReportError("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false); return(false); } Hashtable fields = new Hashtable(); // Check if the type has NodeAttribute attributes applied to fields. Type type = ntype.Type; 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 fdata = new ExtensionNodeType.FieldData(); fdata.Field = field; fdata.Required = at.Required; fdata.Localizable = at.Localizable; string name; if (at.Name != null && at.Name.Length > 0) { name = at.Name; } else { name = field.Name; } fields [name] = fdata; } } type = type.BaseType; } if (fields.Count > 0) { ntype.Fields = fields; } return(true); }
bool InitializeNodeType(ExtensionNodeType ntype) { RuntimeAddin p = AddinManager.SessionService.GetAddin(ntype.AddinId); if (p == null) { if (!AddinManager.SessionService.IsAddinLoaded(ntype.AddinId)) { if (!AddinManager.SessionService.LoadAddin(null, ntype.AddinId, false)) { return(false); } p = AddinManager.SessionService.GetAddin(ntype.AddinId); if (p == null) { AddinManager.ReportError("Add-in not found", ntype.AddinId, null, false); return(false); } } } // If no type name is provided, use TypeExtensionNode by default if (ntype.TypeName == null || ntype.TypeName.Length == 0) { ntype.Type = typeof(TypeExtensionNode); return(true); } ntype.Type = p.GetType(ntype.TypeName, false); if (ntype.Type == null) { AddinManager.ReportError("Extension node type '" + ntype.TypeName + "' not found.", ntype.AddinId, null, false); return(false); } Hashtable fields = new Hashtable(); ArrayList reqFields = new ArrayList(); // Check if the type has NodeAttribute attributes applied to fields. foreach (FieldInfo field in ntype.Type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { NodeAttributeAttribute at = (NodeAttributeAttribute)Attribute.GetCustomAttribute(field, typeof(NodeAttributeAttribute), true); if (at != null) { string name; if (at.Name != null && at.Name.Length > 0) { name = at.Name; } else { name = field.Name; } if (at.Required) { reqFields.Add(name); } fields [name] = field; } } if (fields.Count > 0) { ntype.Fields = fields; if (reqFields.Count > 0) { ntype.RequiredFields = (string[])reqFields.ToArray(typeof(string)); } } return(true); }