예제 #1
0
 public ExtensionMethodResolver(Dictionary<string, bool> namespaces, ReferencedAssemblyCache asmCache)
 {
     _Namespaces = namespaces;
     _AsmCache = asmCache;
 }
예제 #2
0
파일: TypeResolver.cs 프로젝트: taekun/lens
 public TypeResolver(Dictionary <string, bool> namespaces, ReferencedAssemblyCache asmCache)
 {
     _Cache      = new Dictionary <string, Type>();
     _Namespaces = namespaces;
     _AsmCache   = asmCache;
 }
예제 #3
0
파일: TypeResolver.cs 프로젝트: menozz/lens
 public TypeResolver(Dictionary<string, bool> namespaces, ReferencedAssemblyCache asmCache)
 {
     _Cache = new Dictionary<string, Type>();
     _Namespaces = namespaces;
     _AsmCache = asmCache;
 }
예제 #4
0
 public ExtensionMethodResolver(Dictionary <string, bool> namespaces, ReferencedAssemblyCache asmCache)
 {
     _Namespaces = namespaces;
     _AsmCache   = asmCache;
 }
예제 #5
0
파일: Context.cs 프로젝트: menozz/lens
        public Context(LensCompilerOptions options = null)
        {
            Options = options ?? new LensCompilerOptions();

            _DefinedTypes = new Dictionary<string, TypeEntity>();
            _DefinedProperties = new Dictionary<string, GlobalPropertyInfo>();

            Unique = new UniqueNameGenerator();

            if (Options.UseDefaultNamespaces)
            {
                Namespaces.Add("System", true);
                Namespaces.Add("System.Linq", true);
                Namespaces.Add("System.Text.RegularExpressions", true);
            }

            _AssemblyCache = new ReferencedAssemblyCache(Options.UseDefaultAssemblies);
            _ExtensionResolver = new ExtensionMethodResolver(Namespaces, _AssemblyCache);
            _TypeResolver = new TypeResolver(Namespaces, _AssemblyCache)
            {
                ExternalLookup = name =>
                {
                    TypeEntity ent;
                    _DefinedTypes.TryGetValue(name, out ent);
                    return ent == null ? null : ent.TypeBuilder;
                }
            };

            AssemblyName an;
            lock(typeof(Context))
                an = new AssemblyName(Unique.AssemblyName());

            if (Options.AllowSave)
            {
                if(string.IsNullOrEmpty(Options.FileName))
                    Options.FileName = an.Name + (Options.SaveAsExe ? ".exe" : ".dll");

                MainAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave);
                MainModule = MainAssembly.DefineDynamicModule(an.Name, Options.FileName);
            }
            else
            {
                MainAssembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
                MainModule = MainAssembly.DefineDynamicModule(an.Name);
            }

            ContextId = GlobalPropertyHelper.RegisterContext();

            MainType = CreateType(EntityNames.MainTypeName, prepare: false);
            MainType.Kind = TypeEntityKind.Main;
            MainType.Interfaces = new[] {typeof (IScript)};
            MainMethod = MainType.CreateMethod(EntityNames.RunMethodName, typeof(object), Type.EmptyTypes, false, true, false);

            if(Options.LoadStandardLibrary)
                initStdlib();

            InitSafeMode();
        }