Ejemplo n.º 1
0
        public ConstructorGenerator DefineCtor(Emit.ParameterInfo[] parameters, MethodAttributes attrs)
        {
            var ctor = _builder.DefineConstructor(attrs, CallingConventions.Standard, parameters.Map(p => p.Type));
            ConstructorGenerator ctorGen = new ConstructorGenerator(ctor, parameters, this);

            Members.Add(ctorGen);
            return(ctorGen);
        }
Ejemplo n.º 2
0
        public Type CreateType()
        {
            if (_customAttributes != null)
            {
                foreach (var attr in _customAttributes)
                {
                    var cuAttr = new CustomAttributeBuilder(attr.Ctor, attr.Parameters);
                    _builder.SetCustomAttribute(cuAttr);
                }
            }
            if (Members.Any(mem => mem.MemberType == MemberTypes.Constructor) == false)
            {
                //default ctor
                IMember ctor = new ConstructorGenerator(_builder.DefineConstructor(DefaultCtor, CallingConventions.Standard, new Type[0]), new Emit.ParameterInfo[0], this)
                {
                    SyntaxBody = Statement.Empty
                };
                ctor.Compile();
            }
            if (Members.Any(mem => mem.MemberType == MemberTypes.Field && mem.IsStatic))
            {
                //check for static ctor
                if (Members.Any(mem => mem.MemberType == MemberTypes.Constructor && mem.IsStatic) == false)
                {
                    IMember ctor = new ConstructorGenerator(_builder.DefineConstructor(DefaultStaticCtor, CallingConventions.Standard, new Type[0]), new Emit.ParameterInfo[0], this)
                    {
                        SyntaxBody = Statement.Empty
                    };
                    ctor.Compile();
                }
            }
            foreach (var generator in Members)
            {
                generator.Compile();
            }
#if NETSTANDARD
            return(_builder.CreateTypeInfo());
#else
            return(_builder.CreateType());
#endif
        }