Generic Interface Implementation in C# Orcas Beta 1

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RG9uYWxkIFhpZQ==?=

    Generic Interface Implementation in C# Orcas Beta 1

    In C# 2, this works just fine:

    public class foo : IEnumerable<str ing>
    {
    private string[] _list;
    public IEnumerator<str ingGetEnumerato r()
    {
    foreach (string s in _list)
    yield return s;
    }
    }

    However Orcas complains that:

    'myNS.foo' does not implement interface member
    'System.Collect ions.IEnumerabl e.GetEnumerator ()'. 'myNS.foo.GetEn umerator()'
    cannot implement 'System.Collect ions.IEnumerabl e.GetEnumerator ()' because it
    does not have the matching return type of 'System.Collect ions.IEnumerato r'.

    It appears that I'll have to add an explicit non-generic interface
    implementation to appease the compiler:

    IEnumerator IEnumerable.Get Enumerator()
    {
    return GetEnumerator() ;
    }

    Just wondering whether this is a change in generics implementation or just a
    bug in beta 1.

    Cheers,
    Don

  • colin

    #2
    Re: Generic Interface Implementation in C# Orcas Beta 1

    "Donald Xie" <donald_xie@msd n.nospamwrote in message
    news:FA95F828-E810-48D0-9713-C67F31E2DD1B@mi crosoft.com...
    In C# 2, this works just fine:
    >
    public class foo : IEnumerable<str ing>
    {
    private string[] _list;
    public IEnumerator<str ingGetEnumerato r()
    {
    foreach (string s in _list)
    yield return s;
    }
    }
    >
    However Orcas complains that:
    >
    'myNS.foo' does not implement interface member
    'System.Collect ions.IEnumerabl e.GetEnumerator ()'.
    'myNS.foo.GetEn umerator()'
    cannot implement 'System.Collect ions.IEnumerabl e.GetEnumerator ()' because
    it
    does not have the matching return type of
    'System.Collect ions.IEnumerato r'.
    >
    It appears that I'll have to add an explicit non-generic interface
    implementation to appease the compiler:
    >
    IEnumerator IEnumerable.Get Enumerator()
    {
    return GetEnumerator() ;
    }
    >
    Just wondering whether this is a change in generics implementation or just
    a
    bug in beta 1.
    >
    Cheers,
    Don
    ive just done a simple binary sorted tree class,
    and was confused by this error too,
    I ended up inheriting only the non generic collection class stuff
    System.Collecti ons.CollectionB ase

    not sure what the pros and cons are ...

    Colin =^.^=


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Generic Interface Implementation in C# Orcas Beta 1

      Donald,

      Nothing has changed, the same error comes up in C# 2.0, so it's not an
      error in Orcas. This is what I get in C# 2.0:

      Error 1 'foo' does not implement interface member
      'System.Collect ions.IEnumerabl e.GetEnumerator ()'. 'foo.GetEnumera tor()' is
      either static, not public, or has the wrong return type.
      c:\temp\Console Application1\Co nsoleApplicatio n1\Program.cs 86 14
      ConsoleApplicat ion1

      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Donald Xie" <donald_xie@msd n.nospamwrote in message
      news:FA95F828-E810-48D0-9713-C67F31E2DD1B@mi crosoft.com...
      In C# 2, this works just fine:
      >
      public class foo : IEnumerable<str ing>
      {
      private string[] _list;
      public IEnumerator<str ingGetEnumerato r()
      {
      foreach (string s in _list)
      yield return s;
      }
      }
      >
      However Orcas complains that:
      >
      'myNS.foo' does not implement interface member
      'System.Collect ions.IEnumerabl e.GetEnumerator ()'.
      'myNS.foo.GetEn umerator()'
      cannot implement 'System.Collect ions.IEnumerabl e.GetEnumerator ()' because
      it
      does not have the matching return type of
      'System.Collect ions.IEnumerato r'.
      >
      It appears that I'll have to add an explicit non-generic interface
      implementation to appease the compiler:
      >
      IEnumerator IEnumerable.Get Enumerator()
      {
      return GetEnumerator() ;
      }
      >
      Just wondering whether this is a change in generics implementation or just
      a
      bug in beta 1.
      >
      Cheers,
      Don
      >

      Comment

      • =?Utf-8?B?RG9uYWxkIFhpZQ==?=

        #4
        Re: Generic Interface Implementation in C# Orcas Beta 1

        Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
        are you using?

        Thanks,
        Don

        "Nicholas Paldino [.NET/C# MVP]" wrote:
        Donald,
        >
        Nothing has changed, the same error comes up in C# 2.0, so it's not an
        error in Orcas. This is what I get in C# 2.0:
        >
        Error 1 'foo' does not implement interface member
        'System.Collect ions.IEnumerabl e.GetEnumerator ()'. 'foo.GetEnumera tor()' is
        either static, not public, or has the wrong return type.
        c:\temp\Console Application1\Co nsoleApplicatio n1\Program.cs 86 14
        ConsoleApplicat ion1
        >
        --
        - Nicholas Paldino [.NET/C# MVP]
        - mvp@spam.guard. caspershouse.co m
        >
        "Donald Xie" <donald_xie@msd n.nospamwrote in message
        news:FA95F828-E810-48D0-9713-C67F31E2DD1B@mi crosoft.com...
        In C# 2, this works just fine:

        public class foo : IEnumerable<str ing>
        {
        private string[] _list;
        public IEnumerator<str ingGetEnumerato r()
        {
        foreach (string s in _list)
        yield return s;
        }
        }

        However Orcas complains that:

        'myNS.foo' does not implement interface member
        'System.Collect ions.IEnumerabl e.GetEnumerator ()'.
        'myNS.foo.GetEn umerator()'
        cannot implement 'System.Collect ions.IEnumerabl e.GetEnumerator ()' because
        it
        does not have the matching return type of
        'System.Collect ions.IEnumerato r'.

        It appears that I'll have to add an explicit non-generic interface
        implementation to appease the compiler:

        IEnumerator IEnumerable.Get Enumerator()
        {
        return GetEnumerator() ;
        }

        Just wondering whether this is a change in generics implementation or just
        a
        bug in beta 1.

        Cheers,
        Don
        >

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Generic Interface Implementation in C# Orcas Beta 1

          Donald Xie <donald_xie@msd n.nospamwrote:
          Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
          are you using?
          I'm using VS2005 SP1 and get the same failure.

          Complete code:

          using System;
          using System.Collecti ons.Generic;

          public class Test : IEnumerable<str ing>
          {
          private string[] _list;
          public IEnumerator<str ingGetEnumerato r()
          {
          foreach (string s in _list)
          yield return s;
          }

          static void Main()
          {
          }
          }


          Compilation (including compiler version number):

          C:\Users\Jon\Te st>csc Test.cs
          Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
          for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
          Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

          Test.cs(4,14): error CS0536: 'Test' does not implement interface member
          'System.Collect ions.IEnumerabl e.GetEnumerator ()'.
          'Test.GetEnumer ator()'
          is either static, not public, or has the wrong return type.
          c:\Windows\Micr osoft.NET\Frame work\v2.0.50727 \mscorlib.dll: (Location
          of symbol
          related to previous error)
          Test.cs(7,32): (Location of symbol related to previous error)

          --
          Jon Skeet - <skeet@pobox.co m>
          http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
          If replying to the group, please do not mail me too

          Comment

          • =?Utf-8?B?RG9uYWxkIFhpZQ==?=

            #6
            Re: Generic Interface Implementation in C# Orcas Beta 1

            Thanks again Jon. Well I've just tried on my office PC with VS2..5 SP1, and I
            get this error too!

            I'll double check on my home PC when I get back tonight...

            Cheers,
            Don

            "Jon Skeet [C# MVP]" wrote:
            Donald Xie <donald_xie@msd n.nospamwrote:
            Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
            are you using?
            >
            I'm using VS2005 SP1 and get the same failure.
            >
            Complete code:
            >
            using System;
            using System.Collecti ons.Generic;
            >
            public class Test : IEnumerable<str ing>
            {
            private string[] _list;
            public IEnumerator<str ingGetEnumerato r()
            {
            foreach (string s in _list)
            yield return s;
            }
            >
            static void Main()
            {
            }
            }
            >
            >
            Compilation (including compiler version number):
            >
            C:\Users\Jon\Te st>csc Test.cs
            Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
            for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
            Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
            >
            Test.cs(4,14): error CS0536: 'Test' does not implement interface member
            'System.Collect ions.IEnumerabl e.GetEnumerator ()'.
            'Test.GetEnumer ator()'
            is either static, not public, or has the wrong return type.
            c:\Windows\Micr osoft.NET\Frame work\v2.0.50727 \mscorlib.dll: (Location
            of symbol
            related to previous error)
            Test.cs(7,32): (Location of symbol related to previous error)
            >
            --
            Jon Skeet - <skeet@pobox.co m>
            http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
            If replying to the group, please do not mail me too
            >

            Comment

            • =?Utf-8?B?RG9uYWxkIFhpZQ==?=

              #7
              Re: Generic Interface Implementation in C# Orcas Beta 1

              Excuse me when I'm pulling my foot from my mouth - the error is on my home PC
              as well. Now I'm wondering what I was doing yesterday...

              At least this is consistent so I just have to use the workaround.

              Thanks for setting me straight Jon ;-)

              Cheers,
              Don

              "Donald Xie" wrote:
              Thanks again Jon. Well I've just tried on my office PC with VS2..5 SP1, and I
              get this error too!
              >
              I'll double check on my home PC when I get back tonight...
              >
              Cheers,
              Don
              >
              "Jon Skeet [C# MVP]" wrote:
              >
              Donald Xie <donald_xie@msd n.nospamwrote:
              Hmm, I was using VS2005 SP1, which seems to be happy with this. What version
              are you using?
              I'm using VS2005 SP1 and get the same failure.

              Complete code:

              using System;
              using System.Collecti ons.Generic;

              public class Test : IEnumerable<str ing>
              {
              private string[] _list;
              public IEnumerator<str ingGetEnumerato r()
              {
              foreach (string s in _list)
              yield return s;
              }

              static void Main()
              {
              }
              }


              Compilation (including compiler version number):

              C:\Users\Jon\Te st>csc Test.cs
              Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.312
              for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
              Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

              Test.cs(4,14): error CS0536: 'Test' does not implement interface member
              'System.Collect ions.IEnumerabl e.GetEnumerator ()'.
              'Test.GetEnumer ator()'
              is either static, not public, or has the wrong return type.
              c:\Windows\Micr osoft.NET\Frame work\v2.0.50727 \mscorlib.dll: (Location
              of symbol
              related to previous error)
              Test.cs(7,32): (Location of symbol related to previous error)

              --
              Jon Skeet - <skeet@pobox.co m>
              http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
              If replying to the group, please do not mail me too

              Comment

              Working...