本文整理汇总了C#中Mono.Cecil.TypeReference.ResolveType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeReference.ResolveType方法的具体用法?C# TypeReference.ResolveType怎么用?C# TypeReference.ResolveType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeReference
的用法示例。
在下文中一共展示了TypeReference.ResolveType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatValue
public static string FormatValue(object v, TypeReference type, List <string> usings)
{
if (v == null)
return "null";
string ns = type.Namespace;
usings.AddUsing (ns);
TypeDefinition tdef = type.ResolveType ();
string ret;
if (tdef != null && tdef.IsEnum && tdef.HasFields) {
Collection <CustomAttribute> attrs = tdef.CustomAttributes;
CustomAttribute flagsAttr = attrs == null || attrs.Count == 0 ? null : attrs.First ((CustomAttribute attr) => {
if (attr.AttributeType.FullName == "System.FlagsAttribute")
return true;
return false;
});
bool flags = flagsAttr != null;
ns = tdef.Namespace;
usings.AddUsing (ns);
string typeName = tdef.FormatName (); //tdef.Name.Replace ("/", ".");
var sb = new StringBuilder ();
bool first = true;
object constant;
int bits;
foreach (FieldDefinition fd in tdef.Fields) {
if (flags) {
constant = fd.Constant;
bits = CountBits (constant);
if (bits < 0 || bits > 1)
continue;
if (IsBitSet (v, constant)) {
if (first)
first = false;
else
sb.Append (" | ");
sb.AppendFormat ("{0}.{1}", typeName, fd.Name);
}
} else if (v.Equals (fd.Constant)) {
sb.AppendFormat ("{0}.{1}", typeName, fd.Name);
break;
}
}
return sb.ToString ();
}
ret = v.ToString ();
if (v is string)
return "\"" + ret.Replace ("\\", "\\\\") + "\"";
if (v is bool)
return ret.ToLower ();
return ret;
}