Пример #1
0
        public AnalysisNet.Types.TypeDefinition ExtractTypeDefinition(Cecil.TypeDefinition cecilType)
        {
            AnalysisNet.Types.TypeDefinition result;

            // the order matters
            // an enum can be a value type
            if (cecilType.IsEnum)
            {
                result = ExtractEnum(cecilType);
            }
            else if (cecilType.IsValueType)
            {
                result = ExtractClass(cecilType, AnalysisNet.Types.TypeKind.ValueType, AnalysisNet.Types.TypeDefinitionKind.Struct);
            }
            else if (cecilType.IsClass)
            {
                // includes delegates!
                AnalysisNet.Types.TypeDefinitionKind kind = IsDelegate(cecilType) ? AnalysisNet.Types.TypeDefinitionKind.Delegate : AnalysisNet.Types.TypeDefinitionKind.Class;
                result = ExtractClass(cecilType, AnalysisNet.Types.TypeKind.ReferenceType, kind);
            }
            else if (cecilType.IsInterface)
            {
                result = ExtractInterface(cecilType);
            }
            else
            {
                throw new NotImplementedException();
            }

            return(result);
        }
Пример #2
0
        private AnalysisNet.Types.TypeDefinition ExtractClass(Cecil.TypeDefinition cecilType, AnalysisNet.Types.TypeKind typeKind, AnalysisNet.Types.TypeDefinitionKind typeDefinitionKind)
        {
            string name = UnmangleName(cecilType);

            AnalysisNet.Types.TypeDefinition type = new AnalysisNet.Types.TypeDefinition(name, typeKind, typeDefinitionKind);
            Cecil.TypeReference basedef           = cecilType.BaseType;

            type.IsAbstract = cecilType.IsAbstract;
            type.IsSealed   = cecilType.IsSealed;

            if (basedef != null)
            {
                type.Base = ExtractType(basedef) as AnalysisNet.Types.IBasicType;
            }

            ExtractCustomAttributes(type.Attributes, cecilType.CustomAttributes);
            ExtractGenericTypeParameters(type, cecilType);
            ExtractInterfaces(type.Interfaces, cecilType.Interfaces);
            ExtractFields(type, type.Fields, cecilType.Fields);
            ExtractMethods(type, type.Methods, cecilType.Methods);
            ExtractPropertyDefinitions(type, cecilType);
            ExtractExplicitMethodOverrides(type, cecilType);
            ExtractLayoutInformation(type, cecilType);

            return(type);
        }