當前位置: 首頁>>代碼示例>>C#>>正文


C# TypeReference.IsUInt64方法代碼示例

本文整理匯總了C#中Mono.Cecil.TypeReference.IsUInt64方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeReference.IsUInt64方法的具體用法?C# TypeReference.IsUInt64怎麽用?C# TypeReference.IsUInt64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.TypeReference的用法示例。


在下文中一共展示了TypeReference.IsUInt64方法的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.IsUInt64方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。