私はmthodを多く持っていますif and else
です。 Switch
でどのように変換できますか?このサンプルメソッドで(IF&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);
}
ありがとうございます。しかし 'Name'はハードコードであり、適切ではありません。 – Ehsan