2
// TypeExtensionNode.cs
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
/// An extension node which specifies a type.
39
/// This class is a kind of Mono.Addins.ExtensionNode which can be used to register
40
/// types in an extension point. This is a very common case: a host application
41
/// defines an interface, and add-ins create classes that implement that interface.
42
/// The host will define an extension point which will use TypeExtensionNode as node
43
/// type. Add-ins will register the classes they implement in that extension point.
45
/// When the nodes of an extension point are of type TypeExtensionNode it is then
46
/// possible to use query methods such as AddinManager.GetExtensionObjects(string),
47
/// which will get all nodes in the provided extension path and will create an object
50
/// When declaring extension nodes in an add-in manifest, the class names can be
51
/// specified using the 'class' or 'type' attribute. If none of those attributes is
52
/// provided, the class name will be taken from the 'id' attribute.
54
/// TypeExtensionNode is the default extension type used when no type is provided
55
/// in the definition of an extension point.
57
[ExtensionNode ("Type", Description="Specifies a class that will be used to create an extension object.")]
58
[NodeAttribute ("class", typeof(Type), false, ContentType = ContentType.Class, Description="Name of the class. If a value is not provided, the class name will be taken from the 'id' attribute")]
59
public class TypeExtensionNode: InstanceExtensionNode
65
/// Reads the extension node data
67
/// <param name='elem'>
68
/// The element containing the extension data
71
/// This method can be overriden to provide a custom method for reading extension node data from an element.
72
/// The default implementation reads the attributes if the element and assigns the values to the fields
73
/// and properties of the extension node that have the corresponding [NodeAttribute] decoration.
75
internal protected override void Read (NodeElement elem)
78
typeName = elem.GetAttribute ("type");
79
if (typeName.Length == 0)
80
typeName = elem.GetAttribute ("class");
81
if (typeName.Length == 0)
82
typeName = elem.GetAttribute ("id");
86
/// Creates a new extension object
89
/// The extension object
91
public override object CreateInstance ()
93
return Activator.CreateInstance (Type);
97
/// Type of the object that this node creates
102
if (typeName.Length == 0)
103
throw new InvalidOperationException ("Type name not specified.");
104
type = Addin.GetType (typeName, true);
112
/// An extension node which specifies a type with custom extension metadata
115
/// This is the default type for type extension nodes bound to a custom extension attribute.
117
public class TypeExtensionNode<T>: TypeExtensionNode where T:CustomExtensionAttribute
122
/// The custom attribute containing the extension metadata
127
internal set { data = value; }