本文整理汇总了C#中Mono.Cecil.TypeDefinition.CorrectName方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition.CorrectName方法的具体用法?C# TypeDefinition.CorrectName怎么用?C# TypeDefinition.CorrectName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeDefinition
的用法示例。
在下文中一共展示了TypeDefinition.CorrectName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpType
public static XElement DumpType(TypeDefinition type, bool dumpParents=false)
{
string typeType;
if (type.IsInterface)
typeType = "Interface";
else if (type.IsEnum)
typeType = "Enum";
else if (type.IsValueType)
typeType = "Struct";
else if (type.IsClass)
typeType = "Class";
else
typeType = "Type";
XElement typeXml = new XElement(typeType);
typeXml.SetAttributeValue("Name", type.CorrectName());
if (type.IsClass && type.IsSealed && type.IsAbstract)
{
typeXml.SetAttributeValue("Static", "true");
}
else if (type.IsClass && type.IsAbstract)
{
typeXml.SetAttributeValue("Abstract", "true");
}
if (!type.IsNested)
typeXml.SetAttributeValue("Path", type.Namespace);
//adding fields
foreach (FieldDefinition field in type.Fields.Where(f => f.IsPublic))
{
XElement fieldXml = new XElement("Field");
fieldXml.SetAttributeValue("Name", field.Name);
fieldXml.SetAttributeValue("Static", field.IsStatic ? "true" : null);
if (type.IsEnum)
{
fieldXml.SetAttributeValue("Value", field.Constant);
}
else
{
fieldXml.SetAttributeValue("Type", field.FieldType);
}
typeXml.Add(fieldXml);
}
//adding methods
foreach (MethodDefinition method in type.Methods.Where(m => m.IsPublic && !m.IsGetter && !m.IsSetter))
{
typeXml.Add(DumpMethod(method));
}
//adding properties
foreach (PropertyDefinition property in type.Properties.Where(p => (p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic)))
{
XElement propertyXml = new XElement("Property");
propertyXml.SetAttributeValue("Name", property.Name);
propertyXml.SetAttributeValue("Type", property.PropertyType);
if (property.GetMethod != null && property.GetMethod.IsPublic)
{
propertyXml.Add(DumpMethod(property.GetMethod));
}
if (property.SetMethod != null && property.SetMethod.IsPublic)
{
propertyXml.Add(DumpMethod(property.SetMethod));
}
typeXml.Add(propertyXml);
}
//adding nested types
foreach (TypeDefinition nestedType in type.NestedTypes.Where(m => m.IsNestedPublic))
{
typeXml.Add(DumpType(nestedType));
}
//adding members from parent types
if(dumpParents && type.BaseType!=null)
{
XElement parentXml = DumpType(type.BaseType.Resolve(),true);
foreach (XElement element in parentXml.Elements())
{
if(typeXml.Elements().All(e=>!Check.AreCompatible(e,element)))
{
typeXml.Add(element);
}
}
}
return typeXml;
}