【发布时间】:2011-12-04 04:41:05
【问题描述】:
我有很多if and else 的方法。怎么转换成Switch?
protected override IRepository<T> CreateRepository<T>()
{
if (typeof(T).Equals(typeof(Person)))
return new PersonRepositoryNh(this, SessionInstance) as IRepository<T>;
else if (typeof(T).Equals(typeof(Organization)))
return new OrganizationRepositoryNh(this, SessionInstance) as IRepository<T>;
else
return new RepositoryNh<T>(SessionInstance);
}
【问题讨论】:
标签: c# types if-statement switch-statement