本文整理汇总了C#中Mono.Cecil.TypeReference.IsSystemType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeReference.IsSystemType方法的具体用法?C# TypeReference.IsSystemType怎么用?C# TypeReference.IsSystemType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.TypeReference
的用法示例。
在下文中一共展示了TypeReference.IsSystemType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAnnotationArgument
/// <summary>
/// Create an argument for an annotation.
///
/// Java Annotations have some limitations compared to CLRs Attributes:
/// - While they can have default values, there is no way to
/// specify an "unset" field or property.
// - 'null' is not allowed, neither as value nor as default (!)
/// We have to emulate those two extra states to model
/// the flexible constructor/property/field approach of
/// CLR.
/// We therefore save all values in arrays with the semantic:
/// - no elements unset; this is the default value.
/// - one element: the actual value
/// - two elements: null
/// </summary>
private static AnnotationArgument CreateAnnotationArgument(string name, TypeReference valueType, object value, DexTargetPackage targetPackage, XModule module)
{
if (valueType.IsSystemType())
{
// Convert .NET type reference to Dex type reference
value = ((TypeReference) value).GetReference(targetPackage, module);
}
if (valueType.IsArray && value is CustomAttributeArgument[])
{
List<object> values = new List<object>();
foreach (var argument in (CustomAttributeArgument[]) value)
{
// dereference if argument is an object or params array.
var arg = argument.Value as CustomAttributeArgument? ?? argument;
object val;
if (arg.Type.IsSystemType())
val = ((TypeReference)arg.Value).GetReference(targetPackage, module);
else
val = arg.Value;
// Don't add an extra level of indirection for this
// uncommon case until someone really needs it.
if (val == null)
throw new Exception("CustomAttributes: null values in array arguments are not supported.");
values.Add(val);
}
value = values.ToArray();
}
if (value != null)
{
// Note: there could be a special enum handling here, though it should work without.
if (valueType.IsUInt64())
return new AnnotationArgument(name, new object[] { unchecked((long)(ulong)value) });
if (valueType.IsUInt32())
return new AnnotationArgument(name, new object[] { unchecked((int)(uint)value) });
if (!valueType.IsPrimitive || valueType.IsWide() || valueType.IsFloat())
return new AnnotationArgument(name, new[] { value });
return new AnnotationArgument(name, new object[] { unchecked(Convert.ToInt32(value)) });
}
if(valueType.IsWide())
return new AnnotationArgument(name, new object[] { 0L, 0L});
if (valueType.IsPrimitive)
return new AnnotationArgument(name, new object[] { 0, 0 });
return new AnnotationArgument(name, new object[] { "", "" });
}
示例2: CreateAnnotationArgument
/// <summary>
/// Create an argument for an annotation.
/// </summary>
private static AnnotationArgument CreateAnnotationArgument(string name, TypeReference valueType, object value, DexTargetPackage targetPackage, XModule module)
{
if (valueType.IsSystemType())
{
// Convert .NET type reference to Dex type reference
value = ((TypeReference) value).GetReference(targetPackage, module);
}
return new AnnotationArgument(name, value);
}