首页 文章

继承问题

提问于
浏览
-2

我有继承问题 . 我有一个名为 Irewhizz 的界面:

interface Irewhizz {
    void object save(object obj);
    void object getdata(object obj);
}

我把这个定义写在另一个类中:

public user:irewhzz {
    public object save(object obj);
    public object getdata(object obj);
}
public client:irewhzz {
    public object save(object obj);
    public object getdata(object obj);
}

现在我有不同的类,如:

public partial class RwUser
{

    #region variables

    IRewhizzDataHelper irewhizz;
    IRewhizzRelationDataHelper irewhizzrelation;

    #endregion

    //IRewhizz is the interface and its functions are implimented by UserDataHelper class
    //RwUser Class is inheriting the UserDataHelper Properties and functions.
    //Here UserDataHelper functions are called with Irewhizz Interface Object but not with the 
    //UserDataHelper class Object It will resolves the unit testing conflict.

    #region Constructors
    public RwUser() : this(new UserDataHelper(), new RewhizzRelationalDataHelper()) { }
    public RwUser(IRewhizzDataHelper repositary, IRewhizzRelationDataHelper relationrepositary) {
     irewhizz = repositary;
     irewhizzrelation = relationrepositary;
    }
    #endregion

    #region Properties
    public int Role { get; set; }

      public string MobilePhone { get; set; }
      public bool ChangePassword { get; set; }
      public byte[] Image { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string MiddleName { get; set; }
      public string Email { get; set; }
      public string Website { get; set; }
      public int AddressId { get; set; }
      public string City { get; set; }
      public string Zipcode { get; set; }
      public string Phone { get; set; }
      public string Fax { get; set; }
      public string AboutMe { get; set; }
      public string username { get; set; }
      public string password { get; set; }
      public string SecurityQuestion { get; set; }
      public string SecurityQAnswer { get; set; }
      public Guid UserID { get; set; }
      public long RwUserID { get; set; }
      #endregion

      #region MemberFunctions
      // DataHelperDataContext db = new DataHelperDataContext();
      // RewhizzDataHelper rwdh=new RewhizzDataHelper();

      //It saves user information entered by user and returns the id of that user 
      public object saveUserInfo(RwUser userObj) {

       userObj.UserID = irewhizzrelation.GetUserId(username);
       var res = irewhizz.saveData(userObj);
       return res;
      }

      //It returns the security questions for user registration
}

public class Agent : RwUser
     {
      IRewhizzDataHelper irewhizz;
      IRewhizzRelationDataHelper irewhizzrelation;
      public string Locations { get; set; }
      public string SelectedLanguages { get; set; }
      public string SelectedSpecialization { get; set; }
      public string RegisteredStates { get; set; }
      public string AgentID { get; set; }
      public string ExpDate { get; set; }
      public SelectList RegisterStates { get; set; }
      public SelectList Languages { get; set; }
      public SelectList Specializations { get; set; }
      public int[] RegisterdStates { get; set; }
      public int RoleId { get; set; }
      public int SpeclisationId { get; set; }
      public int[] Language { get; set; }
      public int LocationTypeId { get; set; }
      public string BrokarageCompany { get; set; }
      public string Rolename { get; set; }
      public int[] Specialization { get; set; }

      public Agent() : this(new AgentDataHelper(), new RewhizzRelationalDataHelper()) { }

      public Agent(IRewhizzDataHelper repositary, IRewhizzRelationDataHelper relationrepositary) {
       irewhizz = repositary;
       irewhizzrelation = relationrepositary;
      }

      public void inviteclient() {
       //Code related to mailing
      }

      public Agent updateData(Agent objectId) {
       objectId.UserID = irewhizzrelation.GetUserId(objectId.username);
       objectId = (Agent)irewhizz.updateData(objectId);
       return objectId;
      }

      public Agent GetAgentData(Agent agentodj) {
       agentodj.UserID = irewhizzrelation.GetUserId(agentodj.username);
       agentodj = (Agent)irewhizz.getData(agentodj);
       if (agentodj.RoleId != 0)
        agentodj.Rolename = (string)(string)irewhizzrelation.getValue(agentodj.RoleId);

       if (agentodj.RegisterdStates.Count() != 0) {
        List<SelectListItem> list = new List<SelectListItem>();
        string regstates = "";
        foreach (int i in agentodj.RegisterdStates) {
         SelectListItem listitem = new SelectListItem();
         listitem.Value = i.ToString();
         listitem.Text = (string)irewhizzrelation.getValue(i);
         list.Add(listitem);
         regstates += (string)irewhizzrelation.getValue(i) + ",";
        }

        SelectList selectlist = new SelectList(list, "Value", "Text");
        agentodj.RegisterStates = selectlist;
        if(regstates!=null)
            agentodj.RegisteredStates = regstates.Remove(regstates.Length - 1);
       }

       if (agentodj.Language.Count() != 0){
        List<SelectListItem> list = new List<SelectListItem>();
        string selectedlang = "";
        foreach (int i in agentodj.Language) {
         SelectListItem listitem = new SelectListItem();
         listitem.Value = i.ToString();
         listitem.Text = (string)irewhizzrelation.getValue(i);
         list.Add(listitem);
         selectedlang += (string)irewhizzrelation.getValue(i) + ",";
        }

        SelectList selectlist = new SelectList(list, "Value", "Text");
        agentodj.Languages = selectlist;
       }

       if (agentodj.Specialization.Count() != 0) {
        List<SelectListItem> list = new List<SelectListItem>();
        string selectedspel = "";
        foreach (int i in agentodj.Specialization) {
         SelectListItem listitem = new SelectListItem();
         listitem.Value = i.ToString();
         listitem.Text = (string)irewhizzrelation.getValue(i);
         list.Add(listitem);
         selectedspel += (string)irewhizzrelation.getValue(i) + ",";
        }
        SelectList selectlist = new SelectList(list, "Value", "Text");
        agentodj.Specializations = selectlist;
       }

       return agentodj;
      }

      public void SaveImage(byte[] pic, String username) {
       irewhizzrelation.SaveImage(pic, username);
      }
     }

现在的问题是,当我调用代理类时,它会给出rwuser类的null引用异常之类的错误

任何人都可以给我解决方案吗?

1 回答

  • 3

    你应该得到一个编译错误,因为你的界面被称为irewhzz,但是你调用了irewhizz .

    但我猜这只是一个复制粘贴错误,对吧?

相关问题