If you really want the protected internal you can accomplish something
similar with the following


   class FooBase :IFoo {
       protected virtual internal void internalbar() {
           Console.WriteLine("FooBase");
       }
       void IFoo.Bar() {
           this.internalbar();
       }
   }

   class FooDerived : FooBase, IFoo {
       protected internal override void internalbar() {
           Console.WriteLine("DerivedFoo");
       }
   }



On 7/7/06, gregory young <[EMAIL PROTECTED]> wrote:

 The only thing you I don't think you can do is make the explicit
implementation also a protected internal (although this doesn't make much
sense anyways since you are exposing it through a public interface). YOu can
still reimplement the interface without issue.

    public interface IFoo {
        void Bar();
    }

    class FooBase :IFoo {
        void IFoo.Bar() {
            Console.WriteLine("FooBase");
        }
    }

    class FooDerived : FooBase, IFoo {
        void IFoo.Bar() {
            Console.WriteLine("FooDerived");
        }
    }



On 7/7/06, Mike Andrews <[EMAIL PROTECTED]> wrote:
>
> Thank you.
>
> However, that does not help with the idea that a base class implements
> an
> interface and then I re-implement the interface on derived classes where
>
> needed.  This is so that ever class that inherits from the base class
> also
> implements the interface, even if I do not re-implement it for the
> derived
> class.  But some derived classes will add their own functionality.
>
> Thanks,
> Mike
>
>
> On 7/7/06, gregory young <[EMAIL PROTECTED]> wrote:
> >
> > You have to do whats called "explicitly implementing" a interface. See
>
> > http://msdn2.microsoft.com/en-us/library/4taxa8t2.aspx
> >
> > Cheers,
> >
> > Greg
> >
> >
> > On 7/7/06, Mike Andrews < [EMAIL PROTECTED]> wrote:
> > >
> > > Guys,
> > >
> > > I have a question that I need some help with in regards to
> implementing
> > an
> > > interface.
> > > I've been a VB programmer for most of my career and now I use
> C#.  Some
> > of
> > > the functionality that I used in VB seems to be lacking in C#.
> > > I wanted to know if it's my imagination or if there's a workaround.
> > >
> > > The base problem is that I want to change the access level on
> interface
> > > methods once they are implemented in a class.  However, C# seems to
> cry
> > > and
> > > such changes and VB seems to allow them.  Here's the example:
> > >
> > > Here's the VB example:
> > >
> > > Public Interface IBusiness
> > >
> > >    Sub Remove()
> > >    Sub Save()
> > >    Property ID() As Guid
> > >
> > > End Interface
> > >
> > > Public MustInherit Class T
> > >    Implements IBusiness
> > >
> > >    Public MustOverride Sub DoStuff()
> > >
> > >    Protected Friend Overridable Property ID() As System.GuidImplements
> > > IBusiness.ID
> > >        Get
> > >
> > >        End Get
> > >        Set(ByVal value As System.Guid)
> > >
> > >        End Set
> > >    End Property
> > >
> > >    Protected Friend Overridable Sub Remove() Implements
> IBusiness.Remove
> > >
> > >    End Sub
> > >
> > >    Protected Friend Overridable Sub Save() Implements IBusiness.Save
> > >
> > >    End Sub
> > >
> > > End Class
> > >
> > > Notice in this example that these methods are the implementation for
> > > IBusiness, but I changed the access modifiers to Protected Friend
> > instead
> > > of
> > > public or something else.
> > >
> > > Now, in C#, if I try to do the same, I get a compiler error:
> > >
> > >    public interface IBusiness {
> > >
> > >        void Remove();
> > >        void Save();
> > >        Guid ID { get; set;}
> > >
> > >    }
> > >
> > >    public abstract class T: IBusiness {
> > >
> > >
> > >        #region IBusiness Members
> > >
> > >        public void Remove() {
> > >            throw new Exception("The method or operation is not
> > > implemented.");
> > >        }
> > >
> > >        public void Save() {
> > >            throw new Exception("The method or operation is not
> > > implemented.");
> > >        }
> > >
> > >        public Guid ID {
> > >            get {
> > >                throw new Exception("The method or operation is not
> > > implemented.");
> > >            }
> > >            set {
> > >                throw new Exception("The method or operation is not
> > > implemented.");
> > >            }
> > >        }
> > >
> > >        #endregion
> > >
> > >    }
> > >
> > > If I change the public members to protected or private I get an
> > error.  If
> > > I
> > > change them to explicit implementation, then I cannot access them
> > > regardless
> > > unless I cast to the interface.
> > >
> > > What I'm want to do is implement an interface in a base class (so
> that I
> > > don't have to implement it in every derived class) and then
> > "re-implement"
> > > for the derived class where necessary but have a protected internal
> > access
> > > modifier.
> > >
> > > Any suggestions or am I barking up the wrong tree here?
> > >
> > > Thanks,
> > > Mike
> > >
> > > ===================================
> > > This list is hosted by DevelopMentor(r)  http://www.develop.com
> > >
> > > View archives and manage your subscription(s) at
> > > http://discuss.develop.com
> > >
> >
> >
> >
> > --
> > If knowledge can create problems, it is not through ignorance that we
> can
> > solve them.
> >
> > Isaac Asimov
> >
> > ===================================
> > This list is hosted by DevelopMentor(r)  http://www.develop.com
> >
> > View archives and manage your subscription(s) at
> > http://discuss.develop.com
> >
>
> ===================================
> This list is hosted by DevelopMentor(r)   http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>



--

If knowledge can create problems, it is not through ignorance that we can
solve them.

Isaac Asimov




--
If knowledge can create problems, it is not through ignorance that we can
solve them.

Isaac Asimov

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to