本文整理汇总了C#中Mono.Addins.Description.AddinDescription.AddExtensionPoint方法的典型用法代码示例。如果您正苦于以下问题:C# AddinDescription.AddExtensionPoint方法的具体用法?C# AddinDescription.AddExtensionPoint怎么用?C# AddinDescription.AddExtensionPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Addins.Description.AddinDescription
的用法示例。
在下文中一共展示了AddinDescription.AddExtensionPoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScanAssemblyContents
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 + "'.");
//.........这里部分代码省略.........
示例2: ScanAssemblyContents
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);
}
}
}
}