Inheritance: ITypeMapper
Exemplo n.º 1
0
 public DelegateGen Delegate(System.Type returnType, string name)
 {
     return(Delegate(TypeMapper.MapType(returnType), name));
 }
Exemplo n.º 2
0
 public PropertyGen PropertyImplementation(System.Type interfaceType, System.Type type, string name)
 {
     return(PropertyImplementation(TypeMapper.MapType(interfaceType), TypeMapper.MapType(type), name));
 }
Exemplo n.º 3
0
 public TypeGen Class(string name)
 {
     return(Class(name, TypeMapper.MapType(typeof(object)), Type.EmptyTypes));
 }
Exemplo n.º 4
0
 public TypeGen Class(string name, System.Type baseType, params Type[] interfaces)
 {
     return(Class(name, TypeMapper.MapType(baseType), interfaces));
 }
Exemplo n.º 5
0
 public MethodGen Operator(Operator op, System.Type returnType, System.Type operandType)
 {
     return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(operandType)));
 }
Exemplo n.º 6
0
 public MethodGen Operator(Operator op, System.Type returnType, System.Type leftType, System.Type rightType)
 {
     return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(leftType), TypeMapper.MapType(rightType)));
 }
Exemplo n.º 7
0
 public T Parameter(System.Type type, string name)
 {
     return(Parameter(TypeMapper.MapType(type), name));
 }
Exemplo n.º 8
0
 public MethodGen ExplicitConversionTo(System.Type toType)
 {
     return(ExplicitConversionTo(TypeMapper.MapType(toType)));
 }
Exemplo n.º 9
0
 public void Invoke(System.Type target, string method)
 {
     Invoke(TypeMapper.MapType(target), method);
 }
Exemplo n.º 10
0
 public void Invoke(System.Type target, string method, params Operand[] args)
 {
     Invoke(TypeMapper.MapType(target), method, args);
 }
Exemplo n.º 11
0
        public MethodGen AddMethod(string parameterName)
        {
            if (_adder == null)
            {
                LockSignature();
                _adder = new MethodGen(_owner, "add_" + Name, _attrs | MethodAttributes.SpecialName, TypeMapper.MapType(typeof(void)), 0);
                _adder.ImplementedInterface = ImplementedInterface;
                _adder.Parameter(_type, parameterName);
                _eb.SetAddOnMethod(_adder.GetMethodBuilder());
            }

            return(_adder);
        }
Exemplo n.º 12
0
 public AttributeGen <EventGen> BeginAttribute(System.Type attributeType, params object[] args)
 {
     return(BeginAttribute(TypeMapper.MapType(attributeType), args));
 }
Exemplo n.º 13
0
 public AttributeGen <EventGen> BeginAttribute(System.Type attributeType)
 {
     return(BeginAttribute(TypeMapper.MapType(attributeType)));
 }
Exemplo n.º 14
0
 public EventGen Attribute(System.Type attributeType)
 {
     return(Attribute(TypeMapper.MapType(attributeType)));
 }
Exemplo n.º 15
0
        public void Complete()
        {
            if (_type != null)
            {
                return;
            }

            if (_owner != null && TypeBuilder.IsValueType)
            {
                if (_fields.Count == 0 && _properties.Count == 0)
                {
                    // otherwise  "Value class has neither fields nor size parameter."
                    Private.ReadOnly.Field(_typeMapper.MapType(typeof(int)), "_____");
                }
            }

            foreach (TypeGen nested in _nestedTypes)
            {
                nested.Complete();
            }

            if (_owner != null)
            {
                // ensure creation of default constructor
                EnsureDefaultConstructor();
            }

            FlushDefinitionQueue();
            FlushCompletionQueue();

            // implement all interfaces
            foreach (InterfaceImplEntry iie in _implementations)
            {
                if (!iie.IsBound)
                {
                    throw new NotImplementedException(string.Format(null, Properties.Messages.ErrInterfaceNotImplemented,
                                                                    iie.InterfaceType, iie.InterfaceMethod.Member));
                }

                TypeBuilder.DefineMethodOverride(iie.BoundMethod.GetMethodBuilder(), (MethodInfo)iie.InterfaceMethod.Member);
            }

            // set indexer name
            if (_indexerName != null)
            {
                CustomAttributeBuilder cab = new CustomAttributeBuilder(
                    TypeMapper.MapType(typeof(DefaultMemberAttribute)).GetConstructor(new Type[] { TypeMapper.MapType(typeof(string)) }),
                    new object[] { _indexerName });
                TypeBuilder.SetCustomAttribute(cab);
            }

            AttributeGen.ApplyList(ref _customAttributes, TypeBuilder.SetCustomAttribute);

            _type = TypeBuilder.CreateType();

            _typeMapper.TypeInfo.UnregisterProvider(TypeBuilder);
        }
Exemplo n.º 16
0
 public MethodGen ExplicitConversionFrom(System.Type fromType, string parameterName)
 {
     return(ExplicitConversionFrom(TypeMapper.MapType(fromType), parameterName));
 }
Exemplo n.º 17
0
 public FieldGen Field(System.Type type, string name)
 {
     return(Field(TypeMapper.MapType(type), name));
 }
Exemplo n.º 18
0
 public MethodGen ExplicitConversionTo(System.Type toType, string parameterName)
 {
     return(ExplicitConversionTo(TypeMapper.MapType(toType), parameterName));
 }
Exemplo n.º 19
0
 public FieldGen Field(System.Type type, string name, Operand initialValue)
 {
     return(Field(TypeMapper.MapType(type), name, initialValue));
 }
