473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class public members and recurse

Hi,

Does anybody know if I can use something like recurse to get the whole list
of the public members of the class and their types/values?

For example, I created the object with default values, then I need to get
another object, created somewhere else, for example by serialization method,
then to assign all values from this external object to existing ones in my
object. I can do that using the members list, one by one. I suspect that
there is another one approach, more effective, like:

CMyClass MyObject = new CMyClass();
CMyClass DeserializedObject = Deserialize();
foreach (object obj in MyObject){
MyObject.obj = DeserializedObject.obj;
}//foreach

Is it possible at all?

Thanks,
Dmitri

Nov 16 '05 #1
2 1091
Why don't you just use the instance that you have deserialized ? It is a
totally valid instance.
If, for some reason you cannot, you may consider implemnting a 'Clone'
method. Use the protected method memberwiseclone().
If you have no right onthe implementation of your class, you could use
Reflection to list all of the pulic properties, and then loop through them
(as you proposed).

Fred
Nov 16 '05 #2
Hi Fred,

Just because the serialization and deserialization are created as the
methods of the same class. I use these methods from the existing object. I
can't overwrite the instance of the object inside the same instance. That's
why I use this trick with a temporary additional object inside working one
and copy all members (pointers) from there. It's made in a basic class and
I'd like just to inherit these methods. It almost works, but I need to have
an ability to retrieve all members in a root class for all derived.

Thanks,
Dmitri Shvetsov
http://members.cox.net/dshvetsov/pictures.htm

"Iceman" <fr************************@neuf.fr> wrote in message
news:c6**********@aphrodite.grec.isp.9tel.net...
Why don't you just use the instance that you have deserialized ? It is a
totally valid instance.
If, for some reason you cannot, you may consider implemnting a 'Clone'
method. Use the protected method memberwiseclone().
If you have no right onthe implementation of your class, you could use
Reflection to list all of the pulic properties, and then loop through them
(as you proposed).

Fred


Nov 16 '05 #3

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

Similar topics

8
3931
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
5
2300
by: Tappy Tibbons | last post by:
I have a class I am serializing, and need the resultant XML to skip/omit classes that are not initialized, or their member variables have not been set. Is this possible? Say for the following...
5
14406
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
6
1340
by: Laszlo Szijarto | last post by:
What's the best way to recurse through the members of an enum? I want to take an enum and dump into a ListBox the enum's names. Thank you, Laszlo
5
8722
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
5
14002
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
0
3693
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
9
1874
by: olanglois | last post by:
Hi, I am not sure if I have found a compiler bug (I am using VC++.NET2003) or if this is the correct behavior defined by the language but I am sure someone can clear up my confusion. Suppose the...
19
2209
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
0
7205
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
7287
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
7353
jinu1996
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...
1
7011
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
7468
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
5596
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,...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.