Example #1
0
        protected override void Initialize(TypeDefKey key)
        {
            Debug.Assert(key.Type.IsEnum && key is TypeDefKeyWithUnmanagedType);

            Type type = key.Type;

            this.name        = Utility.GetNameOfType(type);
            this.isFlagsEnum = type.IsDefined(typeof(FlagsAttribute), false);

            UnmanagedType underlying_unmng_type = ((TypeDefKeyWithUnmanagedType)key).UnmanagedType;
            TypeName      type_name             = TypeName.GetTypeNameForUnmanagedType(underlying_unmng_type);

            // The unmanaged type has been validated by EnumNativeType and is surely a primitive type, for
            // which there is a simple direct translation to TypeName.
            Debug.Assert(!type_name.IsEmpty);

            this.underlyingType = new PrimitiveNativeType(
                type_name,
                (key.Flags & MarshalFlags.Platform64Bit) == MarshalFlags.Platform64Bit);

            // now enumerate the enum fields and set up the fields array
            string[] names  = Enum.GetNames(type);
            Array    values = Enum.GetValues(type);

            Debug.Assert(names.Length == values.Length);

            this.fields = new EnumField[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                this.fields[i] = new EnumField(names[i], values.GetValue(i));
            }
        }
Example #2
0
        public PrimitiveNativeType(NativeTypeDesc desc, UnmanagedType[] allowedUnmanagedTypes)
            : this(desc)
        {
            UnmanagedType unmng_type = ValidateUnmanagedType(desc, allowedUnmanagedTypes);

            if (desc.Type == typeof(bool))
            {
                // Boolean as I1 and I2 should print 'bool' as the plain C++ type
                if (unmng_type == UnmanagedType.I1)
                {
                    typeName = TypeName.I1_Bool;
                }
                if (unmng_type == UnmanagedType.U1)
                {
                    typeName = TypeName.U1_Bool;
                }
            }

            if (typeName.IsEmpty)
            {
                typeName = TypeName.GetTypeNameForUnmanagedType(unmng_type);
                Debug.Assert(!typeName.IsEmpty);
            }

            if (unmng_type == UnmanagedType.SysInt ||
                unmng_type == UnmanagedType.SysUInt)
            {
                // IntPtr and UIntPtr translate into "void *"
                indirections++;
            }
        }