Ejemplo n.º 1
0
        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.
			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) {
					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;
				}
			}
			if (fields.Count > 0)
				ntype.Fields = fields;
				
			return true;
		}