本文整理汇总了C#中Mono.Addins.RuntimeAddin.CreateInstance方法的典型用法代码示例。如果您正苦于以下问题:C# RuntimeAddin.CreateInstance方法的具体用法?C# RuntimeAddin.CreateInstance怎么用?C# RuntimeAddin.CreateInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Addins.RuntimeAddin
的用法示例。
在下文中一共展示了RuntimeAddin.CreateInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMap
public void AddMap (RuntimeAddin addin, string xmlMap, string fileId)
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml (xmlMap);
foreach (XmlElement elem in doc.DocumentElement.SelectNodes ("DataItem")) {
string tname = elem.GetAttribute ("class");
Type type = addin.GetType (tname);
if (type == null) {
LoggingService.LogError ("[SerializationMap " + fileId + "] Type not found: '" + tname + "'");
continue;
}
string cname = elem.GetAttribute ("name");
string ftname = elem.GetAttribute ("fallbackType");
SerializationMap map;
if (!maps.TryGetValue (type, out map)) {
map = new SerializationMap (type);
maps [type] = map;
map.FileId = fileId;
if (cname.Length > 0 || ftname.Length > 0) {
DataItemAttribute iat = new DataItemAttribute ();
if (cname.Length > 0)
iat.Name = cname;
if (ftname.Length > 0)
iat.FallbackType = addin.GetType (ftname, true);
map.TypeAttributes.Add (iat);
}
} else {
if (!string.IsNullOrEmpty (cname))
throw new InvalidOperationException (string.Format ("Type name for type '{0}' in map '{1}' already specified in another serialization map for the same type ({2}).", type, fileId, map.FileId));
if (!string.IsNullOrEmpty (ftname))
throw new InvalidOperationException (string.Format ("Fallback type for type '{0}' in map '{1}' already specified in another serialization map for the same type ({2}).", type, fileId, map.FileId));
}
string customDataItem = elem.GetAttribute ("customDataItem");
if (customDataItem.Length > 0) {
ICustomDataItemHandler ch = (ICustomDataItemHandler) addin.CreateInstance (customDataItem, true);
if (map.CustomHandler != null)
map.CustomHandler = new CustomDataItemHandlerChain (map.CustomHandler, ch);
else
map.CustomHandler = ch;
}
ItemMember lastMember = null;
int litc = 0;
foreach (XmlElement att in elem.SelectNodes ("ItemProperty|ExpandedCollection|LiteralProperty|ItemMember"))
{
string memberName = null;
ItemMember prevMember = lastMember;
lastMember = null;
if (att.Name == "LiteralProperty") {
ItemMember mem = new ItemMember ();
memberName = mem.Name = "_literal_" + (++litc);
mem.Type = typeof(string);
mem.InitValue = att.GetAttribute ("value");
mem.DeclaringType = map.Type;
map.ExtendedMembers.Add (mem);
ItemPropertyAttribute itemAtt = new ItemPropertyAttribute ();
itemAtt.Name = att.GetAttribute ("name");
map.AddMemberAttribute (mem, itemAtt);
lastMember = mem;
continue;
}
else if (att.Name == "ItemMember") {
ItemMember mem = new ItemMember ();
memberName = mem.Name = att.GetAttribute ("name");
mem.Type = addin.GetType (att.GetAttribute ("type"), true);
mem.DeclaringType = map.Type;
map.ExtendedMembers.Add (mem);
lastMember = mem;
continue;
}
else
{
memberName = att.GetAttribute ("member");
Type mt;
object mi;
if (!FindMember (map, memberName, out mi, out mt)) {
LoggingService.LogError ("[SerializationMap " + fileId + "] Member '" + memberName + "' not found in type '" + tname + "'");
continue;
}
if (att.Name == "ItemProperty")
{
ItemPropertyAttribute itemAtt = new ItemPropertyAttribute ();
string val = att.GetAttribute ("name");
if (val.Length > 0)
itemAtt.Name = val;
val = att.GetAttribute ("scope");
if (val.Length > 0)
itemAtt.Scope = val;
if (att.Attributes ["defaultValue"] != null) {
//.........这里部分代码省略.........