473,569 Members | 2,598 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 DeserializedObj ect = Deserialize();
foreach (object obj in MyObject){
MyObject.obj = DeserializedObj ect.obj;
}//foreach

Is it possible at all?

Thanks,
Dmitri

Nov 16 '05 #1
2 1097
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************ ************@ne uf.fr> wrote in message
news:c6******** **@aphrodite.gr ec.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
3938
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 private members of nesting class. template <typename T> class Container { // NO friendship given to any other public: class ContainerIterator;
5
2307
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 code, sometimes the Person may not have given us one, both, or either of their addresses. The serialize function will still put in a...
5
14415
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 the class and this works but I would also like to know of other ways to do this. Also are there any performance implacations of using sealed?
6
1347
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
8723
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 conceptually speaking : when do I define something as 'struct' and when as 'class' ? for example : if I want to represent a 'Time' thing, containing...
5
14015
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 VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources......
0
3700
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) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
9
1876
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 following: class Base { protected: int x;
19
2215
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 modify come of the classes so they match our purpose better - mostly add a few methods etc. Example: Open source lib has classes Map and Layer...
0
7700
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, 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...
0
7614
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...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2114
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 we have to send another system
1
1221
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.