Share via


CodeAttribute2 インターフェイス

コード要素の属性を定義します。

名前空間:  EnvDTE80
アセンブリ:  EnvDTE80 (EnvDTE80.dll 内)

構文

'宣言
<GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")> _
Public Interface CodeAttribute2 _
    Inherits CodeAttribute
[GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")]
public interface CodeAttribute2 : CodeAttribute
[GuidAttribute(L"35187E2A-E5F6-4F89-A4CE-DA254640855B")]
public interface class CodeAttribute2 : CodeAttribute
[<GuidAttribute("35187E2A-E5F6-4F89-A4CE-DA254640855B")>]
type CodeAttribute2 =  
    interface 
        interface CodeAttribute 
    end
public interface CodeAttribute2 extends CodeAttribute

CodeAttribute2 型で公開されるメンバーは以下のとおりです。

プロパティ

  名前 説明
パブリック プロパティ Arguments この属性に関連付けられた CodeAttributeArgument オブジェクトを含む CodeElement オブジェクトのコレクションを取得します。
パブリック プロパティ Children このコード コンストラクターに含まれているオブジェクトのコレクションを取得します。
パブリック プロパティ Collection CodeAttribute2 オブジェクトのコレクションを取得します。
パブリック プロパティ DTE トップレベルの機能拡張オブジェクトを取得します。
パブリック プロパティ EndPoint コード属性の終了位置であるエディット ポイントを取得します。
パブリック プロパティ Extender 要求された Extender がこのコード属性で利用できる場合はそれを返します。
パブリック プロパティ ExtenderCATID オブジェクトの Extender カテゴリ ID (CATID) を取得します。
パブリック プロパティ ExtenderNames オブジェクトで使用できる Extender の名前の一覧を取得します。
パブリック プロパティ FullName オブジェクトのファイルの完全パスと名前を取得します。
パブリック プロパティ InfoLocation コード モデルを取得します。
パブリック プロパティ IsCodeType このオブジェクトから CodeType オブジェクトを取得できるかどうかを示す値を取得します。
パブリック プロパティ Kind 属性の型を示す列挙値を取得します。
パブリック プロパティ Language 属性の作成に使用されたプログラミング言語を識別する定数を取得します。
パブリック プロパティ Name コード属性の名前を設定または取得します。
パブリック プロパティ Parent コード属性のすぐ上の親オブジェクトを取得します。
パブリック プロパティ ProjectItem コード属性に関連付けられている ProjectItem を取得します。
パブリック プロパティ StartPoint 属性の先頭を定義する TextPoint を取得します。
パブリック プロパティ Target コード属性の対象を設定または取得します。
パブリック プロパティ Value コード属性のデータを設定または取得します。

このページのトップへ

メソッド

  名前 説明
パブリック メソッド AddArgument 属性に引数を追加します。
パブリック メソッド Delete コード要素のすべての属性を削除します。
パブリック メソッド GetEndPoint 属性の終了位置を示す TextPoint オブジェクトを返します。
パブリック メソッド GetStartPoint 属性の開始位置を示す TextPoint オブジェクトを返します。

このページのトップへ

解説

CodeAttribute2 オブジェクトは、コード要素に関連付けられた 1 つの COM メタデータ属性を表します。 AddAttribute メソッドで新しい属性を追加したり、適切なオブジェクトで Delete メソッドを使用して属性を削除したりできます。 このオブジェクトを使用して、コード属性の値を取得および設定できます。

注意

特定の種類の編集を行った後に、クラス、構造体、関数、属性、デリゲートなどのコード モデル要素の値を決定できないことがあります。つまり、これらの要素の値は、信頼できる値ではなく、常に同じ値になるとは限りません。詳細については、「コード モデルを使用したコードの調査 (Visual Basic)」で、コード モデル要素値を変更する方法についての説明を参照してください。

// The following example creates a new namespace and attribute in the current class.
public void CreateClassAndAttrib(DTE2 applicationObject)
{
    // Before running, load or create a project.
    FileCodeModel2 fcm2 = GetFileCodeModel(applicationObject);
    CodeAttribute2 cmAttribute;
    CodeClass2 cmClass;

    if (fcm2 != null)
    {
        CodeNamespace cmNamespace;
        // Try to create a new namespace.
        try
        {
            cmNamespace = fcm2.AddNamespace("CMNamespace", -1);
            // If successful, create the other code elements.
            if (cmNamespace != null)
            {
                cmClass = (CodeClass2)cmNamespace.AddClass("ANewClass", 
                -1, null, null, vsCMAccess.vsCMAccessPrivate);
                cmAttribute = (CodeAttribute2)cmClass.AddAttribute
                ("NewAttribute", "AttributeValue", -1);
            }
            else
            {
                MessageBox.Show("Cannot continue - no filecodemodel 
                available.");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("ERROR: " + ex);
        }
    }
}

public FileCodeModel2 GetFileCodeModel(DTE2 applicationObject)
{
    // Returns the FileCodeModel object of the active 
    // window.
    TextWindow txtWin = 
    (TextWindow)applicationObject.ActiveWindow.Object;
    FileCodeModel2 fcm2;
    if (txtWin != null)
    {
        try
        {
             fcm2 = (FileCodeModel2)txtWin.Parent.
             ProjectItem.FileCodeModel;
             return fcm2;
        }
        catch (Exception ex)
        {
             MessageBox.Show("ERROR: " + ex);
             return null;
        }
    }
    else
        return null;
}

参照

関連項目

EnvDTE80 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する

コード モデルを使用したコードの調査 (Visual Basic)

コード モデルを使用したコードの調査 (Visual C#)