B
bandzuch martin
hello!
is there any way how to return custom type for specific class using typeof
operator?
//my custom type definition
class CustomType : System.Type
{
...
implementation
...
}
//my custom class
class CustomClass
{
}
//main somewhere
Main()
{
//this is what i want to do
CustomType type = typeof( CustomClass );
}
this is state where i have stopped, nothing i can figure out
i have overriden the GetType methods in CustomClass
class CustomClass
{
//static methods
CustomType GetTypeFromXXX()
...
//instance methods
CustomType GetType()
{
...
}
}
but expression typeof( CustomClass ) uses System.Type::GetTypeHandle()
to obtain System.Type for CustomClass.
what i am trying to do is to set some static relationships for classes.
examle:
class Custom1Type : System.Type
{
...
implementation
...
//static relation with Custom2
Custom2Type someRelation;
}
class Custom1
{
}
class Custom2Type : System.Type
{
...
implementation
...
//static relation with Custom1
Custom1Type someRelation1;
//static relation with Custom3
Custom3Type someRelation2;
}
class Custom2
{
}
class Custom3Type : System.Type
{
...
implementation
...
//static relation with Custom2
Custom2Type someRelation;
}
class Custom3
{
public void Method()
{
...
}
}
Main()
{
Custom1Type type1 = typeof( Custom1 );
type1.someRelation.someRelation2.InvokeMethod(...);
}
thank you for any suggestions, critics or comments.
is there any way how to return custom type for specific class using typeof
operator?
//my custom type definition
class CustomType : System.Type
{
...
implementation
...
}
//my custom class
class CustomClass
{
}
//main somewhere
Main()
{
//this is what i want to do
CustomType type = typeof( CustomClass );
}
this is state where i have stopped, nothing i can figure out
i have overriden the GetType methods in CustomClass
class CustomClass
{
//static methods
CustomType GetTypeFromXXX()
...
//instance methods
CustomType GetType()
{
...
}
}
but expression typeof( CustomClass ) uses System.Type::GetTypeHandle()
to obtain System.Type for CustomClass.
what i am trying to do is to set some static relationships for classes.
examle:
class Custom1Type : System.Type
{
...
implementation
...
//static relation with Custom2
Custom2Type someRelation;
}
class Custom1
{
}
class Custom2Type : System.Type
{
...
implementation
...
//static relation with Custom1
Custom1Type someRelation1;
//static relation with Custom3
Custom3Type someRelation2;
}
class Custom2
{
}
class Custom3Type : System.Type
{
...
implementation
...
//static relation with Custom2
Custom2Type someRelation;
}
class Custom3
{
public void Method()
{
...
}
}
Main()
{
Custom1Type type1 = typeof( Custom1 );
type1.someRelation.someRelation2.InvokeMethod(...);
}
thank you for any suggestions, critics or comments.