diff options
18 files changed, 263 insertions, 100 deletions
diff --git a/Mono.Addins/ChangeLog b/Mono.Addins/ChangeLog index 6f58894..4df72a2 100644 --- a/Mono.Addins/ChangeLog +++ b/Mono.Addins/ChangeLog @@ -1,3 +1,32 @@ +2007-05-07 Lluis Sanchez Gual <lluis@novell.com> + + * Mono.Addins.Serialization/BinaryXmlReader.cs, + Mono.Addins.Description/NodeTypeAttribute.cs, + Mono.Addins.Description/AddinDescription.cs, + Mono.Addins.Description/ExtensionNodeType.cs, + Mono.Addins.Description/ExtensionPoint.cs, + Mono.Addins.Description/ConditionTypeDescription.cs, + Mono.Addins.Database/FileDatabase.cs: Added boolean property to be + set to avoid loading documentation information from add-in + descriptions (not needed at run-time). + * Mono.Addins.mdp, Mono.Addins/TypeExtensionNode.cs, + Mono.Addins/InstanceExtensionNode.cs, + Mono.Addins/ExtensionContext.cs, Mono.Addins/ExtensionNode.cs, + Makefile.am: Implemented new InstanceExtensionNode class. It is + almost like TypeExtensionNode, but it does not implement the actual + object creation, since CreateInstance is abstract. + TypeExtensionNode is now a subclass of InstanceExtensionNode which + creates an instance of the class specified in the 'class' + attribute. + * Mono.Addins/NodeAttributeAttribute.cs: Allow specifying the + description in the constructor. + * Mono.Addins.Description/ObjectDescriptionCollection.cs: New AddRange + method. + * Mono.Addins.Description/ExtensionNodeDescription.cs: Added method for + getting the path to a node. Added some helper properties. + * Mono.Addins.Database/AddinScanner.cs: Properly scan node types + declared in node sets or declared as children of other nodes. + 2007-05-04 Lluis Sanchez Gual <lluis@novell.com> * Mono.Addins.mdp: Updated. diff --git a/Mono.Addins/Makefile.am b/Mono.Addins/Makefile.am index bd2915a..a6877c1 100644 --- a/Mono.Addins/Makefile.am +++ b/Mono.Addins/Makefile.am @@ -72,6 +72,7 @@ FILES = \ Mono.Addins/ExtensionPointAttribute.cs \ Mono.Addins/ExtensionTree.cs \ Mono.Addins/GettextCatalog.cs \ + Mono.Addins/InstanceExtensionNode.cs \ Mono.Addins/IProgressStatus.cs \ Mono.Addins/MissingDependencyException.cs \ Mono.Addins/NodeAttributeAttribute.cs \ diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs index 91a3a65..207896d 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs @@ -486,6 +486,10 @@ namespace Mono.Addins.Database // Extension node types may have child nodes declared as attributes. Find them. Hashtable internalNodeSets = new Hashtable (); + + foreach (ExtensionNodeSet eset in config.ExtensionNodeSets) + ScanNodeSet (config, eset, assemblies, internalNodeSets); + foreach (ExtensionPoint ep in config.ExtensionPoints) { ScanNodeSet (config, ep.NodeSet, assemblies, internalNodeSets); } @@ -630,72 +634,68 @@ namespace Mono.Addins.Database void ScanNodeSet (AddinDescription config, ExtensionNodeSet nset, ArrayList assemblies, Hashtable internalNodeSets) { - foreach (ExtensionNodeType nt in nset.NodeTypes) { - if (nt.TypeName.Length == 0) - nt.TypeName = "Mono.Addins.TypeExtensionNode"; - - Type ntype = FindAddinType (nt.TypeName, assemblies); - if (ntype == null) - continue; - - // Add type information declared with attributes in the code - ExtensionNodeAttribute nodeAtt = (ExtensionNodeAttribute) Attribute.GetCustomAttribute (ntype, typeof(ExtensionNodeAttribute), false); - if (nodeAtt != null) { - if (nt.Id.Length == 0 && nodeAtt.NodeName.Length > 0) - nt.Id = nodeAtt.NodeName; - if (nt.Description.Length == 0 && nodeAtt.Description.Length > 0) - nt.Description = nodeAtt.Description; - } else { - // Use the node type name as default name - if (nt.Id.Length == 0) - nt.Id = ntype.Name; - } - - // Add information about attributes - object[] fieldAtts = ntype.GetCustomAttributes (typeof(NodeAttributeAttribute), true); - foreach (NodeAttributeAttribute fatt in fieldAtts) { + foreach (ExtensionNodeType nt in nset.NodeTypes) + ScanNodeType (config, nt, assemblies, internalNodeSets); + } + + void ScanNodeType (AddinDescription config, ExtensionNodeType nt, ArrayList assemblies, Hashtable internalNodeSets) + { + if (nt.TypeName.Length == 0) + nt.TypeName = "Mono.Addins.TypeExtensionNode"; + + Type ntype = FindAddinType (nt.TypeName, assemblies); + if (ntype == null) + return; + + // Add type information declared with attributes in the code + ExtensionNodeAttribute nodeAtt = (ExtensionNodeAttribute) Attribute.GetCustomAttribute (ntype, typeof(ExtensionNodeAttribute), true); + if (nodeAtt != null) { + if (nt.Id.Length == 0 && nodeAtt.NodeName.Length > 0) + nt.Id = nodeAtt.NodeName; + if (nt.Description.Length == 0 && nodeAtt.Description.Length > 0) + nt.Description = nodeAtt.Description; + } else { + // Use the node type name as default name + if (nt.Id.Length == 0) + nt.Id = ntype.Name; + } + + // Add information about attributes + object[] fieldAtts = ntype.GetCustomAttributes (typeof(NodeAttributeAttribute), true); + foreach (NodeAttributeAttribute fatt in fieldAtts) { + NodeTypeAttribute natt = new NodeTypeAttribute (); + natt.Name = fatt.Name; + natt.Required = fatt.Required; + if (fatt.Type != null) + natt.Type = fatt.Type.FullName; + if (fatt.Description.Length > 0) + natt.Description = fatt.Description; + nt.Attributes.Add (natt); + } + + // Check if the type has NodeAttribute attributes applied to fields. + foreach (FieldInfo field in ntype.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { + NodeAttributeAttribute fatt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute)); + if (fatt != null) { NodeTypeAttribute natt = new NodeTypeAttribute (); - natt.Name = fatt.Name; - natt.Required = fatt.Required; - if (fatt.Type != null) - natt.Type = fatt.Type.FullName; + if (fatt.Name.Length > 0) + natt.Name = fatt.Name; + else + natt.Name = field.Name; if (fatt.Description.Length > 0) natt.Description = fatt.Description; + natt.Type = field.FieldType.FullName; + natt.Required = fatt.Required; nt.Attributes.Add (natt); } - - // Check if the type has NodeAttribute attributes applied to fields. - foreach (FieldInfo field in ntype.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { - NodeAttributeAttribute fatt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute)); - if (fatt != null) { - NodeTypeAttribute natt = new NodeTypeAttribute (); - if (fatt.Name.Length > 0) - natt.Name = fatt.Name; - else - natt.Name = field.Name; - if (fatt.Description.Length > 0) - natt.Description = fatt.Description; - natt.Type = field.FieldType.FullName; - natt.Required = fatt.Required; - nt.Attributes.Add (natt); - } - } - - // Check if the extension type allows children by looking for [ExtensionNodeChild] attributes. - // First of all, look in the internalNodeSets hashtable, which is being used as cache - - string childSet = (string) internalNodeSets [nt.TypeName]; - if (childSet != null) { - if (childSet.Length == 0) { - // The extension type does not declare children. - continue; - } - // The extension type can have children. The allowed children are - // defined in this extension set. - nt.NodeSets.Add (childSet); - continue; - } - + } + + // Check if the extension type allows children by looking for [ExtensionNodeChild] attributes. + // First of all, look in the internalNodeSets hashtable, which is being used as cache + + string childSet = (string) internalNodeSets [nt.TypeName]; + + if (childSet == null) { object[] ats = ntype.GetCustomAttributes (typeof(ExtensionNodeChildAttribute), true); if (ats.Length > 0) { // Create a new node set for this type. It is necessary to create a new node set @@ -719,6 +719,18 @@ namespace Mono.Addins.Database ScanNodeSet (config, internalSet, assemblies, internalNodeSets); } } + else { + if (childSet.Length == 0) { + // The extension type does not declare children. + return; + } + // The extension type can have children. The allowed children are + // defined in this extension set. + nt.NodeSets.Add (childSet); + return; + } + + ScanNodeSet (config, nt, assemblies, internalNodeSets); } string GetBaseTypeNameList (Type type) diff --git a/Mono.Addins/Mono.Addins.Database/FileDatabase.cs b/Mono.Addins/Mono.Addins.Database/FileDatabase.cs index 56a5cd4..ee942c9 100644 --- a/Mono.Addins/Mono.Addins.Database/FileDatabase.cs +++ b/Mono.Addins/Mono.Addins.Database/FileDatabase.cs @@ -43,6 +43,7 @@ namespace Mono.Addins.Database Hashtable foldersToUpdate; Hashtable deletedFiles; IDisposable transactionLock; + bool ignoreDesc; public FileDatabase (string rootDirectory) { @@ -57,6 +58,12 @@ namespace Mono.Addins.Database get { return Path.Combine (rootDirectory, "fdb-update-lock"); } } + // Returns 'true' if description data must be ignored when reading the contents of a file + public bool IgnoreDescriptionData { + get { return ignoreDesc; } + set { ignoreDesc = value; } + } + public bool BeginTransaction () { if (inTransaction) diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index 68ded31..6059f7f 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -60,6 +60,7 @@ namespace Mono.Addins.Description string sourceAddinFile; bool isroot; bool hasUserId; + bool canWrite = true; ModuleDescription mainModule; ModuleCollection optionalModules; @@ -164,7 +165,7 @@ namespace Mono.Addins.Description set { basePath = value; } } - internal bool IsRoot { + public bool IsRoot { get { return isroot; } set { isroot = value; } } @@ -352,6 +353,9 @@ namespace Mono.Addins.Description void SaveXml () { + if (!canWrite) + throw new InvalidOperationException ("Can't write incomplete description."); + XmlElement elem; if (configDoc == null) { @@ -470,6 +474,7 @@ namespace Mono.Addins.Description if (description != null) { description.FileName = configFile; description.fromBinaryFile = true; + description.canWrite = !fdb.IgnoreDescriptionData; } return description; } @@ -481,6 +486,7 @@ namespace Mono.Addins.Description if (description != null) { description.FileName = fileName; description.fromBinaryFile = true; + description.canWrite = !fdb.IgnoreDescriptionData; } return description; } @@ -493,12 +499,16 @@ namespace Mono.Addins.Description internal void SaveBinary (FileDatabase fdb) { + if (!canWrite) + throw new InvalidOperationException ("Can't write incomplete description."); fdb.WriteSharedObject (AddinFile, FileName, typeMap, this); // BinaryXmlReader.DumpFile (configFile); } internal void SaveHostBinary (FileDatabase fdb, string basePath) { + if (!canWrite) + throw new InvalidOperationException ("Can't write incomplete description."); if (!fromBinaryFile) FileName = null; FileName = fdb.WriteSharedObject (basePath, AddinId, ".mroot", AddinFile, FileName, typeMap, this); diff --git a/Mono.Addins/Mono.Addins.Description/ConditionTypeDescription.cs b/Mono.Addins/Mono.Addins.Description/ConditionTypeDescription.cs index 6ac34e5..84039f8 100644 --- a/Mono.Addins/Mono.Addins.Description/ConditionTypeDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/ConditionTypeDescription.cs @@ -98,7 +98,8 @@ namespace Mono.Addins.Description { Id = reader.ReadStringValue ("Id"); TypeName = reader.ReadStringValue ("TypeName"); - Description = reader.ReadStringValue ("Description"); + if (!reader.IgnoreDescriptionData) + Description = reader.ReadStringValue ("Description"); AddinId = reader.ReadStringValue ("AddinId"); } } diff --git a/Mono.Addins/Mono.Addins.Description/ExtensionNodeDescription.cs b/Mono.Addins/Mono.Addins.Description/ExtensionNodeDescription.cs index e9fb3a4..3381304 100644 --- a/Mono.Addins/Mono.Addins.Description/ExtensionNodeDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/ExtensionNodeDescription.cs @@ -78,6 +78,18 @@ namespace Mono.Addins.Description return null; } + public string GetParentPath () + { + if (Parent is Extension) + return ((Extension)Parent).Path; + else if (Parent is ExtensionNodeDescription) { + ExtensionNodeDescription pn = (ExtensionNodeDescription) Parent; + return pn.GetParentPath () + "/" + pn.Id; + } + else + return string.Empty; + } + internal override void Verify (string location, StringCollection errors) { if (nodeName == null || nodeName.Length == 0) @@ -91,6 +103,17 @@ namespace Mono.Addins.Description public string Id { get { return GetAttribute ("id"); } + set { SetAttribute ("id", value); } + } + + public string InsertAfter { + get { return GetAttribute ("insertafter"); } + set { SetAttribute ("insertafter", value); } + } + + public string InsertBefore { + get { return GetAttribute ("insertbefore"); } + set { SetAttribute ("insertbefore", value); } } public bool IsCondition { diff --git a/Mono.Addins/Mono.Addins.Description/ExtensionNodeType.cs b/Mono.Addins/Mono.Addins.Description/ExtensionNodeType.cs index 712975d..5054e9e 100644 --- a/Mono.Addins/Mono.Addins.Description/ExtensionNodeType.cs +++ b/Mono.Addins/Mono.Addins.Description/ExtensionNodeType.cs @@ -174,9 +174,11 @@ namespace Mono.Addins.Description base.Read (reader); typeName = reader.ReadStringValue ("typeName"); objectTypeName = reader.ReadStringValue ("objectTypeName"); - description = reader.ReadStringValue ("description"); + if (!reader.IgnoreDescriptionData) + description = reader.ReadStringValue ("description"); addinId = reader.ReadStringValue ("addinId"); - attributes = (NodeTypeAttributeCollection) reader.ReadValue ("Attributes", new NodeTypeAttributeCollection (this)); + if (!reader.IgnoreDescriptionData) + attributes = (NodeTypeAttributeCollection) reader.ReadValue ("Attributes", new NodeTypeAttributeCollection (this)); } } } diff --git a/Mono.Addins/Mono.Addins.Description/ExtensionPoint.cs b/Mono.Addins/Mono.Addins.Description/ExtensionPoint.cs index 5f7c442..a80072e 100644 --- a/Mono.Addins/Mono.Addins.Description/ExtensionPoint.cs +++ b/Mono.Addins/Mono.Addins.Description/ExtensionPoint.cs @@ -221,7 +221,8 @@ namespace Mono.Addins.Description { path = reader.ReadStringValue ("path"); name = reader.ReadStringValue ("name"); - description = reader.ReadStringValue ("description"); + if (!reader.IgnoreDescriptionData) + description = reader.ReadStringValue ("description"); rootAddin = reader.ReadStringValue ("rootAddin"); addins = (StringCollection) reader.ReadValue ("addins", new StringCollection ()); nodeSet = (ExtensionNodeSet) reader.ReadValue ("NodeSet"); diff --git a/Mono.Addins/Mono.Addins.Description/NodeTypeAttribute.cs b/Mono.Addins/Mono.Addins.Description/NodeTypeAttribute.cs index e02d553..1a33441 100644 --- a/Mono.Addins/Mono.Addins.Description/NodeTypeAttribute.cs +++ b/Mono.Addins/Mono.Addins.Description/NodeTypeAttribute.cs @@ -109,7 +109,8 @@ namespace Mono.Addins.Description name = reader.ReadStringValue ("name"); type = reader.ReadStringValue ("type"); required = reader.ReadBooleanValue ("required"); - description = reader.ReadStringValue ("description"); + if (!reader.IgnoreDescriptionData) + description = reader.ReadStringValue ("description"); } } } diff --git a/Mono.Addins/Mono.Addins.Description/ObjectDescriptionCollection.cs b/Mono.Addins/Mono.Addins.Description/ObjectDescriptionCollection.cs index e97cfdd..faac4f3 100644 --- a/Mono.Addins/Mono.Addins.Description/ObjectDescriptionCollection.cs +++ b/Mono.Addins/Mono.Addins.Description/ObjectDescriptionCollection.cs @@ -52,6 +52,12 @@ namespace Mono.Addins.Description List.Add (ep); } + public void AddRange (ObjectDescriptionCollection collection) + { + foreach (ObjectDescription ob in collection) + Add (ob); + } + public void Remove (ObjectDescription ep) { List.Remove (ep); diff --git a/Mono.Addins/Mono.Addins.Serialization/BinaryXmlReader.cs b/Mono.Addins/Mono.Addins.Serialization/BinaryXmlReader.cs index c0b71e3..7fd5650 100644 --- a/Mono.Addins/Mono.Addins.Serialization/BinaryXmlReader.cs +++ b/Mono.Addins/Mono.Addins.Serialization/BinaryXmlReader.cs @@ -52,6 +52,7 @@ namespace Mono.Addins.Serialization ArrayList stringTable = new ArrayList (); BinaryXmlTypeMap typeMap; object contextData; + bool ignoreDesc; public BinaryXmlReader (Stream stream, BinaryXmlTypeMap typeMap) { @@ -70,6 +71,12 @@ namespace Mono.Addins.Serialization set { contextData = value; } } + // Returns 'true' if description data must be ignored when reading the contents of a file + public bool IgnoreDescriptionData { + get { return ignoreDesc; } + set { ignoreDesc = value; } + } + void ReadNext () { int b = reader.BaseStream.ReadByte (); diff --git a/Mono.Addins/Mono.Addins.mdp b/Mono.Addins/Mono.Addins.mdp index 6037b46..8d27175 100644 --- a/Mono.Addins/Mono.Addins.mdp +++ b/Mono.Addins/Mono.Addins.mdp @@ -80,6 +80,7 @@ <File name="./Mono.Addins/AddinRootAttribute.cs" subtype="Code" buildaction="Compile" /> <File name="./ChangeLog" subtype="Code" buildaction="Nothing" /> <File name="./Mono.Addins.Description/ExtensionNodeTypeCollection.cs" subtype="Code" buildaction="Compile" /> + <File name="./Mono.Addins/InstanceExtensionNode.cs" subtype="Code" buildaction="Compile" /> </Contents> <References> <ProjectReference type="Gac" localcopy="True" refto="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> diff --git a/Mono.Addins/Mono.Addins/ExtensionContext.cs b/Mono.Addins/Mono.Addins/ExtensionContext.cs index 9477f1d..9847807 100644 --- a/Mono.Addins/Mono.Addins/ExtensionContext.cs +++ b/Mono.Addins/Mono.Addins/ExtensionContext.cs @@ -715,9 +715,9 @@ namespace Mono.Addins public object ExtensionObject { get { - TypeExtensionNode tnode = node as TypeExtensionNode; + InstanceExtensionNode tnode = node as InstanceExtensionNode; if (tnode == null) - throw new InvalidOperationException ("Node is not a TypeExtensionNode"); + throw new InvalidOperationException ("Node is not an InstanceExtensionNode"); return tnode.GetInstance (); } } diff --git a/Mono.Addins/Mono.Addins/ExtensionNode.cs b/Mono.Addins/Mono.Addins/ExtensionNode.cs index 477215f..b67a040 100644 --- a/Mono.Addins/Mono.Addins/ExtensionNode.cs +++ b/Mono.Addins/Mono.Addins/ExtensionNode.cs @@ -161,9 +161,9 @@ namespace Mono.Addins ArrayList list = new ArrayList (ChildNodes.Count); for (int n=0; n<ChildNodes.Count; n++) { - TypeExtensionNode node = ChildNodes [n] as TypeExtensionNode; + InstanceExtensionNode node = ChildNodes [n] as InstanceExtensionNode; if (node == null) { - AddinManager.ReportError ("Error while getting object for node in path '" + Path + "'. Extension node is not a subclass of TypeExtensionNode.", null, null, false); + AddinManager.ReportError ("Error while getting object for node in path '" + Path + "'. Extension node is not a subclass of InstanceExtensionNode.", null, null, false); continue; } diff --git a/Mono.Addins/Mono.Addins/InstanceExtensionNode.cs b/Mono.Addins/Mono.Addins/InstanceExtensionNode.cs new file mode 100644 index 0000000..5d7afc6 --- /dev/null +++ b/Mono.Addins/Mono.Addins/InstanceExtensionNode.cs @@ -0,0 +1,63 @@ +// +// InstanceExtensionNode.cs +// +// Author: +// Lluis Sanchez Gual +// +// Copyright (C) 2007 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + + +using System; + +namespace Mono.Addins +{ + public abstract class InstanceExtensionNode: ExtensionNode + { + object cachedInstance; + + public object GetInstance (Type expectedType) + { + object ob = GetInstance (); + if (!expectedType.IsInstanceOfType (ob)) + throw new InvalidOperationException (string.Format ("Expected subclass of type '{0}'. Found '{1}'.", expectedType, ob.GetType ())); + return ob; + } + + public object GetInstance () + { + if (cachedInstance == null) + cachedInstance = CreateInstance (); + return cachedInstance; + } + + public object CreateInstance (Type expectedType) + { + object ob = CreateInstance (); + if (!expectedType.IsInstanceOfType (ob)) + throw new InvalidOperationException (string.Format ("Expected subclass of type '{0}'. Found '{1}'.", expectedType, ob.GetType ())); + return ob; + } + + public abstract object CreateInstance (); + } +} diff --git a/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs b/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs index bc294c8..7f175ba 100644 --- a/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs +++ b/Mono.Addins/Mono.Addins/NodeAttributeAttribute.cs @@ -44,26 +44,48 @@ namespace Mono.Addins } public NodeAttributeAttribute (string name) - :this (name, false) + :this (name, false, null) + { + } + + public NodeAttributeAttribute (string name, string description) + :this (name, false, description) { } public NodeAttributeAttribute (string name, bool required) + : this (name, required, null) + { + } + + public NodeAttributeAttribute (string name, bool required, string description) { this.name = name; this.required = required; + this.description = description; } public NodeAttributeAttribute (string name, Type type) - : this (name, type, false) + : this (name, type, false, null) + { + } + + public NodeAttributeAttribute (string name, Type type, string description) + : this (name, type, false, description) { } public NodeAttributeAttribute (string name, Type type, bool required) + : this (name, type, false, null) + { + } + + public NodeAttributeAttribute (string name, Type type, bool required, string description) { this.name = name; this.type = type; this.required = required; + this.description = description; } public string Name { diff --git a/Mono.Addins/Mono.Addins/TypeExtensionNode.cs b/Mono.Addins/Mono.Addins/TypeExtensionNode.cs index 03c84d5..cb4aa70 100644 --- a/Mono.Addins/Mono.Addins/TypeExtensionNode.cs +++ b/Mono.Addins/Mono.Addins/TypeExtensionNode.cs @@ -32,11 +32,11 @@ using System.Xml; namespace Mono.Addins { - [ExtensionNode ("Type")] - public class TypeExtensionNode: ExtensionNode + [ExtensionNode ("Type", Description="Specifies a class that will be used to create an extension object. The name of the class can be provided in the 'class' attribute. If 'class' is not provided, the name will be taken from the 'id' attribute")] + [NodeAttribute ("class", typeof(Type), false, Description="Name of the class")] + public class TypeExtensionNode: InstanceExtensionNode { string typeName; - object cachedInstance; internal protected override void Read (NodeElement elem) { @@ -48,30 +48,7 @@ namespace Mono.Addins typeName = elem.GetAttribute ("id"); } - public object GetInstance (Type expectedType) - { - object ob = GetInstance (); - if (!expectedType.IsInstanceOfType (ob)) - throw new InvalidOperationException (string.Format ("Expected subclass of type '{0}'. Found '{1}'.", expectedType, ob.GetType ())); - return ob; - } - - public object GetInstance () - { - if (cachedInstance == null) - cachedInstance = CreateInstance (); - return cachedInstance; - } - - public object CreateInstance (Type expectedType) - { - object ob = CreateInstance (); - if (!expectedType.IsInstanceOfType (ob)) - throw new InvalidOperationException (string.Format ("Expected subclass of type '{0}'. Found '{1}'.", expectedType, ob.GetType ())); - return ob; - } - - public virtual object CreateInstance () + public override object CreateInstance () { if (typeName.Length == 0) throw new InvalidOperationException ("Type name not specified."); |