当前位置: 首页>>代码示例>>C#>>正文


C# TypeReference.IsUInt32方法代码示例

本文整理汇总了C#中Mono.Cecil.TypeReference.IsUInt32方法的典型用法代码示例。如果您正苦于以下问题:C# TypeReference.IsUInt32方法的具体用法?C# TypeReference.IsUInt32怎么用?C# TypeReference.IsUInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.TypeReference的用法示例。


在下文中一共展示了TypeReference.IsUInt32方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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[] { "", "" });
        }
开发者ID:jakesays,项目名称:dot42,代码行数:70,代码来源:AnnotationBuilder.cs


注:本文中的Mono.Cecil.TypeReference.IsUInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。