示例#1
0
        //TODO: out parameters... yuck
        private TypeDefinition GenerateAutoDIClass(Mapping mapping, Settings settings, ICodeGenerator codeGenerator,
                                                   out MethodDefinition initMethod)
        {
            var containerType = new TypeDefinition(Constants.Namespace, Constants.TypeName,
                                                   TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed
                                                   | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit)
            {
                BaseType = ModuleDefinition.Get <object>()
            };

            FieldDefinition globalServiceProvider =
                ModuleDefinition.CreateStaticReadonlyField(Constants.GlobalServiceProviderName, false, Import.System.IServiceProvider);

            containerType.Fields.Add(globalServiceProvider);

            MethodDefinition configureMethod = GenerateAddServicesMethod(mapping, settings, containerType, codeGenerator);

            containerType.Methods.Add(configureMethod);

            initMethod = GenerateInitMethod(configureMethod, globalServiceProvider);
            containerType.Methods.Add(initMethod);

            MethodDefinition disposeMethod = GenerateDisposeMethod(globalServiceProvider);

            containerType.Methods.Add(disposeMethod);

            return(containerType);
        }
示例#2
0
        public static FieldDefinition CreateStaticReadonlyField <T>(this ModuleDefinition moduleDefintion, string name, bool @public)
        {
            if (moduleDefintion == null)
            {
                throw new ArgumentNullException(nameof(moduleDefintion));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(moduleDefintion.CreateStaticReadonlyField(name, @public, moduleDefintion.Get <T>()));
        }