Ejemplo n.º 1
0
 /// <summary>
 /// Compiles if necessary.
 /// </summary>
 public static void CompileIfNecessary()
 {
     if (compilerResults == null || compilerResults.CompiledAssembly == null)
     {
         compilerResults = RuntimeCompiler.Compile(translation, runtimeNamespace, runtimeClassName);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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()));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Restores all static classes into neutral language.
 /// </summary>
 public static void Restore()
 {
     RuntimeCompiler.Restore(GetRuntimeClass(), translation);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Translates all static classes into current language.
 /// </summary>
 public static void Translate()
 {
     RuntimeCompiler.Translate(GetRuntimeClass(), translation);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Generates the translation code in C# into StringBuilder.
 /// </summary>
 /// <returns></returns>
 public StringBuilder GenerateCode()
 {
     return(RuntimeCompiler.ToCSharpCode(this));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Compiles the translation.
 /// </summary>
 /// <returns></returns>
 public CompilerResults Compile()
 {
     return(RuntimeCompiler.Compile(this));
 }