Exemplo n.º 20
0
 public MethodGen Operator(Operator op, System.Type returnType, Type operandType, string operandName)
 {
     return(Operator(op, TypeMapper.MapType(returnType), operandType, operandName));
 }
Exemplo n.º 21
0
 public PropertyGen Property(System.Type type, string name)
 {
     return(Property(TypeMapper.MapType(type), name));
 }
Exemplo n.º 22
0
 public MethodGen Operator(Operator op, System.Type returnType, System.Type leftType, string leftName, System.Type rightType, string rightName)
 {
     return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(leftType), leftName, TypeMapper.MapType(rightType), rightName));
 }
Exemplo n.º 23
0
 public PropertyGen Indexer(System.Type type, string name)
 {
     return(Indexer(TypeMapper.MapType(type), name));
 }
Exemplo n.º 24
0
 public TypeGen Class(string name, System.Type baseType)
 {
     return(Class(name, TypeMapper.MapType(baseType)));
 }
Exemplo n.º 25
0
 public EventGen CustomEvent(System.Type handlerType, string name)
 {
     return(CustomEvent(TypeMapper.MapType(handlerType), name));
 }
Exemplo n.º 26
0
        public TypeGen Struct(string name, params Type[] interfaces)
        {
            if (TypeBuilder.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoNested);
            }

            if (_typeVis == 0)
            {
                _typeVis |= TypeAttributes.NestedPrivate;
            }

            TypeGen tg = new TypeGen(this, name, (_typeVis | _typeVirt | _typeFlags | TypeAttributes.Sealed | TypeAttributes.SequentialLayout) ^ TypeAttributes.BeforeFieldInit, TypeMapper.MapType(typeof(ValueType)), interfaces, _typeMapper);

            ResetAttrs();
            return(tg);
        }
Exemplo n.º 27
0
 public MethodGen Method(System.Type returnType, string name)
 {
     return(Method(TypeMapper.MapType(returnType), name));
 }
Exemplo n.º 28
0
 public MethodGen MethodImplementation(Type interfaceType, System.Type returnType, string name)
 {
     return(MethodImplementation(interfaceType, TypeMapper.MapType(returnType), name));
 }
Exemplo n.º 29
0
 public MethodGen ExplicitConversionFrom(System.Type fromType)
 {
     return(ExplicitConversionFrom(TypeMapper.MapType(fromType)));
 }
Exemplo n.º 30
0
 public EventGen EventImplementation(System.Type interfaceType, System.Type eventHandlerType, string name)
 {
     return(EventImplementation(TypeMapper.MapType(interfaceType), TypeMapper.MapType(eventHandlerType), name));
 }
Exemplo n.º 31
0
        void Initialize(Universe universe, string assemblyName, AssemblyBuilderAccess access, CompilerOptions options, ITypeMapper typeMapper = null)
        {
            if (universe == null) throw new ArgumentNullException(nameof(universe));
            if (options == null) throw new ArgumentNullException(nameof(options));
            _compilerOptions = options;
            if (typeMapper == null)
#if FEAT_IKVM
                typeMapper = new TypeMapper(universe);
#else
                typeMapper = new TypeMapper();
#endif
            ExpressionFactory = new ExpressionFactory(typeMapper);
            StaticFactory = new StaticFactory(typeMapper);

#if SILVERLIGHT
            bool save = false;
#else
            bool save = (access & AssemblyBuilderAccess.Save) != 0;
#endif
            string path = options.OutputPath;
            if (path == null && save) throw new ArgumentNullException("options.OutputPath");

            Universe = universe;

            TypeMapper = typeMapper;
            _access = access;

            if (Helpers.IsNullOrEmpty(assemblyName))
            {
                if (save) throw new ArgumentNullException(nameof(assemblyName));
                assemblyName = Guid.NewGuid().ToString();
            }
            
            string moduleName = path == null ? assemblyName : assemblyName + Path.GetExtension(path);

            _fileName = path;

            AssemblyName an = new AssemblyName();
            an.Name = assemblyName;

            AssemblyBuilder =
#if !SILVERLIGHT
                path != null ? Universe.DefineDynamicAssembly(an, access, Path.GetDirectoryName(path)) :
#endif
                    Universe.DefineDynamicAssembly(an, access);
#if FEAT_IKVM
            if (!Helpers.IsNullOrEmpty(options.KeyFile))
            {
               AssemblyBuilder.__SetAssemblyKeyPair(new StrongNameKeyPair(File.OpenRead(options.KeyFile)));
            }
            else if (!Helpers.IsNullOrEmpty(options.KeyContainer))
            {
                AssemblyBuilder.__SetAssemblyKeyPair(new StrongNameKeyPair(options.KeyContainer));
            }
            else if (!Helpers.IsNullOrEmpty(options.PublicKey))
            {
                AssemblyBuilder.__SetAssemblyPublicKey(FromHex(options.PublicKey));
            }
            if (!Helpers.IsNullOrEmpty(options.ImageRuntimeVersion) && options.MetaDataVersion != 0)
            {
                AssemblyBuilder.__SetImageRuntimeVersion(options.ImageRuntimeVersion, options.MetaDataVersion);
            }
            ModuleBuilder = AssemblyBuilder.DefineDynamicModule(moduleName, path, options.SymbolInfo);
#else
            if (save)
            {
#if !SILVERLIGHT
                ModuleBuilder = AssemblyBuilder.DefineDynamicModule(moduleName, Path.GetFileName(path));
#else
                throw new NotSupportedException("Can't save on this platform");
#endif
            }
            else
                ModuleBuilder = AssemblyBuilder.DefineDynamicModule(moduleName);
#endif
        }