开发者

Inheritance issue

I have an issue with inheritance. I have an interface called Irewhizz:

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

I've written the definition in a different class:

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);
}

Now I have different classes like:

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
}

and

     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);
      }
     }

Now the issue is when ever I am calling the agent class it is giving an error like null reference exception for rwuser class

Can anybody give me the solution?


You should get a compile error since your interface is called irewhzz but you invoke irewhizz.

But I'm guessing that it's just a copy paste error, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