コード例 #1
0
        public wrapperStatic compile()
        {
            if (this.compiled)
            {
                return(this.compiledWrapper);
            }
            StringBuilder stringBuilder = new StringBuilder();
            string        staticClass   = "";
            string        instanceClass = "";

            typeDescriptor.addUsingsStatements(stringBuilder);
            this.precompile(stringBuilder, ref staticClass, ref instanceClass);
            stringBuilder.AppendLine("class program{public static void main(){}}");
            try
            {
                jxshell.csharplanguage csharplanguage = typeDescriptor.language;
                csharplanguage.runScript(stringBuilder.ToString(), typeDescriptor.generateInMemory);
                Type            type            = csharplanguage.getCompiledAssembly().GetType(string.Concat("jxshell.dotnet4.", staticClass));
                ConstructorInfo constructorInfo = type.GetConstructor(new Type[] { typeof(Type), typeof(typeDescriptor) });
                this.compiledWrapper = (wrapperStatic)constructorInfo.Invoke(new object[] { this.type, this });
                this.compiled        = true;
            }
            catch (Exception exception)
            {
                Exception ex = exception;
                throw new Exception(string.Concat("No se puede obtener un wrapper para el tipo ", this.type.ToString(), ". ", ex.Message), ex);
            }
            return(this.compiledWrapper);
        }
コード例 #2
0
        public void loadManyTypes(Type[] types)
        {
            StringBuilder stringBuilder = new StringBuilder();

            jxshell.dotnet4.typeDescriptor.addUsingsStatements(stringBuilder);
            Dictionary <Type, type_1> dictionary = new Dictionary <Type, type_1>();

            Type[] typeArray = types;
            for (int i = 0; i < (int)typeArray.Length; i++)
            {
                Type type = typeArray[i];
                if (!type.IsGenericType && type.IsPublic)
                {
                    jxshell.dotnet4.typeDescriptor typeDescriptor = new jxshell.dotnet4.typeDescriptor(type, jxshell.dotnet4.typeDescriptor.getNameForType(type), false);
                    if (!typeDescriptor.isCompiled())
                    {
                        string staticClass   = "";
                        string instanceClass = "";
                        typeDescriptor.precompile(stringBuilder, ref staticClass, ref instanceClass);
                        dictionary[type] = new type_1()
                        {
                            td            = typeDescriptor,
                            staticClass   = staticClass,
                            instanceClass = instanceClass,
                            t             = type
                        };
                    }
                }
            }
            stringBuilder.AppendLine("class program{public static void main(){}}");
            jxshell.csharplanguage csharplanguage = (jxshell.csharplanguage)language.defaultLanguage.create();
            if (dictionary.Count > 0)
            {
                csharplanguage.runScript(stringBuilder.ToString(), jxshell.dotnet4.typeDescriptor.generateInMemory);
            }
            foreach (KeyValuePair <Type, type_1> item in dictionary)
            {
                type_1          value       = item.Value;
                Type            type2       = csharplanguage.getCompiledAssembly().GetType(string.Concat("jxshell.dotnet4.", value.staticClass));
                ConstructorInfo constructor = type2.GetConstructor(new Type[] { typeof(Type), typeof(jxshell.dotnet4.typeDescriptor) });
                value.td.setCompiledWrapper((wrapperStatic)constructor.Invoke(new object[] { value.t, value.td }));
            }
        }