Exemplo n.º 1
0
        public TypeGen(TypeBuilder typeBuilder, ITypeMapper typeMapper)
            : base(typeMapper)
        {
            Name        = typeBuilder.Name;
            BaseType    = typeBuilder.BaseType;
            _interfaces = typeBuilder.GetInterfaces();
            _typeMapper = typeMapper;

            _ownExpressionFactory = new ExpressionFactory(typeMapper);
            _ownStaticFactory     = new StaticFactory(TypeMapper);

            TypeBuilder = typeBuilder;
            typeMapper.TypeInfo.RegisterProvider(TypeBuilder, this);

            ResetAttrs();
        }
Exemplo n.º 2
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);

            bool   save = (access & AssemblyBuilderAccess.Save) != 0;
            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 = path != null
                                  ? Universe.DefineDynamicAssembly(an, access, Path.GetDirectoryName(path))
                                  : 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
            ModuleBuilder = save ? AssemblyBuilder.DefineDynamicModule(moduleName, Path.GetFileName(path)) : AssemblyBuilder.DefineDynamicModule(moduleName);
#endif
        }
Exemplo n.º 3
0
 public Context(ITypeMapper typeMapper, StaticFactory staticFactory, ExpressionFactory expressionFactory)
 {
     TypeMapper        = typeMapper;
     StaticFactory     = staticFactory;
     ExpressionFactory = expressionFactory;
 }