CodeAttribute2.IsCodeType 属性
获取是否可以从此对象中获取 CodeType 对象。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
ReadOnly Property IsCodeType As Boolean
bool IsCodeType { get; }
property bool IsCodeType {
bool get ();
}
abstract IsCodeType : bool
function get IsCodeType () : boolean
属性值
类型:System.Boolean
一个布尔值,如果可获取 CodeType 对象,则返回 true;否则返回 false。
备注
返回该代码元素是否为代码类型。 如果是,则可使用查询接口 (QI) 或将该代码元素强制转换为 CodeType 对象。 当 Kind 是下列 vsCMElement 值之一时为 true:vsCMElementClass、vsCMElementInterface、vsCMElementDelegate、vsCMElementStruct 或 vsCMElementEnum。
备注
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。
示例
下面的示例在当前类中创建一个新的命名空间和特性,并列出该特性的一些属性。
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 += "InfoLocation: " + cmAttribute.InfoLocation +
Environment.NewLine;
msg += "IsCodeType?: " + cmAttribute.IsCodeType +
Environment.NewLine;
msg += "Kind: " + cmAttribute.Kind +
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;
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。