AddExtensionPoint() public method

Adds an extension point.
public AddExtensionPoint ( string path ) : ExtensionPoint
path string /// Path that identifies the new extension point. ///
return ExtensionPoint
コード例 #1
0
ファイル: AddinScanner.cs プロジェクト: JamesChan/mono-addins
        void ScanAssemblyContents(IAssemblyReflector reflector, AddinDescription config, ModuleDescription module, object asm, AddinScanResult scanResult)
        {
            bool isMainModule = module == config.MainModule;

            // Get dependencies

            object[] deps = reflector.GetCustomAttributes (asm, typeof(AddinDependencyAttribute), false);
            foreach (AddinDependencyAttribute dep in deps) {
                AddinDependency adep = new AddinDependency ();
                adep.AddinId = dep.Id;
                adep.Version = dep.Version;
                module.Dependencies.Add (adep);
            }

            if (isMainModule) {

                // Get properties

                object[] props = reflector.GetCustomAttributes (asm, typeof(AddinPropertyAttribute), false);
                foreach (AddinPropertyAttribute prop in props)
                    config.Properties.SetPropertyValue (prop.Name, prop.Value, prop.Locale);

                // Get extension points

                object[] extPoints = reflector.GetCustomAttributes (asm, typeof(ExtensionPointAttribute), false);
                foreach (ExtensionPointAttribute ext in extPoints) {
                    ExtensionPoint ep = config.AddExtensionPoint (ext.Path);
                    ep.Description = ext.Description;
                    ep.Name = ext.Name;
                    ExtensionNodeType nt = ep.AddExtensionNode (ext.NodeName, ext.NodeTypeName);
                    nt.ExtensionAttributeTypeName = ext.ExtensionAttributeTypeName;
                }
            }

            // Look for extension nodes declared using assembly attributes

            foreach (CustomAttribute att in reflector.GetRawCustomAttributes (asm, typeof(CustomExtensionAttribute), true))
                AddCustomAttributeExtension (module, att, "Type");

            // Get extensions or extension points applied to types

            foreach (object t in reflector.GetAssemblyTypes (asm)) {

                string typeFullName = reflector.GetTypeFullName (t);

                // Look for extensions

                object[] extensionAtts = reflector.GetCustomAttributes (t, typeof(ExtensionAttribute), false);
                if (extensionAtts.Length > 0) {
                    Dictionary<string,ExtensionNodeDescription> nodes = new Dictionary<string, ExtensionNodeDescription> ();
                    ExtensionNodeDescription uniqueNode = null;
                    foreach (ExtensionAttribute eatt in extensionAtts) {
                        string path;
                        string nodeName = eatt.NodeName;

                        if (eatt.TypeName.Length > 0) {
                            path = "$" + eatt.TypeName;
                        }
                        else if (eatt.Path.Length == 0) {
                            path = GetBaseTypeNameList (reflector, t);
                            if (path == "$") {
                                // The type does not implement any interface and has no superclass.
                                // Will be reported later as an error.
                                path = "$" + typeFullName;
                            }
                        } else {
                            path = eatt.Path;
                        }

                        ExtensionNodeDescription elem = module.AddExtensionNode (path, nodeName);
                        nodes [path] = elem;
                        uniqueNode = elem;

                        if (eatt.Id.Length > 0) {
                            elem.SetAttribute ("id", eatt.Id);
                            elem.SetAttribute ("type", typeFullName);
                        } else {
                            elem.SetAttribute ("id", typeFullName);
                        }
                        if (eatt.InsertAfter.Length > 0)
                            elem.SetAttribute ("insertafter", eatt.InsertAfter);
                        if (eatt.InsertBefore.Length > 0)
                            elem.SetAttribute ("insertbefore", eatt.InsertBefore);
                    }

                    // Get the node attributes

                    foreach (ExtensionAttributeAttribute eat in reflector.GetCustomAttributes (t, typeof(ExtensionAttributeAttribute), false)) {
                        ExtensionNodeDescription node;
                        if (!string.IsNullOrEmpty (eat.Path))
                            nodes.TryGetValue (eat.Path, out node);
                        else if (eat.TypeName.Length > 0)
                            nodes.TryGetValue ("$" + eat.TypeName, out node);
                        else {
                            if (nodes.Count > 1)
                                throw new Exception ("Missing type or extension path value in ExtensionAttribute for type '" + typeFullName + "'.");
                            node = uniqueNode;
                        }
                        if (node == null)
                            throw new Exception ("Invalid type or path value in ExtensionAttribute for type '" + typeFullName + "'.");

                        node.SetAttribute (eat.Name ?? string.Empty, eat.Value ?? string.Empty);
                    }
                }
                else {
                    // Look for extension points

                    extensionAtts = reflector.GetCustomAttributes (t, typeof(TypeExtensionPointAttribute), false);
                    if (extensionAtts.Length > 0 && isMainModule) {
                        foreach (TypeExtensionPointAttribute epa in extensionAtts) {
                            ExtensionPoint ep;

                            ExtensionNodeType nt = new ExtensionNodeType ();

                            if (epa.Path.Length > 0) {
                                ep = config.AddExtensionPoint (epa.Path);
                            }
                            else {
                                ep = config.AddExtensionPoint (GetDefaultTypeExtensionPath (config, typeFullName));
                                nt.ObjectTypeName = typeFullName;
                            }
                            nt.Id = epa.NodeName;
                            nt.TypeName = epa.NodeTypeName;
                            nt.ExtensionAttributeTypeName = epa.ExtensionAttributeTypeName;
                            ep.NodeSet.NodeTypes.Add (nt);
                            ep.Description = epa.Description;
                            ep.Name = epa.Name;
                            ep.RootAddin = config.AddinId;
                            ep.SetExtensionsAddinId (config.AddinId);
                        }
                    }
                    else {
                        // Look for custom extension attribtues
                        foreach (CustomAttribute att in reflector.GetRawCustomAttributes (t, typeof(CustomExtensionAttribute), false)) {
                            ExtensionNodeDescription elem = AddCustomAttributeExtension (module, att, "Type");
                            elem.SetAttribute ("type", typeFullName);
                            if (string.IsNullOrEmpty (elem.GetAttribute ("id")))
                                elem.SetAttribute ("id", typeFullName);
                        }
                    }
                }
            }
        }
