5

Visual Studio でインターフェイス 'public' を作成する方法はありますか? たとえば、フォルダーを右クリック -> 新しい項目を作成 -> コード -> インターフェイス。

ファイルが作成されるときはいつでも、アクセス修飾子はありません。

interface IMyInterface 
{

}

デフォルトで公開する方法はありますか?

public interface IMyInterface
{

}

私はいつも手動でそれらをパブリックに変更することを忘れています(必要な場合)。

4

2 に答える 2

5

Open your project with the public IMyInterface interface shown above.

Go to File > Export Template.

Follow the steps (make sure you choose item template rather than Project template) and save it under a name of your choice.

When you restart visual studio and have a project open it will be available from the add item dialog. You will be able to set the name of the interface from the dialog just like you can with the other items.

Note that this does not overwrite the default interface template installed with Visual Studio so you can still just as easily make a private interface when required.

于 2013-01-05T12:20:43.883 に答える
1

次のようなパブリック インターフェイスのコード スニペットを作成することもできます。

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
    <Header>
        <Title>public interface</Title>
    </Header>
    <Snippet>
        <Code Language="csharp">
            <![CDATA[
    public interface IMyInterface
        {
            }
    ]]>
        </Code>
    </Snippet>
</CodeSnippet>

publicinterfacecsharp.snippet として保存します。次に、[ツール] -> [コード スニペット マネージャー ] に移動し
ます。C# および [マイ コード スニペット] フォルダーとして言語を選択し、[インポート] をクリックして、スニペットを保存した場所をポイントします。これで、任意の新しいプロジェクトで、エディター ウィンドウを右クリックし、[コード スニペットの挿入] -> [マイ コード スニペット] -> [publicinterfacecsharp] を選択できます。

于 2013-01-05T13:12:33.123 に答える