CodeAttribute2.Arguments 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取 CodeElement 对象的集合,该集合包含 CodeAttributeArgument 与此特性关联的对象。
public:
property EnvDTE::CodeElements ^ Arguments { EnvDTE::CodeElements ^ get(); };
[System.Runtime.InteropServices.DispId(202)]
public EnvDTE.CodeElements Arguments { [System.Runtime.InteropServices.DispId(202)] get; }
[<System.Runtime.InteropServices.DispId(202)>]
[<get: System.Runtime.InteropServices.DispId(202)>]
member this.Arguments : EnvDTE.CodeElements
Public ReadOnly Property Arguments As CodeElements
属性值
CodeElement 对象的集合。
- 属性
示例
// The following example creates a new namespace and attribute in
// the current class and lists some of the attribute's properties.
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 += "Arguments: " + cmAttribute.Arguments +
Environment.NewLine;
msg += "Count: " + cmAttribute.Children.Count +
Environment.NewLine;
msg += "Endpoint Location: " +
cmAttribute.EndPoint.DisplayColumn +
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 Studio 2005 。
备注
在赋值后,代码属性参数值不会保留在内存中 Visual Studio ,因此,在对 code 特性参数进行后续更新时,可能会也可能无效。 也就是说,后续参数访问可能返回 E_FAIL 或完全不同的值。 但 (影响元素的子级的任何内容,则不会出现此问题。 )
由于这种不确定的行为,您应在更改之前检索参数的值。 例如,如果您在代码中设置了代码属性参数(如),则 myAttrArg.Value = """a first value""" 应在更新之前显式引用它(如),然后 myAttrArg = myAttr.Arguments.Item("first value") 分配新的值 myAttrArg.Value = """a second value""" 。 这样做可以确保更改正确的参数。
此外,在进行某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能是不确定的,这意味着无法依赖于它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。