コード例 #2
0
		void ScanAssemblyContents (AddinDescription config, Assembly asm, ArrayList hostExtensionClasses, AddinScanResult scanResult)
		{
			// Get dependencies
			
			object[] deps = asm.GetCustomAttributes (typeof(AddinDependencyAttribute), false);
			foreach (AddinDependencyAttribute dep in deps) {
				AddinDependency adep = new AddinDependency ();
				adep.AddinId = dep.Id;
				adep.Version = dep.Version;
				config.MainModule.Dependencies.Add (adep);
			}
			
			// Get extension points
			
			object[] extPoints = asm.GetCustomAttributes (typeof(ExtensionPointAttribute), false);
			foreach (ExtensionPointAttribute ext in extPoints) {
				ExtensionPoint ep = config.AddExtensionPoint (ext.Path);
				ep.Description = ext.Description;
				ep.Name = ext.Name;
				ep.AddExtensionNode (ext.NodeName, ext.NodeType.FullName);
			}
			
			foreach (Type t in asm.GetTypes ()) {
				
				if (Attribute.IsDefined (t, typeof(ExtensionAttribute))) {
					foreach (ExtensionAttribute eatt in t.GetCustomAttributes (typeof(ExtensionAttribute), false)) {
						string path;
						string nodeName;
						
						if (eatt.Path.Length == 0) {
							if (config.IsRoot) {
								// The extension point must be one of the defined by the assembly
								// Look for it later, when the assembly has been fully scanned.
								hostExtensionClasses.Add (t);
								continue;
							}
							else {
								path = GetBaseTypeNameList (t);
								if (path == "$") {
									// The type does not implement any interface and has no superclass.
									// Will be reported later as an error.
									path = "$" + t.FullName;
								}
								nodeName = "Type";
							}
						} else {
							path = eatt.Path;
							nodeName = eatt.NodeName;
						}
							
						ExtensionNodeDescription elem = config.MainModule.AddExtensionNode (path, nodeName);
						if (eatt.Id.Length > 0) {
							elem.SetAttribute ("id", eatt.Id);
							elem.SetAttribute ("type", t.FullName);
						} else {
							elem.SetAttribute ("id", t.FullName);
						}
						if (eatt.InsertAfter.Length > 0)
							elem.SetAttribute ("insertafter", eatt.InsertAfter);
						if (eatt.InsertBefore.Length > 0)
							elem.SetAttribute ("insertbefore", eatt.InsertAfter);
					}
				}
				else if (Attribute.IsDefined (t, typeof(TypeExtensionPointAttribute))) {
					foreach (TypeExtensionPointAttribute epa in t.GetCustomAttributes (typeof(TypeExtensionPointAttribute), false)) {
						ExtensionPoint ep;
						
						ExtensionNodeType nt = new ExtensionNodeType ();
						
						if (epa.Path.Length > 0) {
							ep = config.AddExtensionPoint (epa.Path);
						}
						else {
							ep = config.AddExtensionPoint (GetDefaultTypeExtensionPath (config, t));
							nt.ObjectTypeName = t.FullName;
						}
						nt.Id = epa.NodeName;
						nt.TypeName = epa.NodeType.FullName;
						ep.NodeSet.NodeTypes.Add (nt);
						ep.Description = epa.Description;
						ep.Name = epa.Name;
						ep.RootAddin = config.AddinId;
						ep.SetExtensionsAddinId (config.AddinId);
					}
				}
			}
		}