CodeAttribute2.DTE Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Ruft das Erweiterbarkeitsobjekt der obersten Ebene ab.
public:
property EnvDTE::DTE ^ DTE { EnvDTE::DTE ^ get(); };
public:
property EnvDTE::DTE ^ DTE { EnvDTE::DTE ^ get(); };
[System.Runtime.InteropServices.DispId(1)]
public EnvDTE.DTE DTE { [System.Runtime.InteropServices.DispId(1)] [System.Runtime.InteropServices.TypeLibFunc(1024)] get; }
[<System.Runtime.InteropServices.DispId(1)>]
[<get: System.Runtime.InteropServices.DispId(1)>]
[<get: System.Runtime.InteropServices.TypeLibFunc(1024)>]
member this.DTE : EnvDTE.DTE
Public ReadOnly Property DTE As DTE
Eigenschaftswert
Ein DTE-Objekt.
Implementiert
- Attribute
Beispiele
Im folgenden Beispiel werden ein neuer Namespace und ein neues Attribut in der aktuellen Klasse erstellt und einige Eigenschaften des Attributs aufgelistet.
public void CreateClassAndAttrib(DTE2 applicationObject)
{
// Before running, load or create a project.
FileCodeModel2 fcm2 = GetFileCodeModel(applicationObject);
CodeAttribute2 cmAttribute;
CodeClass2 cmClass;
String msg = null;
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);
msg += "Attribute count: " +
cmAttribute.Collection.Count + Environment.NewLine;
msg += "Document name: " +
cmAttribute.DTE.ActiveDocument.Name;
}
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;
}
Hinweise
In Visual Studio ist der Stamm DTE des Automatisierungs Modells, das von anderen Objekt Modellen oft als "Application" bezeichnet wird.
Hinweis
Die Werte von Codemodellelementen wie z. B. Klassen, Strukturen, Funktionen, Attributen Delegaten usw. sind nach bestimmten Änderungen unter Umständen nicht deterministisch, d. h. deren Werte bleiben nicht zuverlässig immer gleich. Weitere Informationen finden Sie im Abschnitt Code Modell Element-Werte können sich in ermitteln von Code mithilfe des Code Modells (Visual Basic)ändern.