Exemplo n.º 1
0
        public uint GetEnumTypeIndex(TypeDesc type)
        {
            System.Diagnostics.Debug.Assert(type.IsEnum, "GetEnumTypeIndex was called with wrong type");
            DefType defType = type as DefType;

            System.Diagnostics.Debug.Assert(defType != null, "GetEnumTypeIndex was called with non def type");
            EnumTypeDescriptor enumTypeDescriptor = new EnumTypeDescriptor();
            List <FieldDesc>   fieldsDescriptors  = new List <FieldDesc>();

            foreach (var field in defType.GetFields())
            {
                if (field.IsLiteral)
                {
                    fieldsDescriptors.Add(field);
                }
            }
            enumTypeDescriptor.ElementCount = (ulong)fieldsDescriptors.Count;
            enumTypeDescriptor.ElementType  = PrimitiveTypeDescriptor.GetPrimitiveTypeIndex(defType.UnderlyingType);
            enumTypeDescriptor.Name         = defType.Name;
            enumTypeDescriptor.UniqueName   = defType.GetFullName();
            EnumRecordTypeDescriptor[] typeRecords = new EnumRecordTypeDescriptor[enumTypeDescriptor.ElementCount];
            for (int i = 0; i < fieldsDescriptors.Count; ++i)
            {
                FieldDesc field = fieldsDescriptors[i];
                EnumRecordTypeDescriptor recordTypeDescriptor;
                recordTypeDescriptor.Value = GetEnumRecordValue(field);
                recordTypeDescriptor.Name  = field.Name;
                typeRecords[i]             = recordTypeDescriptor;
            }
            uint typeIndex = _objectWriter.GetEnumTypeIndex(enumTypeDescriptor, typeRecords);

            _knownTypes[type]         = typeIndex;
            _completeKnownTypes[type] = typeIndex;
            return(typeIndex);
        }
Exemplo n.º 2
0
        public uint GetEnumTypeIndex(EnumTypeDescriptor enumTypeDescriptor, EnumRecordTypeDescriptor[] enumerates)
        {
            checked
            {
                FieldListInProgress fieldList = default(FieldListInProgress);
                if ((enumerates != null && enumerates.Length > 0))
                {
                    fieldList = StartFieldList();
                    foreach (EnumRecordTypeDescriptor enumerate in enumerates)
                    {
                        EmitEnumerate(ref fieldList, enumerate.Value, new Utf8String(enumerate.Name));
                    }
                    FinalizeFieldList(fieldList);
                }

                if (enumerates != null)
                {
                    Debug.Assert(checked ((int)enumTypeDescriptor.ElementCount == enumerates.Length));
                }
                if (enumerates == null)
                {
                    Debug.Assert(enumTypeDescriptor.ElementCount == 0);
                }

                uint       enumTypeIndex = _blob.GetNextTypeIndex();
                Utf8String name          = new Utf8String(enumTypeDescriptor.Name);
                uint       recordSize    = 16 + DebugInfoBlob.StringLengthEncoded(name);
                _blob.WriteWORD(checked ((ushort)(_blob.DWORDAlignedSize(recordSize) - 2))); // don't include size of 'length' in 'length'
                _blob.WriteLeafKind(LeafKind.LF_ENUM);
                _blob.WriteWORD(fieldList.FieldsCount);
                _blob.WriteWORD(0);
                _blob.WriteDWORD((uint)enumTypeDescriptor.ElementType);
                _blob.WriteDWORD(fieldList.TypeIndexOfFieldList);
                _blob.WriteString(name);
                _blob.AlignToDWORD();
                VerifyBlobEligibleToBeBetweenRecords();
                return(enumTypeIndex);
            }
        }