-
Notifications
You must be signed in to change notification settings - Fork 43
/
StatelessConverter.cs
52 lines (43 loc) · 1.57 KB
/
StatelessConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using FubuCore.Descriptions;
namespace FubuCore.Conversion
{
public abstract class StatelessConverter : IObjectConverterFamily, IConverterStrategy
{
public abstract object Convert(IConversionRequest request);
public abstract bool Matches(Type type, ConverterLibrary converter);
public IConverterStrategy CreateConverter(Type type, Func<Type, IConverterStrategy> converterSource)
{
return this;
}
public virtual void Describe(Description description)
{
// no-op;
}
}
public abstract class StatelessConverter<TReturnType> : StatelessConverter
{
public override sealed bool Matches(Type type, ConverterLibrary converter)
{
return type == typeof (TReturnType);
}
public override sealed object Convert(IConversionRequest request)
{
return convert(request.Text);
}
protected abstract TReturnType convert(string text);
}
public abstract class StatelessConverter<TReturnType, TService> : StatelessConverter
{
public override sealed bool Matches(Type type, ConverterLibrary converter)
{
return type == typeof(TReturnType);
}
public override sealed object Convert(IConversionRequest request)
{
var service = request.Get<TService>();
return convert(service, request.Text);
}
protected abstract TReturnType convert(TService service, string text);
}
}