示例#1
0
 /// <summary>
 /// Compiles if necessary.
 /// </summary>
 public static void CompileIfNecessary()
 {
     if (compilerResults == null || compilerResults.CompiledAssembly == null)
     {
         compilerResults = RuntimeCompiler.Compile(translation, runtimeNamespace, runtimeClassName);
     }
 }
示例#2
0
        /// <summary>
        /// Compiles the specified translation.
        /// </summary>
        /// <param name="translation">The translation.</param>
        /// <param name="directoryName">Name of the directory.</param>
        /// <param name="runtimeNamespace">The runtime namespace.</param>
        /// <param name="runtimeClassName">Name of the runtime class.</param>
        /// <returns></returns>
        public static CompilerResults Compile(Translation translation, string directoryName,
                                              string runtimeNamespace, string runtimeClassName)
        {
            CompilerParameters parameters = new CompilerParameters();

            parameters.GenerateInMemory      = true;
            parameters.TreatWarningsAsErrors = false;
            parameters.GenerateExecutable    = false;
            parameters.CompilerOptions       = "/optimize";
            parameters.ReferencedAssemblies.AddRange(translation.CodeModules.ToArray());
            CSharpCodeProvider provider      = new CSharpCodeProvider();
            string             lastDirectory = Directory.GetCurrentDirectory();
            CompilerResults    compiler      = null;

            try
            {
                Directory.SetCurrentDirectory(directoryName);
                compiler = provider.CompileAssemblyFromSource(parameters,
                                                              new string[] { RuntimeCompiler.ToCSharpCode(translation).ToString() });
                if (compiler.Errors.HasErrors)
                {
                    StringBuilder str = new StringBuilder();
                    foreach (CompilerError ce in compiler.Errors)
                    {
                        str.AppendLine(ce.ToString());
                    }
                    throw new Exception("Compile error\r\n" + str.ToString());
                }
            }
            finally
            {
                Directory.SetCurrentDirectory(lastDirectory);
            }
            return(compiler);
        }
示例#3
0
 /// <summary>
 /// Gets the runtime compiled class (compile if necessary).
 /// </summary>
 /// <returns></returns>
 public static Type GetRuntimeClass()
 {
     CompileIfNecessary();
     if (compilerResults != null)
     {
         return(RuntimeCompiler.GetCompiledClass(compilerResults));
     }
     return(null);
 }
示例#4
0
        /// <summary>
        /// Compiles if necessary.
        /// </summary>
        public static void CompileIfNecessary()
        {
            if (translation.Count == 0)
            {
                translation.Read(TranslationDirectory);
            }

            if (translation.Count == 0)
            {
                if (ReportErrors)
                {
                    throw new Exception("NLocalizer: Translation is empty. Please enter any .lang file in Your program directory or any subdirectory.");
                }
                return;
            }

            if (compilerResults == null || compilerResults.CompiledAssembly == null)
            {
                compilerResults = RuntimeCompiler.Compile(translation);
            }
        }
示例#5
0
 /// <summary>
 /// Generates the translation code in C# into StringBuilder.
 /// </summary>
 /// <returns></returns>
 public StringBuilder GenerateCode(Assembly assembly)
 {
     return(RuntimeCompiler.ToCSharpCode(this, RuntimeCompiler.GetCompileUsings(this, assembly), GetMacros()));
 }
示例#6
0
 /// <summary>
 /// Shows the className as form.
 /// </summary>
 /// <param name="className">Name of the class.</param>
 public static void ShowDialog(string className)
 {
     RuntimeCompiler.ShowDialog(GetRuntimeClass(), className);
 }
示例#7
0
 /// <summary>
 /// Creates the specified class name.
 /// </summary>
 /// <param name="className">Name of the class.</param>
 /// <returns></returns>
 public static object Create(string className)
 {
     return(RuntimeCompiler.Create(GetRuntimeClass(), className));
 }
示例#8
0
 /// <summary>
 /// Restores all static classes into neutral language.
 /// </summary>
 public static void Restore()
 {
     RuntimeCompiler.Restore(GetRuntimeClass(), translation);
 }
示例#9
0
 /// <summary>
 /// Restores the specified obj into neutral language.
 /// </summary>
 /// <param name="obj">The obj.</param>
 public static void Restore(object obj)
 {
     RuntimeCompiler.Restore(GetRuntimeClass(), obj, translation);
 }
示例#10
0
 /// <summary>
 /// Translates all static classes into current language.
 /// </summary>
 public static void Translate()
 {
     RuntimeCompiler.Translate(GetRuntimeClass(), translation);
 }
示例#11
0
 /// <summary>
 /// Translates all static classes into specified language.
 /// </summary>
 /// <param name="language">The language.</param>
 public static void Translate(string language)
 {
     RuntimeCompiler.Translate(GetRuntimeClass(), language, translation);
 }
示例#12
0
 /// <summary>
 /// Generates the translation code in C# into StringBuilder.
 /// </summary>
 /// <returns></returns>
 public StringBuilder GenerateCode()
 {
     return(RuntimeCompiler.ToCSharpCode(this));
 }
示例#13
0
 /// <summary>
 /// Translates the specified obj into current language.
 /// </summary>
 /// <param name="obj">The obj.</param>
 public static void Translate(object obj)
 {
     Translate();
     RuntimeCompiler.Translate(GetRuntimeClass(), obj, translation);
 }
示例#14
0
 /// <summary>
 /// Gets the runtime compiled class (compile if necessary).
 /// </summary>
 /// <returns></returns>
 public static Type GetRuntimeClass()
 {
     CompileIfNecessary();
     return(RuntimeCompiler.GetCompiledClass(compilerResults, runtimeNamespace, runtimeClassName));
 }
示例#15
0
 /// <summary>
 /// Generates the translation code in C# into StringBuilder.
 /// </summary>
 /// <param name="runtimeNamespace">The runtime namespace.</param>
 /// <param name="runtimeClassName">Name of the runtime class.</param>
 /// <returns></returns>
 public StringBuilder GenerateCode(string runtimeNamespace, string runtimeClassName)
 {
     return(RuntimeCompiler.ToCSharpCode(this, runtimeNamespace, runtimeClassName));
 }
示例#16
0
 /// <summary>
 /// Compiles the translation.
 /// </summary>
 /// <param name="directoryName">Name of the directory.</param>
 /// <param name="runtimeNamespace">The runtime namespace.</param>
 /// <param name="runtimeClassName">Name of the runtime class.</param>
 /// <returns></returns>
 public CompilerResults Compile(string directoryName, string runtimeNamespace, string runtimeClassName)
 {
     return(RuntimeCompiler.Compile(this, directoryName, runtimeNamespace, runtimeClassName));
 }
示例#17
0
 /// <summary>
 /// Compiles the translation.
 /// </summary>
 /// <param name="directoryName">Name of the directory.</param>
 /// <returns></returns>
 public CompilerResults Compile(string directoryName)
 {
     return(RuntimeCompiler.Compile(this, directoryName));
 }
示例#18
0
 /// <summary>
 /// Compiles the translation.
 /// </summary>
 /// <returns></returns>
 public CompilerResults Compile()
 {
     return(RuntimeCompiler.Compile(this));
 }