I will explain my question with an example. I have a student class.
Expand|Select|Wrap|Line Numbers
- public class Student : INotifyPropertyChanged
- {
- const int MINIMUM_AGE = 1;
- int rollNumber = 0;
- int age = 0;
- string studentName = string.Empty;
- #region INotifyPropertyChanged Members
- public event PropertyChangedEventHandler PropertyChanged;
- #endregion
- public Student() { }
- public Student(string studentName, int age, int rollNumber)
- {
- this.StudentName = studentName;
- this.StudentAge = age;
- this.RollNumber = rollNumber;
- }
- public string Name
- {
- get
- {
- return this.studentName;
- }
- set
- {
- if (value != this.studentName)//guard clause
- {
- if (value.Trim() == string.Empty)
- throw new Exception("Name assigned does not confirms to the format. Please assign a proper alphanumeric value.");
- this.studentName = value;
- this.DisplayPropertyChange("StudentName");
- }
- }
- }
- public int StudentAge
- {
- get
- {
- return this.age;
- }
- set
- {
- if (value != this.age)//guard clause
- {
- //any value lesss than minumum age goes to minimum ages.
- if (value < MINIMUM_AGE)
- this.age = MINIMUM_AGE;
- else
- this.age = value;
- this.DisplayPropertyChange("StudentAge");
- }
- }
- }
- public int RollNumber
- {
- get
- {
- return this.rollNumber;
- }
- set
- {
- if (value != this.rollNumber)//guard clause
- {
- if (value < 0)
- throw new Exception("Wrong value supplied. Only non negative integers allowed.");
- this.rollNumber = value;
- this.DisplayPropertyChange("RollNumber");
- }
- }
- }
- void DisplayPropertyChange(string propertyName)
- {
- if (null!=this.PropertyChanged)
- {
- this.PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
- }
- }
- }
Now, in the same class a property type is a complex/user defined type. Then how are we going to handle it.?e.g.
say in the above class the Name property is changed to the following class instead of string:
Expand|Select|Wrap|Line Numbers
- public class StudentName
- {
- string firstName = string.Empty;
- string lastName = string.Empty;
- public string FirstName
- {
- get { return firstName; }
- set { firstName = value; }
- }
- public string LastName
- {
- get { return lastName; }
- set { lastName = value; }
- }
- public string FullName
- {
- get { return String.Concat(this.firstName," ",this.lastName); }
- }
- //Default
- public StudentName()
- {}
- //Overloaded
- public StudentName(string firstName, string lastName)
- {
- this.firstName = firstName;
- this.lastName = lastName;
- }
- }
Expand|Select|Wrap|Line Numbers
- Student student=new Student();
- string.Format("The student's name is {0}",student.Name.FullName);
IF INotifyPorpertyChanged is not extendable for complex property is there some workaround?
Or am I overlooking some Object Oriented Concept here?
Any help will be highly appreciated.
Regards,
Sid