emitting assembly with circular reference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to emit an assembly with these 2 classe

public class a :


public class

public A getA()


I cant createtype on a until b is define
I cant createtype on b until a is defined
 
I was wondering why you need the GetA in B

B is the base class, A is derived from it. Therefore if in B you have
public B GetObj(
It can actually return an A if the reference is really an A, eg

A= b.GetObj() as A or A = (A)b.GetObj(

This way B does not need to know anything of A.

This is one of the major principal of polymorphsm. IE, some time in the future yon can cerater a C and still return a reference to it from B

Regard
Michael G Walmsley
 
How about this well known exampl
public class Type : Objec


public Objec

public Type GetType()
}
 
pmoore said:
How about this well known example
public class Type : Object
{
}
public Object
{
public Type GetType();
}


pmoore

As i tried to say in my previous reply - the function GetType should
return an Object not a Type. This way later when you add a TypeA or
TypeB it can still return one (as long as its derived from Object). If
GetType returns a TypeA or a TypeA or any other object derived from
object, it can be cast to the correct type by the caller.

Eg
TypeA = Object.GetType() as TypeA
TypeB = (TypeB)Object.GetType() (this will throw if it isnt a TypeB)

If the object returned is a valid TypeA it will be ok.

Regards
Michael
 
In case you didnt notice my example was directly copied from the base CLR hierachy
I assume you will explain to the C# team that they have created a very poor design

The solution to my problem is that you must emit the base type first (Object in this case) and then Type.
 
Back
Top