c# - recreate instance in base class -


I was wondering if it is possible to replace the example of any derived class of a derived class of a base class On the same basis, I will try to explain it in a code in the following.

  public class ValueTypeClass {private string _note; Private string _Name; Private node class refrenceNode; // ...} public class refrenceDBClass: valuetypeclass {// ...} public class refrenceFileClass: valuetypeclass {// ...}  

Now every time refrenceNode is changing I want To change the type of example based on the RefrenceNode properties, <1 p>

Edit 1: Now I am doing such a class that keeps a description of refrencedbclass and refrencefileclass and every time refrencenode changes I am making Am a new example.

  public class ValueTypeClass {Private string _Note; Private string _Name; Private node class refrenceNode; Private Detail Class DetailsEfO; // ...} public class detailClass {// ...} public class refrenceDBClass: detailClass {// ...} public class refrenceFileClass: detailClass {// ...}  

You can not change the type of a managed .NET object. If you were encapsulating object (in a cover - for example - refrenceNode ), then you can swap the context, but it's about it.

In some (limited) cases, you may be able to serialize / dister a charged frequency, change the type in the process (works only for contractual-based serializers with compatible contracts Is not very likely). You can not change the current example type definitly


Re-edit; Again, you can not change how you highlight the details, but with some casting, you can work it out; Unclearly, something like this:

  public class ValueTypeClass {private string _note; Private string _Name; Private node class refrenceNode; Set the public node class reference node {return {refrenceNode;} {if (refrenceNode == value) return; // nop refrenceNode = value; BuildDetailInfo (); }} Private Extension Class Details Info; Public Description Class DetailsInfo {get return returnInfo;}} Private Zero BuildDetailInfo () {// TODO: Decide on the appropriate type (based on refrenceNode) // and re-create detailsInfone}}  

It seems as if you should use polymorphism if you are doing data-binding, then there are some things you can do (with a lot of hard work) to make it more friendly, but this does not affect the regular code Will do


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -