views:

56

answers:

1

hi Friends i am facing a issue in Inheritance i have a interface called Irewhizz

interface irewhzz
{

void object save(object obj); void object getdata(object obj); }

i write definition in different class like

public user:irewhzz
{
    public object save(object obj);

{ ....... }

public object getdata(object obj); { ....... } }

this is antoher class

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;
    private string _firstName;
    private string _lastName;
    private string _middleName;
    private string _email;
    private string _website;
    private int _addressId;
    private string _city;
    private string _zipcode;
    private string _phone;
    private string _fax;
    //private string _location;
    private string _aboutMe;
    private string _username;
    private string _password;
    private string _securityQuestion;
    private string _securityQAnswer;

private Guid _user_Id; private long _rwuserid; private byte[] _image; private bool _changepassword; private string _mobilephone; private int _role; #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 { return _role; } set { _role = value; } }

public string MobilePhone { get { return _mobilephone; } set { _mobilephone = value; } }

public bool ChangePassword { get { return _changepassword; } set { _changepassword = value; } }

public byte[] Image { get { return _image; } set { _image = value; }

}

public string FirstName { get { return _firstName; } set { _firstName = value; } }

public string LastName { get { return _lastName; } set { _lastName = value; } }

public string MiddleName { get { return _middleName; } set { _middleName = value; } }

public string Email { get { return _email; } set { _email = value; } }

public string Website { get { return _website; } set { _website = value; } }

public int AddressId { get { return _addressId; } set { _addressId = value; } }

public string City { get { return _city; } set { _city = value; } }

public string Zipcode { get { return _zipcode; } set { _zipcode = value; } }

public string Phone { get { return _phone; } set { _phone = value; } }

public string Fax { get { return _fax; } set { _fax = value; } }

//public string Location //{ // get // { // return _location; // } // set // { // _location = value; // } //}

public string AboutMe { get { return _aboutMe; } set { _aboutMe = value; } }

public string username { get { return _username; } set { _username = value; } }

public string password { get { return _password; } set { _password = value; } }

public string SecurityQuestion { get { return _securityQuestion; } set { _securityQuestion = value; } }

public string SecurityQAnswer { get { return _securityQAnswer; } set { _securityQAnswer = value; } }

public Guid UserID { get { return _user_Id; } set { _user_Id = value; } }

public long RwUserID { get { return _rwuserid; } set { _rwuserid = value; } } #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; private int _roleid; private int _speclisationid; private int[] _language; private string _brokaragecompany; private int _loctionType_lk; private string _rolename; private int[] _specialization; private string _agentID; private string _expDate; private string _regstates; private string _selLangs; private string _selSpels; private string _locations; public string Locations { get { return _locations; } set { _locations = value; } }

public string SelectedLanguages { get { return _selLangs; } set { _selLangs = value; } }

public string SelectedSpecialization { get { return _selSpels; } set { _selSpels = value; } }

public string RegisteredStates { get { return _regstates;

} set { _regstates = value; } }

//private string _registeredStates; public string AgentID { get { return _agentID;

} set { _agentID = value;

} }

public string ExpDate { get { return _expDate;

} set { _expDate = value;

} }

private int[] _registeredStates; public SelectList RegisterStates { set; get; }

public SelectList Languages { set; get; }

public SelectList Specializations { set; get; }

public int[] RegisterdStates { get { return _registeredStates; } set { _registeredStates = value; }

}

//public string RegisterdStates //{ // get // { // return _registeredStates; // } // set // { // _registeredStates = value; // }

//}

public int RoleId { get { return _roleid; } set { _roleid = value; }

}

public int SpeclisationId { get { return _speclisationid; } set { _speclisationid = value; }

}

public int[] Language { get { return _language; } set { _language = value; }

}

public int LocationTypeId { get { return _loctionType_lk; } set { _loctionType_lk = value; }

}

public string BrokarageCompany { get { return _brokaragecompany; } set { _brokaragecompany = value; }

}

public string Rolename { get { return _rolename; } set { _rolename = value; }

}

public int[] Specialization { get { return _specialization; } set { _specialization = value; }

}

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

}

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

}

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

//DataHelperDataContext dataObj = new DataHelperDataContext();

//#region IRewhizzFactory Members

//public List getAgentInfo(string username) //{ // var res=dataObj.GetCompleteUserDetails(username); // return res.ToList();

// throw new NotImplementedException(); //} //public List GetRegisterAgentData(string username) //{ // var res= dataObj.RegisteredUserdetails(username); // return res.ToList(); //}

//public void saveAgentInfo(string username, string password, string firstname, string lastname, string middlename, string securityquestion, string securityQanswer) //{ // User userobj=new User();

// var result = dataObj.rw_Users_InsertUserInfo(firstname, middlename, lastname, dataObj.GetUserId(username), securityquestion, securityquestionanswer);

// throw new NotImplementedException(); //}

//#endregion

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 list = new List(); 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;
// agentodj.SelectedLanguages = selectedlang;

}

if (agentodj.Specialization.Count() != 0) { List list = new List(); 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; //agentodj.SelectedSpecialization = selectedspel;

}

return agentodj;

}

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

}

now the issue is when ever i am calling agent class it is given error like null reference exception for rwuser class

can any body give the solution thanks in advance

+2  A: 

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?

Kristian Hebert
+1 for copy/paste suggestion.
rlb.usa