Mono.TextTemplating.TemplatingEngine.Run C# (CSharp) Method

Run() public static method

public static Run ( System assem, string type, ITextTemplatingEngineHost host, System culture ) : string
assem System
type string
host ITextTemplatingEngineHost
culture System
return string
			return ccu;
		}
		
		public static string Run (System.Reflection.Assembly assem, string type, ITextTemplatingEngineHost host, System.Globalization.CultureInfo culture)
		{
			Type transformType = assem.GetType (type);
		    var extendedHost = host as IExtendedTextTemplatingEngineHost;

		    TextTransformation tt;
            if (extendedHost != null)
                tt = extendedHost.CreateInstance(transformType);
            else
			    tt = (TextTransformation)Activator.CreateInstance (transformType);
			
			//set the host property if it exists
			System.Reflection.PropertyInfo hostProp = transformType.GetProperty ("Host", typeof (ITextTemplatingEngineHost));
			if (hostProp != null && hostProp.CanWrite)
				hostProp.SetValue (tt, host, null);
			
			//set the culture
			if (culture != null)
				ToStringHelper.FormatProvider = culture;
			else
				ToStringHelper.FormatProvider = System.Globalization.CultureInfo.InvariantCulture;
			
			tt.Initialize ();
			string output = tt.TransformText ();
			host.LogErrors (tt.Errors);
			ToStringHelper.FormatProvider = System.Globalization.CultureInfo.InvariantCulture;

Usage Example

        public string Process()
        {
            string output = "";

            try {
                output = TemplatingEngine.Run(assembly, settings.Namespace + "." + settings.Name, host, settings.Culture);
            } catch (Exception ex) {
                parsedTemplate.LogError("Error running transform: " + ex);
            }

            host.LogErrors(parsedTemplate.Errors);
            return(output);
        }