CodeAttribute2 接口
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义代码元素的特性。
public interface class CodeAttribute2 : EnvDTE::CodeAttribute
public interface class CodeAttribute2 : EnvDTE::CodeAttribute
__interface CodeAttribute2 : EnvDTE::CodeAttribute
[System.Runtime.InteropServices.Guid("35187E2A-E5F6-4F89-A4CE-DA254640855B")]
[System.Runtime.InteropServices.TypeLibType(4160)]
public interface CodeAttribute2 : EnvDTE.CodeAttribute
[<System.Runtime.InteropServices.Guid("35187E2A-E5F6-4F89-A4CE-DA254640855B")>]
[<System.Runtime.InteropServices.TypeLibType(4160)>]
type CodeAttribute2 = interface
interface CodeAttribute
Public Interface CodeAttribute2
Implements CodeAttribute
- 属性
- 实现
示例
// 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;
}
注解
CodeAttribute2对象表示与代码元素关联的单个 COM 元数据特性。 您可以使用方法添加新属性 AddAttribute ,并通过 Delete 在相应的对象上使用方法来删除属性。 您可以使用此对象获取和设置代码特性的值。
备注
在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。
属性
| Arguments |
获取 CodeElement 对象的集合,该集合包含 CodeAttributeArgument 与此特性关联的对象。 |
| Children |
获取此代码构造中包含的对象的集合。 |
| Collection |
获取 CodeAttribute2 对象的集合。 |
| DTE |
获取顶级扩展性对象。 |
| EndPoint |
获取表示代码特性的结束位置的编辑点。 |
| Extender[String] |
如果请求的 |
| ExtenderCATID |
获取对象的扩展程序类别 ID (CATID)。 |
| ExtenderNames |
获取对象的可用扩展程序的名称列表。 |
| FullName |
获取对象文件的完整路径和名称。 |
| InfoLocation |
获取代码模型。 |
| IsCodeType |
获取一个, CodeType 该值指示是否可以从此对象中获取对象。 |
| Kind |
获取一个指示特性类型的枚举。 |
| Language |
获取标识用于创作特性的编程语言的常数。 |
| Name |
设置或获取代码特性的名称。 |
| Parent |
获取代码特性的直接父对象。 |
| ProjectItem |
获取 ProjectItem 与代码属性关联的。 |
| StartPoint |
获取一个 TextPoint ,它定义属性的开头。 |
| Target |
设置或获取代码特性的目标。 |
| Value |
设置或获取代码特性的数据。 |
方法
| AddArgument(String, Object, Object) |
向特性添加参数。 |
| Delete() |
删除代码元素中的所有特性。 |
| GetEndPoint(vsCMPart) |
返回一个 TextPoint 对象,该对象标记属性的结束位置。 |
| GetStartPoint(vsCMPart) |
返回一个 TextPoint 对象,该对象定义特性的开始位置。 |