CodeAttribute2.Target 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
设置或获取代码特性的目标。
public:
property System::String ^ Target { System::String ^ get(); void set(System::String ^ value); };
public:
property Platform::String ^ Target { Platform::String ^ get(); void set(Platform::String ^ value); };
[System.Runtime.InteropServices.DispId(200)]
public string Target { [System.Runtime.InteropServices.DispId(200)] get; [System.Runtime.InteropServices.DispId(200)] set; }
[<System.Runtime.InteropServices.DispId(200)>]
[<get: System.Runtime.InteropServices.DispId(200)>]
[<set: System.Runtime.InteropServices.DispId(200)>]
member this.Target : string with get, set
Public Property Target As String
属性值
表示代码特性目标的字符串。
- 属性
示例
下面的示例在当前类中创建新的命名空间和属性,并列出属性的一些属性。
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 += "Project Item Name: " +
cmAttribute.ProjectItem.Name + Environment.NewLine;
msg += "Startpoint DisplayColumn: " +
cmAttribute.StartPoint.DisplayColumn +
Environment.NewLine;
msg += "Target: " + cmAttribute.Target +
Environment.NewLine;
msg += "Value: " + cmAttribute.Value +
Environment.NewLine;
MessageBox.Show(msg);
}
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;
}
注解
备注
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。