Thursday, July 27, 2006

[itsdifferent] .net 2.0 ... Help me out..urgent

Dear friends,

In my current project I am using the CustomCollections with the help of BindingList<T> generic class to store the database records instead using DataSet objects as offline database identities.

Now I do have a large number of property classes each having a large number of properties in it.

I want to implement the INotifyPropertyChanged interface in every property class as follows:

The purpose to implement the INotifyPropertyChanged interface is I want to inform the UI whenever any property change occurs and update the it accodingly. Also I need to inform the ListChanged event of the my BindingList<T> collection object using the PropertyChangedEvent of INotifyPropertyChanged interface. I know that the PropertyChangedEvent automatically raises the ListChanged event of the BindingList<T> object.

I want to maintain a flag whose value will be false whenever the collection gets changed means any property value of any item in the collection gets changed.

My code is like below:


 public class Customer :INotifyPropertyChanged
    {
           
        private int number;
      
        public int Number
        {
            get { return number; }
            set { number = value;if(value!=number) OnPropertyChanged("Number"); }
        }

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value;if(value != name) OnPropertyChanged("Name"); }
        }

  public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
}

Now what if my class has 100 properties then....

Is there any way out so I dont need to write the same code like below again and again in each property's set method:

if(value != name) OnPropertyChanged("Name");

I dont want to write the above line for every property.

So is it possible to do this using Reflection and subscribe for the event PropertyChanged for every property in the class in a single code block..

I have seen such a code months ago on any website but can't recall it right now as that time I was not so serious and not knowing I might have to implement this in future:)

Suggest me how to do this and put the code snippet if possible.

THANKS in ADVANCE.

Regards,
Hardeek Thakkar

__._,_.___
Note: This Group is not a Job Searching Group, so please co-operate and dont transfer any kind of job related material across this Group.AnyOne doing so can be banned from the Group
Thanx , Group Co-Ordinators
SPONSORED LINKS
Yahoo! Mail

You're invited!

Try the all-new

Yahoo! Mail Beta

Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Y! Messenger

Make free calls

Call PC-to-PC

worldwide- free!

.

__,_._,___

No comments: