1
我有使用C#6以下通用類:通用方法用的Ti和Ti + 1
public class IncludeMapper<T1> {
private readonly Dictionary<String, List<LambdaExpression>> _properties = new Dictionary<String, List<LambdaExpression>>();
public IncludeMapper<T1> Add<T2, T3>(String property, Expression<Func<T1, T2>> path1, Expression<Func<T2, T3>> path2) {
if (!_properties.ContainsKey(property))
_properties.Add(property, new List<LambdaExpression> { path1, path2 });
return this;
}
public IncludeMapper<T1> Add<T2, T3, T4>(String property, Expression<Func<T1, T2>> path1, Expression<Func<T2, T3>> path2, Expression<Func<T3, T4>> path3) {
if (!_properties.ContainsKey(property))
_properties.Add(property, new List<LambdaExpression> { path1, path2, path3 });
return this;
}
}
Add方法有幾個表達它們取一個的Ti和Ti + 1(路徑)。
有沒有簡化我的代碼的方法?我將至少需要4個像這樣的方法,直到路徑7.
簡答題:不可以擴展答案:[here](http://stackoverflow.com/questions/15417174/using-the-params-keyword-for-generic-parameters-in-c-sharp) – lokusking