Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Question with Generics

C# Question with Generics

Scheduled Pinned Locked Moved C#
csharpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    malharone
    wrote on last edited by
    #1

    I posted a question earlier re. genarics for .net 2.0 and seems that what I'm trying to do is unfeasible. So here's my last (I think it's last) question on generics: Is it possible to reference "current class" instead of hard-coding the class name in the code? E.g.

    abstract class BaseClass
    {
    static void GenericStaticMethod < T > (args)
    {
    ...
    }
    void Foo()
    {
    GenericStaticMethod <CurrentClass>.(args);
    }
    }

    class C1 : BaseClass
    {
    ...
    }
    class C2 : BaseClass
    {
    ...
    }

    when calling C1.Foo(), it should in turn call GenericStaticMethod < C1 > (...) or calling C2.Foo(), it should in turn call GenericStaticMethod < C2 > (...) ? - Malhar

    S M 2 Replies Last reply
    0
    • M malharone

      I posted a question earlier re. genarics for .net 2.0 and seems that what I'm trying to do is unfeasible. So here's my last (I think it's last) question on generics: Is it possible to reference "current class" instead of hard-coding the class name in the code? E.g.

      abstract class BaseClass
      {
      static void GenericStaticMethod < T > (args)
      {
      ...
      }
      void Foo()
      {
      GenericStaticMethod <CurrentClass>.(args);
      }
      }

      class C1 : BaseClass
      {
      ...
      }
      class C2 : BaseClass
      {
      ...
      }

      when calling C1.Foo(), it should in turn call GenericStaticMethod < C1 > (...) or calling C2.Foo(), it should in turn call GenericStaticMethod < C2 > (...) ? - Malhar

      S Offline
      S Offline
      Ssswamii
      wrote on last edited by
      #2

      I don't think so. The best way to accomplish what you're trying to do is to make Foo() virtual, then override Foo in the base classes to do call GenericStaticMethod using the current class type.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord's Prayer in Aramaic song (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      M 1 Reply Last reply
      0
      • S Ssswamii

        I don't think so. The best way to accomplish what you're trying to do is to make Foo() virtual, then override Foo in the base classes to do call GenericStaticMethod using the current class type.

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: The Lord's Prayer in Aramaic song (audio) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        M Offline
        M Offline
        malharone
        wrote on last edited by
        #3

        that's what i was afraid of! i wanted to use generics to the fullest. i wonder why microsoft couldn't have anticipated need for such. - Malhar

        1 Reply Last reply
        0
        • M malharone

          I posted a question earlier re. genarics for .net 2.0 and seems that what I'm trying to do is unfeasible. So here's my last (I think it's last) question on generics: Is it possible to reference "current class" instead of hard-coding the class name in the code? E.g.

          abstract class BaseClass
          {
          static void GenericStaticMethod < T > (args)
          {
          ...
          }
          void Foo()
          {
          GenericStaticMethod <CurrentClass>.(args);
          }
          }

          class C1 : BaseClass
          {
          ...
          }
          class C2 : BaseClass
          {
          ...
          }

          when calling C1.Foo(), it should in turn call GenericStaticMethod < C1 > (...) or calling C2.Foo(), it should in turn call GenericStaticMethod < C2 > (...) ? - Malhar

          M Offline
          M Offline
          Mattias Olgerfelt
          wrote on last edited by
          #4

          GenericStaticMethod .(args); Does not work? /M

          M 1 Reply Last reply
          0
          • M Mattias Olgerfelt

            GenericStaticMethod .(args); Does not work? /M

            M Offline
            M Offline
            malharone
            wrote on last edited by
            #5

            nope

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups