/// <summary> /// Adds all formatter that are decorated with the <see cref="MorestachioFormatterAttribute" /> /// </summary> public static void AddFromType(this IMorestachioFormatterService service, Type type) { foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)) { var hasFormatterAttr = method.GetCustomAttributes <MorestachioFormatterAttribute>(); foreach (var morestachioFormatterAttribute in hasFormatterAttr) { if (morestachioFormatterAttribute == null) { continue; } service.Add(method, morestachioFormatterAttribute); } } foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public)) { var hasFormatterAttr = method.GetCustomAttributes <MorestachioFormatterAttribute>(); foreach (var morestachioFormatterAttribute in hasFormatterAttr) { if (morestachioFormatterAttribute == null) { continue; } morestachioFormatterAttribute.LinkFunctionTarget = true; morestachioFormatterAttribute.IsSourceObjectAware = false; service.Add(method, morestachioFormatterAttribute); } } }
/// <summary> /// Adds a new Function to the list of formatters /// </summary> public static MultiFormatterInfoCollection AddSingleGlobal(this IMorestachioFormatterService service, Delegate function, [CanBeNull] string name = null) { return(service.AddSingle(function, new MorestachioGlobalFormatterAttribute(name, "Autogenerated description") { OutputType = function.Method.ReturnType, ReturnHint = "None", })); }
/// <summary> /// Adds a new Function to the list of formatters /// </summary> public static MultiFormatterInfoCollection AddSingle(this IMorestachioFormatterService service, Delegate function, [NotNull] MorestachioFormatterAttribute attribute) { attribute.OutputType = function.Method.ReturnType; attribute.ReturnHint = "None"; var morestachioFormatterModel = service.Add(function.Method, attribute); morestachioFormatterModel.FunctionTarget = function.Target; return(morestachioFormatterModel.MetaData); }
public static MultiFormatterInfoCollection AddSingle(this IMorestachioFormatterService service, Delegate function, [CanBeNull] string name = null) { var morestachioFormatterModel = service.Add(function.Method, new MorestachioFormatterAttribute(name, "Autogenerated description") { OutputType = function.Method.ReturnType, ReturnHint = "None", }); morestachioFormatterModel.FunctionTarget = function.Target; return(morestachioFormatterModel.MetaData); }
/// <summary> /// Initializes a new instance of the <see cref="ParserOptions" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="sourceStream">The source stream.</param> /// <param name="encoding">The encoding.</param> public ParserOptions([NotNull] string template, [CanBeNull] Func <Stream> sourceStream, [CanBeNull] Encoding encoding) { Template = template ?? ""; SourceFactory = sourceStream ?? (() => new MemoryStream()); Encoding = encoding ?? Encoding.UTF8; _formatters = new MorestachioFormatterService(); Null = string.Empty; MaxSize = 0; DisableContentEscaping = false; WithModelInference = false; Timeout = TimeSpan.Zero; PartialStackSize = 255; }
/// <summary> /// Adds all formatter that are decorated with the <see cref="MorestachioFormatterAttribute" /> /// </summary> /// <param name="type">The type.</param> public static void AddFromType(this IMorestachioFormatterService service, Type type) { foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Public)) { var hasFormatterAttr = method.GetCustomAttributes <MorestachioFormatterAttribute>(); foreach (var morestachioFormatterAttribute in hasFormatterAttr) { if (morestachioFormatterAttribute == null) { continue; } service.Add(method, morestachioFormatterAttribute); } } }
/// <summary> /// Initializes a new instance of the <see cref="ParserOptions" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="sourceStream">The source stream.</param> /// <param name="encoding">The encoding.</param> public ParserOptions([NotNull] string template, [CanBeNull] Func <Stream> sourceStream, [CanBeNull] Encoding encoding) { Template = template ?? ""; StreamFactory = new ByteCounterFactory(sourceStream); Encoding = encoding ?? Encoding.UTF8; _formatters = new MorestachioFormatterService(); Null = string.Empty; MaxSize = 0; DisableContentEscaping = false; Timeout = TimeSpan.Zero; PartialStackSize = 255; _customDocumentItemProviders = new SealableList <CustomDocumentItemProvider>(); CultureInfo = CultureInfo.CurrentCulture; }
/// <summary> /// Initializes a new instance of the <see cref="ParserOptions" /> class. /// </summary> /// <param name="template">The template.</param> /// <param name="sourceStream">The source stream.</param> /// <param name="encoding">The encoding.</param> public ParserOptions(ITemplateContainer template, Func <ParserOptions, IByteCounterStream> sourceStream, Encoding encoding) { Template = template ?? new StringTemplateContainer(""); StreamFactory = new ByteCounterFactory(sourceStream); Encoding = encoding ?? Encoding.UTF8; _formatters = new MorestachioFormatterService(); Null = string.Empty; MaxSize = 0; DisableContentEscaping = false; Timeout = TimeSpan.Zero; PartialStackSize = 255; _customDocumentItemProviders = new CustomDocumentList(); CultureInfo = CultureInfo.CurrentCulture; UnmatchedTagBehavior = UnmatchedTagBehavior.ThrowError | UnmatchedTagBehavior.LogWarning; }
static MorestachioFormatterService() { Default = new MorestachioFormatterService(); }
public static MultiFormatterInfoCollection AddSingle <T, T1, T2, T3, T4>(this IMorestachioFormatterService service, Func <T, T1, T2, T3, T4> function, [CanBeNull] string name = null) { return(service.AddSingle((Delegate)function, name)); }
/// <summary> /// Adds all formatter that are decorated with the <see cref="MorestachioFormatterAttribute" /> /// </summary> public static void AddFromType <T>(this IMorestachioFormatterService service) { AddFromType(service, typeof(T)); }
/// <summary> /// Adds a new Function to the list of formatters /// </summary> public static MultiFormatterInfoCollection AddSingleGlobal <T, T1, T2>(this IMorestachioFormatterService service, Action <T, T1, T2> function, [CanBeNull] string name = null) { return(service.AddSingleGlobal((Delegate)function, name)); }
/// <summary> /// Adds a new Function to the list of formatters /// </summary> public static MultiFormatterInfoCollection AddSingleGlobal <T, T1, T2, T3, T4>(this IMorestachioFormatterService service, Func <T, T1, T2, T3, T4> function, string name) { return(service.AddSingleGlobal((Delegate)function, name)); }
/// <summary> /// Adds a new Function to the list of formatters /// </summary> public static MultiFormatterInfoCollection AddSingle <T>(this IMorestachioFormatterService service, Func <T> function, string name) { return(service.AddSingle((Delegate)function, name)); }