C# call derived class property using base class reference?

You should make a virtual or abstract method in the base class, override it in each derived class, and call it normally.

If those method are in RequestDetails I suggest you make it receive a RequestDetail instead and in that method you can call an abstract method from RequestDetail that does those minor differences and each of ClassA and ClassB implement the different approach something like class RequestDetail{ public void CreateMethod(RequestDetails reqD){ //do what you need AbstCreateMethod(reqD); } public abstract void AbstCreateMethod(RequestDetails reqD); } class ClassA : RequestDetails{ public void AbstCreateMethod(RequestDetails reqD){ //do classA things } } class ClassB : RequestDetails{ public void AbstCreateMethod(RequestDetails reqD){ //do classB things } } if it's in another class follow a similar solution to this but with the class that has those methods. For more information on this read the design pattern Template method.

Actually I am writing a webservice Method which uses the proxy class. The base class and derived classes are defined in the proxy class. The webservice method takes the derived class as arguments.

Please find below the proxyclass and the webservice for your reference. – elamaran Oct 26 at 8:44.

Specify your base class as abstract, write the method "CreateMethod" inside it and create abstract functions where different behavior is required (or virtual if the behavior overriding is optional). Override the abstract functions, adding the desired behaviors inside them. Public abstract RequestDetail { public void CreateDetail() { CustomBehavior(); } protected abstract CustomBehavior(); } public RequestDetailA : RequestDetail { protected override void CustomBehavior() { // Foo } }.

Ctually I am writing a webservice Method which uses the proxy class. The base class and derived classes are defined in the proxy class. The webservice method takes the derived class as arguments.

Please find below the proxyclass and the webservice for your reference. – elamaran Oct 26 at 8:48 Both baseclass and derived class has properties and not the methods. Derived class, baseclass and the interface which has got methods are in the proxy class generated using wsdl.

Exe – elamaran Oct 26 at 8:56.

Class mybase { virtual void DoStuff(){...} } class Der1:mybase { virtual override void DoStuff(){ base.DoStuff(); // Call the Common Code .... Custom Code for this class } Der1 A = new Der1(); mybase B = new Der1(); A.DoStuff(); // this will call the derived version B.DoStuff(); // So will this.

I have a class RequestDetail. I am writing a method CreateMethod1(ClassA a) and CreateMethod2(ClassB b). Both methods doing the same stuff except some minor difference.

I would like to write a generic method and call that method by passing the reference in CreateMethod1 and CreateMethod2. Can anyone help me in doing this? What I have excluded is I have received a WSDL which when generated gives me four separate classes that inherit from a base class with around 20 properties.

They only differ very slightly, to be exact 2 classes contain the same field (IsUrgent), the third contains (Ticket and Reason) and the fourth contains (BudgetCode) The persistance however is exactly the same for all implementations. I don't want to create 4 seperate methods to persist the same information. Its worth noting the classes are partial.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions