Synchronizing a ListDictionary

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Allen Jones

    #1

    Synchronizing a ListDictionary

    Hi,

    I tried to extend ListDictionary in order to create a thread safe version
    named SynchronizedLis tDictionary.

    Despite the docs saying the properties and methods of ListDictionary are
    virtual, when I try to compile my derived class, the compiler tells me that
    I "cannot override inherited member XXX because it is not marked virtual,
    abstract, or override".

    I know there are other collections and techniques that I can use as an
    alternative, but I want to understand how a method can be listed as virtual
    in the docs (which I thought came straight from the source) but the compiler
    doesnt recognize it as such.

    Thanks

    Regards
    Allen


  • Jon Davis

    #2
    Re: Synchronizing a ListDictionary

    Try using "new". It doesn't override the virtual method, but it will be
    called when referenced in the context of your customized class.

    Jon


    "Allen Jones" <agj@bigfoot.co m> wrote in message
    news:eW48zPgTDH A.2280@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi,
    >
    > I tried to extend ListDictionary in order to create a thread safe version
    > named SynchronizedLis tDictionary.
    >
    > Despite the docs saying the properties and methods of ListDictionary are
    > virtual, when I try to compile my derived class, the compiler tells me[/color]
    that[color=blue]
    > I "cannot override inherited member XXX because it is not marked virtual,
    > abstract, or override".
    >
    > I know there are other collections and techniques that I can use as an
    > alternative, but I want to understand how a method can be listed as[/color]
    virtual[color=blue]
    > in the docs (which I thought came straight from the source) but the[/color]
    compiler[color=blue]
    > doesnt recognize it as such.
    >
    > Thanks
    >
    > Regards
    > Allen
    >
    >[/color]


    Comment

    • Allen Jones

      #3
      Re: Synchronizing a ListDictionary

      Hi Jon,

      Thanks for the input, but as I said in my post, I am not after work arounds
      or alternatives. I want to understand why this does not work the way it
      should.

      Regards
      Allen

      "Jon Davis" <jon@REMOVE.ME. PLEASE.jondavis .net> wrote in message
      news:us7qwAoTDH A.3712@tk2msftn gp13.phx.gbl...[color=blue]
      > Try using "new". It doesn't override the virtual method, but it will be
      > called when referenced in the context of your customized class.
      >
      > Jon
      >
      >
      > "Allen Jones" <agj@bigfoot.co m> wrote in message
      > news:eW48zPgTDH A.2280@TK2MSFTN GP12.phx.gbl...[color=green]
      > > Hi,
      > >
      > > I tried to extend ListDictionary in order to create a thread safe[/color][/color]
      version[color=blue][color=green]
      > > named SynchronizedLis tDictionary.
      > >
      > > Despite the docs saying the properties and methods of ListDictionary are
      > > virtual, when I try to compile my derived class, the compiler tells me[/color]
      > that[color=green]
      > > I "cannot override inherited member XXX because it is not marked[/color][/color]
      virtual,[color=blue][color=green]
      > > abstract, or override".
      > >
      > > I know there are other collections and techniques that I can use as an
      > > alternative, but I want to understand how a method can be listed as[/color]
      > virtual[color=green]
      > > in the docs (which I thought came straight from the source) but the[/color]
      > compiler[color=green]
      > > doesnt recognize it as such.
      > >
      > > Thanks
      > >
      > > Regards
      > > Allen
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Austin Ehlers

        #4
        Re: Synchronizing a ListDictionary

        On Sat, 19 Jul 2003 15:42:01 +0100, "Allen Jones" <agj@bigfoot.co m>
        wrote:
        [color=blue]
        >Hi,
        >
        >I tried to extend ListDictionary in order to create a thread safe version
        >named SynchronizedLis tDictionary.
        >
        >Despite the docs saying the properties and methods of ListDictionary are
        >virtual, when I try to compile my derived class, the compiler tells me that
        >I "cannot override inherited member XXX because it is not marked virtual,
        >abstract, or override".
        >
        >I know there are other collections and techniques that I can use as an
        >alternative, but I want to understand how a method can be listed as virtual
        >in the docs (which I thought came straight from the source) but the compiler
        >doesnt recognize it as such.
        >
        >Thanks
        >
        >Regards
        >Allen
        >[/color]

        How did you override it? Using VS2003, this works:
        public class MyDict:ListDict ionary,IDiction ary
        {
        public MyDict()
        {
        }
        private class myDict:IDiction ary
        }


        When you type myDict:IDiction ary, VS will show a little tip that says:
        "Press TAB to implement stubs for interface
        System.Collecti ons.IDictionary "

        Does that work for you?

        Comment

        • Allen Jones

          #5
          Re: Synchronizing a ListDictionary

          Austin,

          Its the individual members that cause a problem when I compile them. e.g.

          public class SynchronizedLis tDictionary : ListDictionary {

          // other stuff

          public override void Add(object key, object value) {
          // method implementation
          }
          }

          In the example the Add method causes the compiler to report the message:
          Add(object, object) canot override
          System.Collecti ons.Specialized .ListDictionary .Add(object,obj ect) because it
          is not marked virtual, abstract, or override.

          The problem is, according to the docs, ListDictionary. Add IS virtual.

          Regards
          Allen

          "Austin Ehlers" <the*remove*bor ed*me*guy16@hot mail.com> wrote in message
          news:8gcmhvon4t usi0k692bc6v850 5hfho2t59@4ax.c om...[color=blue]
          > On Sat, 19 Jul 2003 15:42:01 +0100, "Allen Jones" <agj@bigfoot.co m>
          > wrote:
          >[color=green]
          > >Hi,
          > >
          > >I tried to extend ListDictionary in order to create a thread safe version
          > >named SynchronizedLis tDictionary.
          > >
          > >Despite the docs saying the properties and methods of ListDictionary are
          > >virtual, when I try to compile my derived class, the compiler tells me[/color][/color]
          that[color=blue][color=green]
          > >I "cannot override inherited member XXX because it is not marked virtual,
          > >abstract, or override".
          > >
          > >I know there are other collections and techniques that I can use as an
          > >alternative, but I want to understand how a method can be listed as[/color][/color]
          virtual[color=blue][color=green]
          > >in the docs (which I thought came straight from the source) but the[/color][/color]
          compiler[color=blue][color=green]
          > >doesnt recognize it as such.
          > >
          > >Thanks
          > >
          > >Regards
          > >Allen
          > >[/color]
          >
          > How did you override it? Using VS2003, this works:
          > public class MyDict:ListDict ionary,IDiction ary
          > {
          > public MyDict()
          > {
          > }
          > private class myDict:IDiction ary
          > }
          >
          >
          > When you type myDict:IDiction ary, VS will show a little tip that says:
          > "Press TAB to implement stubs for interface
          > System.Collecti ons.IDictionary "
          >
          > Does that work for you?[/color]


          Comment

          • Simon Trew

            #6
            Re: Synchronizing a ListDictionary

            Yes, I have tried it & I agree there seems to be a discrepancy between the
            docs and real life.

            I appreciate you are not looking for workarounds, but just for information,
            you can override the interface explicitly i.e.:

            void IDictionary.Add (object key, object value);

            However, this may not be ideal in all circumstances.

            S.

            "Allen Jones" <agj@bigfoot.co m> wrote in message
            news:e476VD2TDH A.2092@TK2MSFTN GP10.phx.gbl...[color=blue]
            > Austin,
            >
            > Its the individual members that cause a problem when I compile them. e.g.
            >
            > public class SynchronizedLis tDictionary : ListDictionary {
            >
            > // other stuff
            >
            > public override void Add(object key, object value) {
            > // method implementation
            > }
            > }
            >
            > In the example the Add method causes the compiler to report the message:
            > Add(object, object) canot override
            > System.Collecti ons.Specialized .ListDictionary .Add(object,obj ect) because[/color]
            it[color=blue]
            > is not marked virtual, abstract, or override.
            >
            > The problem is, according to the docs, ListDictionary. Add IS virtual.
            >
            > Regards
            > Allen
            >
            > "Austin Ehlers" <the*remove*bor ed*me*guy16@hot mail.com> wrote in message
            > news:8gcmhvon4t usi0k692bc6v850 5hfho2t59@4ax.c om...[color=green]
            > > On Sat, 19 Jul 2003 15:42:01 +0100, "Allen Jones" <agj@bigfoot.co m>
            > > wrote:
            > >[color=darkred]
            > > >Hi,
            > > >
            > > >I tried to extend ListDictionary in order to create a thread safe[/color][/color][/color]
            version[color=blue][color=green][color=darkred]
            > > >named SynchronizedLis tDictionary.
            > > >
            > > >Despite the docs saying the properties and methods of ListDictionary[/color][/color][/color]
            are[color=blue][color=green][color=darkred]
            > > >virtual, when I try to compile my derived class, the compiler tells me[/color][/color]
            > that[color=green][color=darkred]
            > > >I "cannot override inherited member XXX because it is not marked[/color][/color][/color]
            virtual,[color=blue][color=green][color=darkred]
            > > >abstract, or override".
            > > >
            > > >I know there are other collections and techniques that I can use as an
            > > >alternative, but I want to understand how a method can be listed as[/color][/color]
            > virtual[color=green][color=darkred]
            > > >in the docs (which I thought came straight from the source) but the[/color][/color]
            > compiler[color=green][color=darkred]
            > > >doesnt recognize it as such.
            > > >
            > > >Thanks
            > > >
            > > >Regards
            > > >Allen
            > > >[/color]
            > >
            > > How did you override it? Using VS2003, this works:
            > > public class MyDict:ListDict ionary,IDiction ary
            > > {
            > > public MyDict()
            > > {
            > > }
            > > private class myDict:IDiction ary
            > > }
            > >
            > >
            > > When you type myDict:IDiction ary, VS will show a little tip that says:
            > > "Press TAB to implement stubs for interface
            > > System.Collecti ons.IDictionary "
            > >
            > > Does that work for you?[/color]
            >
            >[/color]


            Comment

            • Austin Ehlers

              #7
              Re: Synchronizing a ListDictionary ATTN: MSFT

              Well. looking at the rotor source code, it does appear that the
              documentation is wrong. It's declared as:

              public void Add(object key, object value)
              {
              //stuff
              }

              So, it's another error in the documentation.


              On Mon, 21 Jul 2003 09:19:32 +0100, "Allen Jones" <agj@bigfoot.co m>
              wrote:
              [color=blue]
              >Austin,
              >
              >Its the individual members that cause a problem when I compile them. e.g.
              >
              >public class SynchronizedLis tDictionary : ListDictionary {
              >
              > // other stuff
              >
              > public override void Add(object key, object value) {[/color]
              [color=blue]
              > // method implementation
              > }
              >}
              >
              >In the example the Add method causes the compiler to report the message:
              >Add(object, object) canot override
              >System.Collect ions.Specialize d.ListDictionar y.Add(object,ob ject) because it
              >is not marked virtual, abstract, or override.
              >
              >The problem is, according to the docs, ListDictionary. Add IS virtual.
              >
              >Regards
              >Allen
              >
              >"Austin Ehlers" <the*remove*bor ed*me*guy16@hot mail.com> wrote in message
              >news:8gcmhvon4 tusi0k692bc6v85 05hfho2t59@4ax. com...[color=green]
              >> On Sat, 19 Jul 2003 15:42:01 +0100, "Allen Jones" <agj@bigfoot.co m>
              >> wrote:
              >>[color=darkred]
              >> >Hi,
              >> >
              >> >I tried to extend ListDictionary in order to create a thread safe version
              >> >named SynchronizedLis tDictionary.
              >> >
              >> >Despite the docs saying the properties and methods of ListDictionary are
              >> >virtual, when I try to compile my derived class, the compiler tells me[/color][/color]
              >that[color=green][color=darkred]
              >> >I "cannot override inherited member XXX because it is not marked virtual,
              >> >abstract, or override".
              >> >
              >> >I know there are other collections and techniques that I can use as an
              >> >alternative, but I want to understand how a method can be listed as[/color][/color]
              >virtual[color=green][color=darkred]
              >> >in the docs (which I thought came straight from the source) but the[/color][/color]
              >compiler[color=green][color=darkred]
              >> >doesnt recognize it as such.
              >> >
              >> >Thanks
              >> >
              >> >Regards
              >> >Allen
              >> >[/color]
              >>
              >> How did you override it? Using VS2003, this works:
              >> public class MyDict:ListDict ionary,IDiction ary
              >> {
              >> public MyDict()
              >> {
              >> }
              >> private class myDict:IDiction ary
              >> }
              >>
              >>
              >> When you type myDict:IDiction ary, VS will show a little tip that says:
              >> "Press TAB to implement stubs for interface
              >> System.Collecti ons.IDictionary "
              >>
              >> Does that work for you?[/color]
              >[/color]

              Comment

              Working...