createObject() public static method

public static createObject ( IoState state ) : IoCLRAssembly
state IoState
return IoCLRAssembly
コード例 #1
0
ファイル: IoCLR.cs プロジェクト: MilkTool/io-clr
        public static IoObject slotLoadAssembly(IoObject target, IoObject locals, IoObject message)
        {
            IoCLR         self         = target as IoCLR;
            IoMessage     m            = message as IoMessage;
            IoSeq         assemblyName = m.localsSymbolArgAt(locals, 0);
            IoCLRAssembly asm          = self.loadedAssemblies[assemblyName.value] as IoCLRAssembly;

            if (asm != null)
            {
                return(asm);
            }

            asm = IoCLRAssembly.createObject(target.state);

            asm.assembly = Assembly.LoadWithPartialName(assemblyName.value);
            if (asm.assembly == null)
            {
                return(self);
            }

            self.loadedAssemblies[assemblyName.value] = asm;

            asm.assemblyTypes      = asm.assembly.GetTypes();
            asm.assemblyNamespaces = new Hashtable();
            foreach (Type t in asm.assemblyTypes)
            {
                string theNameSpace = t.FullName.LastIndexOf(".") == -1 ? "-" : t.FullName.Substring(0, t.FullName.LastIndexOf("."));
                string theClass     = t.FullName.LastIndexOf(".") == -1 ? t.FullName : t.FullName.Substring(t.FullName.LastIndexOf(".") + 1);
                if (theClass.Equals("Form"))
                {
                    int i = 0;
                }
                if (asm.assemblyNamespaces.ContainsKey(theNameSpace))
                {
                    Hashtable a = asm.assemblyNamespaces[theNameSpace] as Hashtable;
                    a[theClass] = t;
                }

                else
                {
                    Hashtable classes = new Hashtable();
                    classes[theClass] = t;
                    asm.assemblyNamespaces[theNameSpace] = classes;
                }
            }
            return(asm);
        }
コード例 #2
0
        public static IoObject slotLoadAssembly(IoObject target, IoObject locals, IoObject message)
        {
            IoCLR         self         = target as IoCLR;
            IoMessage     m            = message as IoMessage;
            IoSeq         assemblyName = m.localsSymbolArgAt(locals, 0);
            IoCLRAssembly asm          = null;

            if (self.loadedAssemblies.ContainsKey(assemblyName.value))
            {
                asm = self.loadedAssemblies[assemblyName.value];
                if (asm != null)
                {
                    return(asm);
                }
            }

            asm = IoCLRAssembly.createObject(target.state);
            var name = new AssemblyName(assemblyName.value);

            try
            {
                asm.assembly = Assembly.Load(name);
                Console.WriteLine("载入{0} ....成功!", name.Name);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("载入{0} ....失败!", name.Name);
            }

            if (asm.assembly == null)
            {
                return(self);
            }

            self.loadedAssemblies[assemblyName.value] = asm;

            asm.assemblyTypes      = asm.assembly.GetTypes();
            asm.assemblyNamespaces = new Dictionary <string, Dictionary <string, Type> >();
            foreach (Type t in asm.assemblyTypes)
            {
                string theNameSpace = t.FullName.LastIndexOf(".") == -1 ? "-" : t.FullName.Substring(0, t.FullName.LastIndexOf("."));
                string theClass     = t.FullName.LastIndexOf(".") == -1 ? t.FullName : t.FullName.Substring(t.FullName.LastIndexOf(".") + 1);
                if (theClass.Equals("Form"))
                {
                    //~//int i = 0;
                }

                if (asm.assemblyNamespaces.ContainsKey(theNameSpace))
                {
                    Dictionary <string, Type> a = asm.assemblyNamespaces[theNameSpace];
                    a[theClass] = t;
                }
                else
                {
                    Dictionary <string, Type> classes = new Dictionary <string, Type>();
                    classes[theClass] = t;
                    asm.assemblyNamespaces[theNameSpace] = classes;
                }
            }
            return(asm);
        }