473,385 Members | 1,356 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,385 software developers and data experts.

Reflection and PropertyInfo

Hi guys

is it possible, once getting hold of a propertyInfo instance to know when
the value of the property changed?

that is without requiring the property to raise an event on change
obviously...

maybe something with the PropertyInfo.GetSetMethod()? monitoring when that
method is called somehow?

how does the dataBinding mechanism work? seems to do the job, but how?

thanx,

Picho
Nov 17 '05 #1
2 2043
No, there's no way to do it using PropertyInfo, for two reasons.

First (and most obvious) because there's no such mechanism in .NET.

Second (even if there were such a mechanism), a PropertyInfo instance
_doesn't remember_ which object instance it came from (if any). Here
proof: you can get a PropertyInfo without having an instance of the
object at all:

PropertyInfo pi = typeof(MyClass).GetProperty("PropertyName");

PropertyInfo is pure metadata: it contains no information about any
object instance, so it can't help you if something about the instance
changes.

As to your second question, bindings do their job by requiring that
every property they're monitoring have a "...Changed" event. So, if you
have a class with a "BalanceDue" property, if you define an event
called "BalanceDueChanged" then you can bind that property to some
screen control using a binding. No event, no successful binding. No
magic involved at all. :)

Nov 17 '05 #2
Well, Figures.

thanx, I guess I have to stick to the OnChange thing.

b.t.w: is there a naming convention to link the property name to the event
name for the DataBinding to work?

thanx

Picho
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
No, there's no way to do it using PropertyInfo, for two reasons.

First (and most obvious) because there's no such mechanism in .NET.

Second (even if there were such a mechanism), a PropertyInfo instance
_doesn't remember_ which object instance it came from (if any). Here
proof: you can get a PropertyInfo without having an instance of the
object at all:

PropertyInfo pi = typeof(MyClass).GetProperty("PropertyName");

PropertyInfo is pure metadata: it contains no information about any
object instance, so it can't help you if something about the instance
changes.

As to your second question, bindings do their job by requiring that
every property they're monitoring have a "...Changed" event. So, if you
have a class with a "BalanceDue" property, if you define an event
called "BalanceDueChanged" then you can bind that property to some
screen control using a binding. No event, no successful binding. No
magic involved at all. :)

Nov 17 '05 #3

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

Similar topics

0
by: Nigel Sampson | last post by:
ey all, I'm in the process of creating a method of tracking whenever an objects properties are changed. Since its not possible to alter existing types I decided to used a proxy generated using...
6
by: Lars Nielsen | last post by:
Hi everybody, I've run into a problem when using the reflection assembly on COM objects and been browsing around the net for some while. Apparently a few has asked the same question though no...
4
by: Frank Rizzo | last post by:
Ok, I've heard all about reflection. How do I print out the results for all the properties on this object: System.Reflection.Assembly.GetExecutingAssembly().GetName() I don't want a list of...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
3
by: Roger Webb | last post by:
Hey, I'm attempting to use reflection in order to get the types of properties in a class. However, I seem to be having trouble determining exactly which type I am getting. In the foreach of...
2
by: Marc | last post by:
Given a class 'Invoice' with a property 'public IMyColl<IInvoiceLine> InvoiceLines' where 'IMyColl<T> : IList<T>' i would like to detect by reflection that 'InvoiceLines' is a...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
3
by: Oskar Lundgren | last post by:
I want to iterate over fields declared like this, using reflection (and there are good reasons for that): Protected WithEvents Foo1 As Bar Protected WithEvents Foo2 As Bar .... I use the...
4
by: Lucas Tam | last post by:
Hi all, I need to set a property on a subclass such as: Report.ExportOptions.ExportFormatType = ExportFormatType.Excel AND Report.ExportOptions.FormatOptions = excelFormatOpts
15
by: satankidneypie | last post by:
Hi, I'm going to start this off with some code as it'll make it easier to explain afterwards... using System; namespace ConsoleApplication1 { /// <summary>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.