/// <summary> /// Compiles if necessary. /// </summary> public static void CompileIfNecessary() { if (compilerResults == null || compilerResults.CompiledAssembly == null) { compilerResults = RuntimeCompiler.Compile(translation, runtimeNamespace, runtimeClassName); } }
/// <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); }
/// <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); }
/// <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); } }
/// <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())); }
/// <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); }
/// <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)); }
/// <summary> /// Restores all static classes into neutral language. /// </summary> public static void Restore() { RuntimeCompiler.Restore(GetRuntimeClass(), translation); }
/// <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); }
/// <summary> /// Translates all static classes into current language. /// </summary> public static void Translate() { RuntimeCompiler.Translate(GetRuntimeClass(), translation); }
/// <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); }
/// <summary> /// Generates the translation code in C# into StringBuilder. /// </summary> /// <returns></returns> public StringBuilder GenerateCode() { return(RuntimeCompiler.ToCSharpCode(this)); }
/// <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); }
/// <summary> /// Gets the runtime compiled class (compile if necessary). /// </summary> /// <returns></returns> public static Type GetRuntimeClass() { CompileIfNecessary(); return(RuntimeCompiler.GetCompiledClass(compilerResults, runtimeNamespace, runtimeClassName)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <summary> /// Compiles the translation. /// </summary> /// <returns></returns> public CompilerResults Compile() { return(RuntimeCompiler.Compile(this)); }