Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2003

Tip: Looking for answers? Try searching our database.

how to represent class by custom type?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bandzuch martin - 12 Nov 2003 09:47 GMT
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.
Ben Rush - 12 Nov 2003 20:25 GMT
I don't think it's possible. My understanding is that GetTypeHandle()
returns a handle (pointer) to a class object. Within a class object is a
reference to the type it is, and this is something that is maintained by the
runtime; not accessible in any other way.

This is an interesting topic, and I'm interested in possibly being proven
that I'm wrong since this is currently something I'm beginning to explore in
ROTOR - how the type maintains its identity, etc.

Unless I've completely misunderstood your situation, I don't think you can
spoof GetTypeHandle() to return anything but a pointer to the class object.

> hello!
> is there any way how to return custom type for specific class using typeof
[quoted text clipped - 97 lines]
>
> thank you for any suggestions, critics or comments.
bandzuch martin - 13 Nov 2003 08:48 GMT
my plan is to create statical C# classes model from UML model.
and i want to realize association elements as references to classType.
so i need to create for each class corresponding classRuntimeType and
associate
it with that class. i had also looked at sscli and found some code, but had
not found
the whole principle and association with the System.Type and
System.RuntimeType classes yet.
i am confused about System.Type class because it is abstract, public and
there is written some
'note to implementors', so there should be some reason to derive from
System.Type for custom
type implementors. May be there is some other reason that i see ( create
custom classType ) but
i can't figure out.
and if it is possible to create custom classType, it's use is limited
without possibility to attach it to corresponding
class.
now i am trying to realize that mapping ( uml model -> c# classes ) some
other way, maybe attributes will
provide sufficient potential to realize it.
thak you for your interest and time.

> I don't think it's possible. My understanding is that GetTypeHandle()
> returns a handle (pointer) to a class object. Within a class object is a
[quoted text clipped - 7 lines]
> Unless I've completely misunderstood your situation, I don't think you can
> spoof GetTypeHandle() to return anything but a pointer to the class object.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.