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)); } }
public override void PrintTo(ICodePrinter printer, ILogPrinter logPrinter, PrintFlags flags) { Debug.Assert(printer != null && logPrinter != null); base.PrintTo(printer, logPrinter, flags); switch (arrayKind) { case ArrayKind.Invalid: { // void */PVOID PrimitiveNativeType.PrintNameTo(TypeName.Void, 1, printer, flags); break; } case ArrayKind.SafeArray: { // prefix with const if in-only if (isInOnly) { printer.Print(OutputType.Keyword, "const"); printer.Print(OutputType.Other, " "); } // SAFEARRAY * or LPSAFEARRAY if ((flags & PrintFlags.UsePlainC) == PrintFlags.UsePlainC) { TypeName.PrintTo(printer, TypeName.SafeArray.PlainC); printer.Print(OutputType.Other, " "); printer.Print(OutputType.Operator, "*"); } else { TypeName.PrintTo(printer, "LP" + TypeName.SafeArray.WinApi); } break; } default: { elementType.PrintTo(printer, logPrinter, flags); break; } } if (indirections > 0) { // We'll suppress the [] suffix in this case; one indirection will be provided by the // element itself because the ByRefParam flag has been inherited by it. int stars = indirections; while (stars-- > 0) { printer.Print(OutputType.Operator, "*"); } } }
protected override void Initialize(TypeDefKey key) { if (key == null) throw new ArgumentNullException(nameof(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)); } }