Created
July 13, 2011 04:47
-
-
Save jmarnold/1079734 to your computer and use it in GitHub Desktop.
Conventions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IConfigurationAction | |
{ | |
void Configure(SemanticModel model); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReusableDateConvention : IConfigurationAction | |
{ | |
public void Configure(SemanticModel model) | |
{ | |
model.AddStringifier(new LambdaStringifier(r => r.RequestType == typeof(DateTime), | |
r => ((DateTime)r.RawValue).ToString("MM/dd/yyyy HH:mm:ss"))) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StringifierRegistry | |
{ | |
private readonly StringifierModel _model = new StringifierModel(); | |
private readonly IList<IConfigurationAction> _conventions = new List<IConfigurationAction>(); | |
public StringifierRegistry() | |
{ | |
AddStringifier<DefaultStringifier>(); | |
} | |
public void AddStringifier<TStringifier>() | |
where TStringifier : IStringifier | |
{ | |
_model.AddStringifier(typeof(TStringifier)); | |
} | |
public void AddStringifier(IStringifier stringifier) | |
{ | |
_model.AddStringifier(stringifier); | |
} | |
public void ApplyConvention<TConvention>() | |
where TConvention : IConfigurationAction, new() | |
{ | |
ApplyConvention(new TConvention()); | |
} | |
public void ApplyConvention(IConfigurationAction convention) | |
{ | |
_conventions.Add(convention); | |
} | |
public ConfigureStringifierExpression IfRequestMatches(Func<StringifyRequest, bool> predicate) | |
{ | |
return new ConfigureStringifierExpression(predicate, _model); | |
} | |
public StringifierModel BuildModel() | |
{ | |
_conventions.Each(c => c.Configure(_model)); | |
return _model; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment