예제 #1
0
        public SchemaConstructorBuilder(SchemaDocument doc,
                                        SchemaTypeBuilder types,
                                        SchemaFieldBuilder fields,
                                        SchemaBasicReaderBuilder basic)
        {
            Doc    = doc;
            Types  = types;
            Fields = fields;
            Basic  = basic;

            CompoundConstructors = Types.CompoundTypes
                                   .ToDictionary(
                kvp => kvp.Key,
                kvp => WriteCompoundConstructor(kvp.Value)
                );
            //NiObjectConstructors = Types.NiObjectTypes
            //    .ToDictionary(
            //        kvp => kvp.Key,
            //        kvp => kvp.Value.DefineDefaultConstructor(MethodAttributes.Public)
            //    );
        }
예제 #2
0
        /// <summary>
        /// Writes types for each niObject, compound, enum, bitflag and bitfield
        /// into a reflection module, as well as building constructors for each
        /// type.
        /// </summary>
        /// <param name="moduleBuilder">The module to write the types to</param>
        /// <param name="document">The base schema document that described the types in NIF.xml/BlockStructure format</param>
        /// <param name="basics">A map of basic type names to their primitive values</param>
        /// <param name="version">The specific version of the document to use</param>
        public SchemaDocumentBuilder(ModuleBuilder moduleBuilder,
                                     SchemaDocument document,
                                     Dictionary <string, Type> basics,
                                     VersionKey version)
        {
            Document          = document;
            SchemaBasicReader = new SchemaBasicReaderBuilder(moduleBuilder, document, basics);

            SchemaTypes        = new SchemaTypeBuilder(document, moduleBuilder, SchemaBasicReader);
            SchemaFields       = new SchemaFieldBuilder(this, version);
            SchemaInheritance  = new SchemaInheritanceBuilder(SchemaTypes);
            SchemaEnum         = new SchemaEnumBuilder(SchemaTypes);
            SchemaConstructors = new SchemaConstructorBuilder(document, SchemaTypes, SchemaFields, SchemaBasicReader);
            SchemaILBuilder    = new SchemaConstructorILBuilder(this);

            foreach (var enumBuilder in SchemaTypes.BuiltEnumsByName.Values)
            {
                enumBuilder.CreateTypeInfo();
            }
            foreach (var typeBuilder in SchemaTypes.BuiltTypesByName.Values)
            {
                typeBuilder.CreateTypeInfo();
            }
        }
예제 #3
0
        public SchemaTypeBuilder(SchemaDocument document,
                                 ModuleBuilder moduleBuilder,
                                 SchemaBasicReaderBuilder basicBuilder)
        {
            Document = document;
            BasicTypeDescriptions = basicBuilder;

            CompoundTypes = document.Compounds
                            .ToDictionary(kvp => kvp.Value, kvp => BuildCompoundType(moduleBuilder, kvp.Value));
            NiObjectTypes = document.NiObjects
                            .ToDictionary(kvp => kvp.Value, kvp => BuildNiObjectType(moduleBuilder, kvp.Value));
            EnumTypes = document.Enums
                        .ToDictionary(kvp => kvp.Value, kvp => BuildEnumType(moduleBuilder, kvp.Value, document));
            BitFieldTypes = document.Bitfields
                            .ToDictionary(kvp => kvp.Value, kvp => BuildBitfieldType(moduleBuilder, kvp.Value));
            BitflagsTypes = document.Bitflags
                            .ToDictionary(kvp => kvp.Value, kvp => BuildBitflagType(moduleBuilder, kvp.Value, document));

            BuiltTypesByName = new List <(string, TypeBuilder)>()
                               .Concat(CompoundTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .Concat(NiObjectTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .Concat(BitFieldTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .ToDictionary(pair => pair.Item1, pair => pair.Item2);
            BuiltEnumsByName = new List <(string, EnumBuilder)>()
                               .Concat(EnumTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .Concat(BitflagsTypes.Select(kvp => (kvp.Key.Name, kvp.Value)))
                               .ToDictionary(pair => pair.Item1, pair => pair.Item2);

            SchemaTypesByName = new List <(string, Type)>()
                                .Concat(BasicTypeDescriptions.BasicDescriptions.Select(kvp => (kvp.Key.Name, kvp.Value.UnderlyingType)))
                                .Concat(BuiltTypesByName.Select(kvp => (kvp.Key, kvp.Value as Type)))
                                .Concat(BuiltEnumsByName.Select(kvp => (kvp.Key, kvp.Value as Type)))
                                .ToDictionary(pair => pair.Item1, pair => pair.Item2);
            TemplateTypeByName = CompoundTypes
                                 .ToDictionary(c => c.Key.Name, c => BuildTemplateType(c.Value, c.Key));
        }