how to represent custom class by custom type?

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.
 
D

Dino Chiesa [Microsoft]

I am sure I don't understand what you are trying to accomplish, but why can
you not do the following:

System.Type t = typeof( MyCustomClass ) ;

What is wrong with the result here? Why do you need to extend System.Type ?
-D
 
B

bandzuch martin

hello.
i will try to explain my problem.
i am trying to create corresponding uml metalevels using c# language.
c# classes are good for creating some model. but i want to have metamodel as
well
in c#. and the system.type is what i want to use. but there is problem in
declaring statical
associations between model classes. therefor i wanted to associate with each
model class
corresponding metaclass ( custom type derived from System.Type ). This way i
could add
new properties ( associations, stereotypes, constraints, ... ) on metalevel.
so when i wanted to get metaclass for some model class i will use typeof(
ModelClass ) or
use modelClassInstance.GetType() or some static method of MetaClassType.
This is my problem.

So now i will probably use Attributes, but there is problem in using
attributes, because they use
objects to initialize themselfs.
class MetaClassAttribute : System.Attribute
{
//some constructors
//some properties
//some methods
}

[ MetaClassAttribute( someObject1, someObject2 ) ]
class ModelClass
{
}
and that is problem. because it is no longer meta ( it uses object
instances ). MetaClassType will have not this kind
of problem, because i can use other MetaXXXType for referencing, or other
purpose.
I know this is only principal problem, not technical. but i wanted to
accomplish this transparently.

p.s.: I have two question yet. Why is the System.Type public abstract class,
and in help there is 'note to inheritors', if
there will be no purpose for doing it? And if there will be purpose for
deriving from System.Type, why there is no
way how to associate it with some class or anything appropriate.

thank you for your interest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top