2009-10-22 3 views
1

이 같은 인터페이스 계층 구조를 상상 :부모 인터페이스에 동일한 멤버의보다 인터페이스의 멤버로 다른 특성을 적용하는 방법

public interface IAnimal 
{ 
    string Color { get; } 
} 


public interface ICat : IAnimal 
{ 
} 

이 경우를 ICAT '상속'IAnimal의 Color 속성.

ICat의 Color 속성에 IAnimal에 속성을 추가하지 않고 속성을 추가 할 수 있습니까? 다음

내가 달성하기 위해 노력하고 무엇의 예이지만, 컴파일러 경고 제공 :

public interface IAnimal 
{ 
    string Color { get; } 
} 


public interface ICat : IAnimal 
{ 
    [MyProperty] 
    string Color { get; } 
} 

답변

1

나는 당신이 점점 경고 당신이 그 속성을 적용하여 달성하려고하는 무엇

warning CS0108: 'ICat.Color' hides inherited member 'IAnimal.Color'. Use the new keyword if hiding was intended. 

가정?
경고를 피하려면 다음과 같이하십시오.

public class MyPropertyAttribute : Attribute { } 

public interface IAnimal { 
    string Color { get; } 
} 

public abstract class Cat : IAnimal { 
    [MyProperty] 
    public string Color { 
     get { return CatColor; } 
    } 
    protected abstract string CatColor { 
     get; 
    } 
} 
관련 문제