1

このクラス プロパティは、インターフェイスにリファクタリングしようとしているものです。

public class Stuff : IStuff {
    public int Number {
        get;
        protected internal set;
    }
}

Visual Studio 2008 リファクタリング ツールは、次のインターフェイスを抽出します

// Visual Studio 2008's attempt is:
public interface IStuff {
    int Number { get; }
}

C# コンパイラは次のエラーを訴えます。

'Stuff.Number.set' adds an accessor not found in interface member 'IStuff.DataOperations'

(これは、Visual Studio が不適切なコンパイル状況を引き起こすコードを生成する状況に遭遇した数少ない状況の 1 つです。)

この 1 つのプロパティをインターフェイスに抽出する直接的な解決策はありますか?

4

1 に答える 1

2

私は以下でテストしました:

class bla : Ibla {
    public int Blargh { get; protected internal set; }
}

interface Ibla {
    int Blargh { get; }
}

そしてそれはうまく機能します。インターフェイスを正しく実装しましたか?

于 2009-12-09T19:11:48.903 に答える