Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDynamo_Maestro

Posted 31 May 2013 - 08:09 AM

Code Example:

 

    public interface ITest
    {
        void SomeMethod();
    }

    public abstract class TestBase : ITest
    {
        void ITest.SomeMethod()
        { 
            // Stuff
        }
    }

    /// <summary>
    /// Compiler Error: -
    ///     Error	1	'AnotherTest.ITest.SomeMethod()': containing type does not implement interface 'ITest'
    /// 
    /// Need to implement ITest to avoid this error
    /// </summary>
    public class AnotherTest : TestBase, ITest
    {
        /// <summary>
        /// Did I just override this?
        /// What if I wanted it sealed
        /// </summary>
        void ITest.SomeMethod()
        {
            // Stuff
        }
    }

 

When you explicitly implement an interface, you cant use the modifier abstract or virtual on its members you want to be called explicitly (in this cast ITest.SomeMethod()), so my question is, in the class AnotherTest did I override ITest.SomeMethod()? and why do I get a compiler error if I don't inherit ITest in AnotherTest despite it already being inherited in the base class?

 

I am not familiar with CIL or how this is treated internally, but would this be treated as a virtual method being overridden or a completely new method?


#2Dynamo_Maestro

Posted 31 May 2013 - 08:09 AM

Code Example:

 

    public interface ITest
    {
        void SomeMethod();
    }

    public abstract class TestBase : ITest
    {
        void ITest.SomeMethod()
        { 
            // Stuff
        }
    }

    /// <summary>
    /// Compiler Error: -
    ///     Error	1	'AnotherTest.ITest.SomeMethod()': containing type does not implement interface 'ITest'
    /// 
    /// Need to implement ITest to avoid this error
    /// </summary>
    public class AnotherTest : TestBase, ITest
    {
        /// <summary>
        /// Did I just override this?
        /// What if I wanted it sealed
        /// </summary>
        void ITest.SomeMethod()
        {
            // Stuff
        }
    }

 

When you explicitly implement an interface, you cant use the modifier abstract or virtual on its members you want to be called explicitly (in this cast ITest.SomeMethod()), so my question is, in the class AnotherTest did I override ITest.SomeMethod()? and why do I get a compiler error if I don't inherit ITest in AnotherTest despite it already being inherited in the base class?

 

I am not familiar with CIL or how this is treated externally, but would this be treated as a virtual method being overridden or a completely new method?


#1Dynamo_Maestro

Posted 31 May 2013 - 08:05 AM

Code Example:

 

    public interface ITest
    {
        void SomeMethod();
    }

    public abstract class TestBase : ITest
    {
        void ITest.SomeMethod()
        { 
            // Stuff
        }
    }

    /// <summary>
    /// Compiler Error: -
    ///     Error	1	'AnotherTest.ITest.SomeMethod()': containing type does not implement interface 'ITest'
    /// 
    /// Need to implement ITest to avoid this error
    /// </summary>
    public class AnotherTest : TestBase, ITest
    {
        /// <summary>
        /// Did I just override this?
        /// What if I wanted it sealed
        /// </summary>
        void ITest.SomeMethod()
        {
            // Stuff
        }
    }

 

When you explicitly implement an interface, you cant use the modifier abstract or virtual, so my question is in the class AnotherTest did I override ITest.SomeMethod()? and why do I get a compiler error if I don't implement ITest in AnotherTest despite it already being implemented in the base class?

 

I am not familiar with CIL or how this is treated externally, but would this be treated as a virtual method being overridden or a completely new method?


PARTNERS