How to get an a class without it's base class
-
Hi, I have a class Dog which derives from Animal. Suppose my instance of Dog is bulldog. bulldog has all the members of Animal plus Dog. How can copy just the members from Dog to a new Dog called boxer? Just get the Dog members from bulldog and leave out any inherited members from Animal. Dog bulldog=new Dog(); <-has inhereited members from Animal Dob boxer =
bulldog - inherited Animal members
How can I do this?/\ |_ E X E GG
-
Hi, I have a class Dog which derives from Animal. Suppose my instance of Dog is bulldog. bulldog has all the members of Animal plus Dog. How can copy just the members from Dog to a new Dog called boxer? Just get the Dog members from bulldog and leave out any inherited members from Animal. Dog bulldog=new Dog(); <-has inhereited members from Animal Dob boxer =
bulldog - inherited Animal members
How can I do this?/\ |_ E X E GG
-
Hi, I have a class Dog which derives from Animal. Suppose my instance of Dog is bulldog. bulldog has all the members of Animal plus Dog. How can copy just the members from Dog to a new Dog called boxer? Just get the Dog members from bulldog and leave out any inherited members from Animal. Dog bulldog=new Dog(); <-has inhereited members from Animal Dob boxer =
bulldog - inherited Animal members
How can I do this?/\ |_ E X E GG
You want to set properties that are common to the animal class, and then keep them that way ? So, for instance, if sex is a common property, you want to do this: Dog bulldog=new Dog(); // defaults to male bulldog.Sex = Sex.Female; Dob boxer = bulldog; // boxer is male That's a weird and counterintuitive requirement. You could do this with your own operator =, but I would recommend against it. Adding a method that creates a new Dog, then sets the local properties, is the way to go public Dog GetDefaultAnimalWithDogProperties() { Dog dog = new Dog(); dog.DogBreed = this.DogBreed; // Or whatever properties are only on the dog class return dog; }
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You want to set properties that are common to the animal class, and then keep them that way ? So, for instance, if sex is a common property, you want to do this: Dog bulldog=new Dog(); // defaults to male bulldog.Sex = Sex.Female; Dob boxer = bulldog; // boxer is male That's a weird and counterintuitive requirement. You could do this with your own operator =, but I would recommend against it. Adding a method that creates a new Dog, then sets the local properties, is the way to go public Dog GetDefaultAnimalWithDogProperties() { Dog dog = new Dog(); dog.DogBreed = this.DogBreed; // Or whatever properties are only on the dog class return dog; }
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Maybe, I'm not explaining it very well, here's what I want to do without dog metaphors. I have a class that is derived from another class that does lots of reflection. So when I pass my class to
JavascriptConvert.SerializeObject(myclass)
all of the base class reflection causes a self referencing loop exception to be thrown from SerializeObject. That's why I don't want to include anything from the base class. (SerializeObject creates a JSON string of the object) -- modified at 18:24 Tuesday 14th August, 2007/\ |_ E X E GG
-
Maybe, I'm not explaining it very well, here's what I want to do without dog metaphors. I have a class that is derived from another class that does lots of reflection. So when I pass my class to
JavascriptConvert.SerializeObject(myclass)
all of the base class reflection causes a self referencing loop exception to be thrown from SerializeObject. That's why I don't want to include anything from the base class. (SerializeObject creates a JSON string of the object) -- modified at 18:24 Tuesday 14th August, 2007/\ |_ E X E GG
Hi, when you use reflection, you can specify the scope of the things you are looking for. As an example, Type.GetMethods accepts a BindingsFlag, you may want to specify BindingFlags.DeclaredOnly to avoid inherited stuff. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google