forked from shengqh/RCPA.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPropertyConverter.cs
84 lines (64 loc) · 2.03 KB
/
IPropertyConverter.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System.Text;
using System.Collections.Generic;
namespace RCPA
{
public interface IPropertyConverter<T>
{
string Version { get; }
string Name { get; }
void AddPropertyTo(StringBuilder sb, T t);
string GetProperty(T t);
void SetProperty(T t, string value);
/// <summary>
/// 根据实际数据,产生相关联的Converter
/// </summary>
/// <param name="items">实际数据列表</param>
/// <returns>关联Converter列表,默认返回null</returns>
List<IPropertyConverter<T>> GetRelativeConverter(List<T> items);
/// <summary>
/// 根据文件读取或者设定的header,产生相关联的Converter
/// </summary>
/// <param name="header">文件读取(或者设定的)header</param>
/// <param name="delimiter">文件读取(或者设定的)分隔字符</param>
/// <returns>关联Converter列表,默认返回null</returns>
List<IPropertyConverter<T>> GetRelativeConverter(string header, char delimiter);
bool HasName(string name);
IPropertyConverter<T> GetConverter(string name);
}
public abstract class AbstractPropertyConverter<T> : IPropertyConverter<T>
{
#region IPropertyConverter<T> Members
public virtual string Version
{
get { return ""; }
}
public abstract string Name { get; }
public void AddPropertyTo(StringBuilder sb, T t)
{
sb.Append(GetProperty(t));
}
public abstract string GetProperty(T t);
public abstract void SetProperty(T t, string value);
public virtual bool HasName(string name)
{
return this.Name.Equals(name);
}
public virtual List<IPropertyConverter<T>> GetRelativeConverter(List<T> items)
{
return null;
}
public virtual List<IPropertyConverter<T>> GetRelativeConverter(string header, char delimiter)
{
return null;
}
public virtual IPropertyConverter<T> GetConverter(string name)
{
return this;
}
#endregion
public override string ToString()
{
return this.Name;
}
}
}