GetType within shared method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Pateman

    #1

    GetType within shared method

    Hi there,

    I'm trying to find the quickest way to get a type object of the current
    class within any part of the class. For example,

    Me.GetType < This works fine within an instance method but not in a
    shared method

    GetType(<nameof type>) < This works fine but defeats the object

    Any idea on how I can find it dynamically without having to write the
    name of the type myself?

    Cheers in advance.

    Nick.


  • Herfried K. Wagner [MVP]

    #2
    Re: GetType within shared method

    "Nick Pateman" <a@a.com> schrieb:[color=blue]
    > I'm trying to find the quickest way to get a type object of the current
    > class within any part of the class. For example,
    >
    > Me.GetType < This works fine within an instance method but not in a
    > shared method
    >
    > GetType(<nameof type>) < This works fine but defeats the object
    >
    > Any idea on how I can find it dynamically without having to write the
    > name of the type myself?[/color]

    Try 'MethodBase.Get CurrentMethod() .DeclaringType' .

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Mattias Sjögren

      #3
      Re: GetType within shared method

      > Any idea on how I can find it dynamically without having to write the[color=blue]
      >name of the type myself?[/color]

      MethodBase.GetC urrentMethod(). DeclaringType


      Mattias

      --
      Mattias Sjögren [C# MVP] mattias @ mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      Comment

      • Nick Pateman

        #4
        Re: GetType within shared method

        Hurrah! thanks for your help!

        "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
        news:%23ZlKqIXL GHA.3984@TK2MSF TNGP14.phx.gbl. ..[color=blue][color=green]
        >> Any idea on how I can find it dynamically without having to write the
        >>name of the type myself?[/color]
        >
        > MethodBase.GetC urrentMethod(). DeclaringType
        >
        >
        > Mattias
        >
        > --
        > Mattias Sjögren [C# MVP] mattias @ mvps.org
        > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        > Please reply only to the newsgroup.[/color]


        Comment

        • Nick Pateman

          #5
          Re: GetType within shared method

          Hurrah! thanks for your help!

          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          news:%23X8ULHXL GHA.3984@TK2MSF TNGP14.phx.gbl. ..[color=blue]
          > "Nick Pateman" <a@a.com> schrieb:[color=green]
          >> I'm trying to find the quickest way to get a type object of the
          >> current class within any part of the class. For example,
          >>
          >> Me.GetType < This works fine within an instance method but not in a
          >> shared method
          >>
          >> GetType(<nameof type>) < This works fine but defeats the object
          >>
          >> Any idea on how I can find it dynamically without having to write the
          >> name of the type myself?[/color]
          >
          > Try 'MethodBase.Get CurrentMethod() .DeclaringType' .
          >
          > --
          > M S Herfried K. Wagner
          > M V P <URL:http://dotnet.mvps.org/>
          > V B <URL:http://classicvb.org/petition/>[/color]


          Comment

          Working...