I have a class called products. In my maintenance application I am instantiating two versions of this class.
mProduct is used in all transactions and changes
mProduct_origin al is loaded at the same time as the original mProduct is instantiated.
I would like to know if there is a simple way to iterate through the properties of each and compare them for changes?
--
--Eric Cathell, MCSA 8 1520
ok I have figured out so far I can do this with reflection. here is what I have so far.
Private Sub checkForChanges (ByVal pType As Type) ', ByVal poType As Type)
Dim productProperti es() As PropertyInfo = pType.GetProper ties(BindingFla gs.Public Or BindingFlags.In stance)
Dim PropertyItem As PropertyInfo
For Each PropertyItem In productProperti es
With PropertyItem
Debug.WriteLine (PropertyItem.N ame)
debug.WriteLine (mproduct.prope rty
End With
Next
End Sub
I got this far with an article from O'reilly. Now how do I use the propertyitem.na me to tie in with the actual class property? In otherwords, If propertyname is Customername who do I use that to access product.custome rname's value so that I can compare it to product_origina l.customername?
--
--Eric Cathell, MCSA
"ECathell" <ec******@nospa m.mountaire.com > wrote in message news:uZ******** ********@tk2msf tngp13.phx.gbl. ..
I have a class called products. In my maintenance application I am instantiating two versions of this class.
mProduct is used in all transactions and changes
mProduct_origin al is loaded at the same time as the original mProduct is instantiated.
I would like to know if there is a simple way to iterate through the properties of each and compare them for changes?
--
--Eric Cathell, MCSA
IMHO, the best thing to do would be to have you class implement the
IComparable interface and then write the code to compare the two objects
and return the results.
Hope this helps,
Brian Swanson
"ECathell" <ec******@nospa m.mountaire.com > wrote in message
news:ec******@n ospam.mountaire .com: I have a class called products. In my maintenance application I am instantiating two versions of this class.
mProduct is used in all transactions and changes mProduct_origin al is loaded at the same time as the original mProduct is instantiated.
I would like to know if there is a simple way to iterate through the properties of each and compare them for changes?
-- --Eric Cathell, MCSA
everything I find on icomparable shows it only as a method for sorting data.
How would I use it to compare the differences in the properties of the
Product object?
--
--Eric Cathell, MCSA
"Brian Swanson" <pu*******@gREM OVETHISmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. IMHO, the best thing to do would be to have you class implement the IComparable interface and then write the code to compare the two objects and return the results.
Hope this helps, Brian Swanson
"ECathell" <ec******@nospa m.mountaire.com > wrote in message news:ec******@n ospam.mountaire .com: I have a class called products. In my maintenance application I am instantiating two versions of this class.
mProduct is used in all transactions and changes mProduct_origin al is loaded at the same time as the original mProduct is instantiated.
I would like to know if there is a simple way to iterate through the properties of each and compare them for changes?
-- --Eric Cathell, MCSA
Having a class implement IComparable gives it a "CompareTo" method which
can takes an object as a parameter, you then compare the current
instance of your class (that was used to run CompareTo) to the instance
that was passed as a parameter.
I'll post an example if you need it, just let me know...
Hope this helps,
Brian Swanson
"ECathell" <ec******@nospa m.mountaire.com > wrote in message
news:ec******@n ospam.mountaire .com: everything I find on icomparable shows it only as a method for sorting data. How would I use it to compare the differences in the properties of the Product object?
-- --Eric Cathell, MCSA "Brian Swanson" <pu*******@gREM OVETHISmail.com > wrote in message news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. IMHO, the best thing to do would be to have you class implement the IComparable interface and then write the code to compare the two objects
and return the results.
Hope this helps, Brian Swanson
"ECathell" <ec******@nospa m.mountaire.com > wrote in message news:ec******@n ospam.mountaire .com: I have a class called products. In my maintenance application I am instantiating two versions of this class.
mProduct is used in all transactions and changes mProduct_origin al is loaded at the same time as the original mProduct is instantiated.
I would like to know if there is a simple way to iterate through the properties of each and compare them for changes?
-- --Eric Cathell, MCSA
hmmm, I dont think that will still work because I am trying to compare the Properties of the class to see if they have been changed... here is some more code hope it helps...
mProduct = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location)
mProduct_Origin al = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location)
populateProduct Fields(mProduct )
This first bit creates 2 new product objects. The populateproduct fields populates text fields and boxes with the information on that product.
When the user moves off this particular product I need to verify that no changes were made. The easiest way for me to do this is to compare the properties of both product objects to see if they are different.
there are 45 or so properties of the product class that need to be compared. If I understand you right if I compare the 2 alone it will still work?
ie
private function CompareTo(by val obj as object) as integer implements icomparable.com pareto
dim other as product=ctype(o bj,product)
if me=other then return 0 else return 1
end function
Is that what you mean?
Eric
Sorry if I wasn't clear on this...You'll still have to compare the
individual properties in your "CompareTo" code, I was just suggesting
that you use the IComparable interface as a place to implement that
code.
Sorry for the confusion..
"ECathell" <ec******@nospa m.mountaire.com > wrote in message
news:ec******@n ospam.mountaire .com: hmmm, I dont think that will still work because I am trying to compare the Properties of the class to see if they have been changed... here is some more code hope it helps...
mProduct = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location)
mProduct_Origin al = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location) populateProduct Fields(mProduct ) This first bit creates 2 new product objects. The populateproduct fields populates text fields and boxes with the information on that product. When the user moves off this particular product I need to verify that no changes were made. The easiest way for me to do this is to compare the properties of both product objects to see if they are different.
there are 45 or so properties of the product class that need to be compared. If I understand you right if I compare the 2 alone it will still work?
ie private function CompareTo(by val obj as object) as integer implements icomparable.com pareto dim other as product=ctype(o bj,product) if me=other then return 0 else return 1 end function
Is that what you mean? Eric
no worries. Then we are back to reflection. I can get all the property names
from reflection, In fact I already have that code done. Do you know how I
can use that information to test the properties of the specific instances?
Dim productProperti es() As PropertyInfo =
pType.GetProper ties(BindingFla gs.Public Or BindingFlags.In stance)
'Dim oProductPropert ies() As PropertyInfo =
poType.GetPrope rties(BindingFl ags.GetProperty )
Dim PropertyItem As PropertyInfo
For Each PropertyItem In productProperti es
With PropertyItem
Debug.WriteLine (PropertyItem.N ame)
if mproduct.proper tyitem=mOrigina lProduct.proper tyitem then
isDifferent=tru e
End With
Next
of course propertyitem doesnt work...do you know how I could use it to make
it work?
--
--Eric Cathell, MCSA
"Brian Swanson" <pu*******@gREM OVETHISmail.com > wrote in message
news:us******** ******@tk2msftn gp13.phx.gbl... Sorry if I wasn't clear on this...You'll still have to compare the individual properties in your "CompareTo" code, I was just suggesting that you use the IComparable interface as a place to implement that code.
Sorry for the confusion..
"ECathell" <ec******@nospa m.mountaire.com > wrote in message news:ec******@n ospam.mountaire .com:
hmmm, I dont think that will still work because I am trying to compare the Properties of the class to see if they have been changed... here is some more code hope it helps...
mProduct = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location)
mProduct_Origin al = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location) populateProduct Fields(mProduct ) This first bit creates 2 new product objects. The populateproduct fields populates text fields and boxes with the information on that product. When the user moves off this particular product I need to verify that no changes were made. The easiest way for me to do this is to compare the properties of both product objects to see if they are different.
there are 45 or so properties of the product class that need to be compared. If I understand you right if I compare the 2 alone it will still work?
ie private function CompareTo(by val obj as object) as integer implements icomparable.com pareto dim other as product=ctype(o bj,product) if me=other then return 0 else return 1 end function
Is that what you mean? Eric
I found the information I was looking for..if you are interested here it
is...
myClass.GetType .GetProperty("P ropertyName").g etvalue(myclass ,nothing)
that will return the value of that property. You can then use the following
code to loop through the properties of your class...
For Each PropertyItem In productProperti es
With PropertyItem
end with
next
--
--Eric Cathell, MCSA
"Brian Swanson" <pu*******@gREM OVETHISmail.com > wrote in message
news:us******** ******@tk2msftn gp13.phx.gbl... Sorry if I wasn't clear on this...You'll still have to compare the individual properties in your "CompareTo" code, I was just suggesting that you use the IComparable interface as a place to implement that code.
Sorry for the confusion..
"ECathell" <ec******@nospa m.mountaire.com > wrote in message news:ec******@n ospam.mountaire .com:
hmmm, I dont think that will still work because I am trying to compare the Properties of the class to see if they have been changed... here is some more code hope it helps...
mProduct = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location)
mProduct_Origin al = New Mountaire.Datab ase.Product(txt PLUnumber.Text, mCurrentFacilit y.Location) populateProduct Fields(mProduct ) This first bit creates 2 new product objects. The populateproduct fields populates text fields and boxes with the information on that product. When the user moves off this particular product I need to verify that no changes were made. The easiest way for me to do this is to compare the properties of both product objects to see if they are different.
there are 45 or so properties of the product class that need to be compared. If I understand you right if I compare the 2 alone it will still work?
ie private function CompareTo(by val obj as object) as integer implements icomparable.com pareto dim other as product=ctype(o bj,product) if me=other then return 0 else return 1 end function
Is that what you mean? Eric This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MIchael McDowell |
last post by:
Anyidea how this might be done using and XML Web Service
and the XMLSerialzation class?
A pointer to an online example would be deeply appreciated.
Thankyou in advance,
Michael McD
|
by: Kenneth Baltrinic |
last post by:
What is the best way to determine if two objects are of the same type? The
'is' operator is not precise enough. Currently I am using
Obj1.GetType().Name == Obj2.GetType().Name but it seems to me there must be
a better way. The following code gives a better idea of the situation:
abstract class A
{
//the arguments could be instances of any of the classes defined
static void TestFunc(A obj1, A obj2)
{
|
by: Dennis |
last post by:
I have a public variable in a class of type color declared as follows:
public mycolor as color = color.Empty
I want to check to see if the user has specified a color like;
if mycolor = Color.Empty then.....
or
if mycolor is Color.Empty then .......
|
by: richardkreidl |
last post by:
I have the following hash script that I use to compare two text files.
'Class
Public Class FileComparison
Public Class FileComparisonException
Public Enum ExceptionType
U 'Unknown
A 'Add
D 'Delete
|
by: andreas |
last post by:
Hello,
I have a problem with iterators in a fairly complex polygonal mesh data
structure which is implemented using lists of geometric entities.
However, the problem in itself is fairly simple:
I need to define special iterator values. In particular, I want a null
iterator. This is different from end() which means the end of this
list. I want an iterator value that is known to just not correspond to
any element. It must be possible to...
| |
by: netnet |
last post by:
I have a collection of objects that I store in the session. Then I look in
that collection to see if the collection.contains an object. it answers
false. If I dont store that collection in the session it answers true. Is
the session somehow modifying the collection? The objects look identical.
|
by: Bill Pursell |
last post by:
This question involves code relying on mmap, and thus
is not maximally portable. Undoubtedly, many will
complain that my question is not topical...
I have two pointers, the first of which is mmapped
to a single page. I want to determine if the second
is on the page. I'd like to do:
#include "platform_appropriate_definition_of_PAGESIZE.h"
int compare1(const char *a, const char *b)
|
by: J Caesar |
last post by:
In C you can compare two pointers, p<q, as long as they come from the
same array or the same malloc()ated block. Otherwise you can't.
What I'd like to do is write a function
int comparable(void *p, void *q)
that will take any two pointers and decide whether they can be compared
or not.
I really can't think how to do this - any suggestions?
|
by: Ladislav Andel |
last post by:
Hi,
what would be the most efficient way to do following?
I have a list of dictionaries taken from DB e.g.
dblist =
and list of object instances in memory(it's just for example)
which are looping within itself and testing particular hosts
memlist =
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |