messagetemplates / messagetemplates-fsharp

Message templates - the ability to format named string values, and capture the properties
http://messagetemplates.org/
Apache License 2.0
18 stars 4 forks source link

Decide on a public C# API #6

Closed adamchester closed 8 years ago

adamchester commented 9 years ago

As per this comment, the C# API might be as follows:

public class MessageTemplate
{
    public MessageTemplate(string templateMessage);
    public string Format(params object[] args);
    public void Format(TextWriter writer, params object[] args);
    public IEnumerable<TemplateProperty> Capture(params object[] args);
}

// And some static helpers
public static class Template
{
    public static MessageTemplate Parse(string templateMessage);
    public static IEnumerable<TemplateProperty> Capture(string templateMessage, params object[] args);
    public static void Format(IFormatProvider formatProvider, System.IO.TextWriter output, string templateMessage, params object[] args);
    public static string Format(IFormatProvider formatProvider, string templateMessage, params object[] args);
    public static string Format(string templateMessage, params object[] args);
}
nblumhardt commented 9 years ago

LGTM!

FWIW, one thing that might be desirable on the MessageTemplate class is a Format(TextWriter, ...) option, the difference in allocations is going to be significant when argument strings are large.

adamchester commented 9 years ago

Thanks @nblumhardt, you are right, I have added a TextWriter overload here, and also in #5.