Ejemplo n.º 1
0
Archivo: DC.cs Proyecto: airbrush/CSD
        void AddType(TypeDefinition type, Action<ModelType, string> add)
        {
            MetadataReader reader = _reader.Value.Reader;

            ModelType modelType = new ModelType { Name = reader.GetString(type.Name) };
            add(modelType, reader.GetString(type.Namespace));

            foreach (var hmember in type.GetFields())
            {
                FieldDefinition member = reader.GetFieldDefinition(hmember);
                modelType.Members.Add(new ModelTypeMember
                {
                    Name = "[f] " + reader.GetString(member.Name)
                });
            }

            foreach (var hmember in type.GetMethods())
            {
                MethodDefinition member = reader.GetMethodDefinition(hmember);
                modelType.Members.Add(new ModelMethod
                {
                    Name = reader.GetString(member.Name) + "()",
                    Handle = hmember,
                    Type = type,
                });
            }

            foreach (var hchild in type.GetNestedTypes())
            {
                TypeDefinition child = reader.GetTypeDefinition(hchild);
                AddType(child, (m, typeNs) => modelType.Members.Add(m));
            }
        }
        void ParseEnum(TypeDefinition enumTypeDef)
        {
            // TODO: verify that int32 is the enums storage type for constant read below

            InspectorEnum ienum = new InspectorEnum ();

            ienum.Name = metaReader.GetString (enumTypeDef.Name);

            InspectorEnums [ienum.Name] = ienum;

            var fields = enumTypeDef.GetFields ();

            foreach (var fieldHandle in fields) {

                var inspectorField = new InspectorField ();

                var fieldDef = metaReader.GetFieldDefinition (fieldHandle);

                if ((fieldDef.Attributes & FieldAttributes.HasDefault) != 0) {

                    var constantHandle = fieldDef.GetDefaultValue ();
                    var constant = metaReader.GetConstant (constantHandle);

                    BlobReader constantReader = metaReader.GetBlobReader (constant.Value);

                    ienum.Values [metaReader.GetString (fieldDef.Name)] = constantReader.ReadInt32 ();

                }
            }

            return;
        }