在c#中使用Factory模式返回对象和List <object>

时间:2017-05-12 08:51:53

标签: c# design-patterns factory-pattern

我有两个班级

public class LoginModel : IBaseInterface
{
   public string EmailAddress { get; set; }
   public string Password { get; set; }
}

public class UsersModel : IBaseInterface
{
    public int UserID { get; set; }
    public string UserName { get; set; }
    public string EmailAddress { get; set; }
    public int RoleID { get; set; }
    public string RoleName { get; set; }
    public int ProjectID { get; set; }
    public string ProjectName { get; set; }
    public int PMID { get; set; }
    public string PMEmailAddress { get; set; }
    public string PMEmailName { get; set; }
    public int DMID { get; set; }
    public string DMEmailAddress { get; set; }
    public string DMEmailName { get; set; }
}

IBaseInterface是一个界限,没有任何定义。

public static IBaseInterface Create(ObjectsCollection Type)
    {
        switch (Type)
        {
            default:
                return null;
            case ObjectsCollection.UsersModel:
                return new UsersModel();
            case ObjectsCollection.LoginModel:
                return new LoginModel();
        }
    }

一切都很好用于物体。但是如何使用此工厂返回List<UsersModel>List<LoginModel>

如果有人请帮我解决这个问题会很好。

由于

0 个答案:

没有答案