473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

.Net 2.0 INotifyPropertyChanged Interface Implementation...help needed..urgent

Dear friends,

In my current project I am using the CustomCollections with the help of
BindingList<Tgeneric 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<Tcollection object using the PropertyChangedEvent of
INotifyPropertyChanged interface. I know that the PropertyChangedEvent
automatically raises the ListChanged event of the BindingList<Tobject.

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

*** Sent via Developersdex http://www.developersdex.com ***
Jul 27 '06 #1
1 2104
"Hardeek Thakkar" <ha*************@gmail.coma écrit dans le message de
news: e8**************@TK2MSFTNGP04.phx.gbl...

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

Create a base class with a generic property setter method and call that from
the separate property setters.

public class BaseObject : INotifyPropertyChanged
{
protected void SetValue<valueT>(string fieldName, valueT value)
{
FieldInfo fi = GetType().GetField(fieldName, ...);
fi.SetValue(value);
// call propertychanged event with fieldName
}
}

public class Customer : BaseObject
{
private string name;

public string Name
{
get {...}
set { SetValue<string>(value); }
}
}

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jul 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Pierre Barbier de Reuille | last post by:
Ok, I first want to stress that I looked through the newsgroups archives (on Google) for an answer to my question, but I didn't find it. It's about the interface of the set classes as defined in...
4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
3
by: John Underwood | last post by:
Hi.. I was looking at interface, and I have a example in the docs i'll paste below.. I'm not grasping what you would gain by using a interface, does any one have a brief description of their...
8
by: khalprin | last post by:
Hello, I'm trying to create a component that will be used from .net clients and COM clients. I've got an object model that looks something like this: ISystem IRuntime IConfiguration...
20
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this,...
2
by: John Greenwood | last post by:
Hi, I'm not sure if i'm misunderstanding how INotifyPropertyChanged should work but it's not working as I expected. I have a sample program with a very simple 'Customer' class with three...
0
by: Gerrit | last post by:
Hello, On http://msdn2.microsoft.com/en-us/library/ms184414.aspx is an example of the implementation of INotifyPropertyChanged Interface. I work with the C# example. I have tried this sample,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.