|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing type name from a static methodI've come to a problem that I am not able to solve, although something is telling me there must be a solution. Let's say I have a class MyType: public class MyType { public MyType() {} public static void DoSomethingWithTypeName() { doSomething("MyType"); } } The problem is that I don't want to pass a literal string to doSomething method - this should not be necessary since this method is executed from within MyType context, so I should be able to retrieve the type name. However, since static method does not have access to "this" (for obvious reason), I can't use .NET Type non-static methods to retrieve class name. And I can't find any static function that would do that. I am puzzled because CLR must have such run-time information, but how to get access to it? Help is appreciated Vagif Abilov vagif @ online.no Oslo Norway Vagif,
>I am puzzled because CLR must have such run-time information, but how to get typeof(MyType).Name>access to it? or MethodBase.GetCurrentMethod().DeclaringType.Name Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. That's the one I need:
MethodBase.GetCurrentMethod().DeclaringType.Name Thanks a lot! Show quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:ubQKbtv%23EHA.1404@TK2MSFTNGP11.phx.gbl... > Vagif, > >>I am puzzled because CLR must have such run-time information, but how to >>get >>access to it? > > typeof(MyType).Name > > or > > MethodBase.GetCurrentMethod().DeclaringType.Name > > > > Mattias > > -- > Mattias Sjögren [MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. |
|||||||||||||||||||||||