[Mono-list] Help John's poor tired brain.

Jason Diamond jason@injektilo.org
Sun, 15 Jul 2001 00:20:28 -0700


Sorry, that was a cut and paste bug on my part. Explicit interface
implementation members can't have a public modifier since they aren't
supposed to be accessible through references to the class.

namespace Test
{
	interface IEnumerable
	{
		IEnumerator GetEnumerator();
	}

	interface IDictionary : IEnumerable
	{
		new IDictionaryEnumerator GetEnumerator();
	}

	interface IEnumerator {}

	interface IDictionaryEnumerator : IEnumerator {}

	class Foo : IDictionary
	{
		IEnumerator IEnumerable.GetEnumerator()
		{
			return null;
		}

		public virtual IDictionaryEnumerator GetEnumerator()
		{
			return null;
		}
	}
}

Adding public or virtual to the first GetEnumerator gives the errors you
described. Interface methods are always public and virtual by definition so
the there's no need to specify that.

Jason.

> -----Original Message-----
> From: John Barnette [mailto:jbarn@httcb.net]
> Sent: Sunday, July 15, 2001 12:10 AM
> To: Jason Diamond; mono
> Subject: RE: [Mono-list] Help John's poor tired brain.
>
>
> > Try using an explicit interface implementation:
> >
> > public virtual IEnumerator IEnumerable.GetEnumerator() {
> > 	return null;
> > }
>
> Tried that already, actually.  With stub code like:
>
> 	public virtual IDictionaryEnumerator IDictionary.GetEnumerator() {
> 		return null;
> 	}
>
> 	public virtual IEnumerator IEnumerable.GetEnumerator() {
> 		return null;
> 	}
>
> ...two errors pop up for each method, along the lines of:
>
> error CS0106: The modifier 'virtual' is not valid for this item
> error CS0106: The modifier 'public' is not valid for this item
>
>
>
> ~ j.
>
>
>
> > > -----Original Message-----
> > > From: mono-list-admin@ximian.com [mailto:mono-list-admin@ximian.com]On
> > > Behalf Of John Barnette
> > > Sent: Saturday, July 14, 2001 11:42 PM
> > > To: mono
> > > Subject: [Mono-list] Help John's poor tired brain.
> > >
> > >
> > > Okay, so Hashtable implements IEnumerable and IDictionary,
> both of which
> > > define a GetEnumerator() method.  Specifically:
> > >
> > > IEnumerable:
> > > 	IEnumerator GetEnumerator();
> > >
> > > IDictionary:
> > > 	IDictionaryEnumerator GetEnumerator();
> > >
> > > IDictionary inherits from IEnumerable:
> > > 	public interface IDictionary : ICollection, IEnumerable
> > >
> > >
> > > Attempting to compile my Hashtable with this stubbed implementation of
> > > GetEnumerator():
> > >
> > > 		public virtual IDictionaryEnumerator GetEnumerator() {
> > > 			return null;
> > > 		}
> > >
> > > ...yields a pleasant compiler error:
> > >
> > > "error CS0536: 'System.Collections.JBHashtable' does not
> > > implement interface
> > > member 'System.Collections.IEnumerable.GetEnumerator()'.
> > > 'System.Collections.JBHashtable.GetEnumerator()' is either static, not
> > > public, or has the wrong return type."
> > >
> > > Help!  I'm tired, I just wrote the threadsafe wrapper, and I
> > want to go to
> > > sleep. ;-)
> > >
> > >
> > > ~ j.
> > >
> > >
> > > _______________________________________________
> > > Mono-list maillist  -  Mono-list@ximian.com
> > > http://lists.ximian.com/mailman/listinfo/mono-list
> > >
> >
>