ReferenceContext 类

在序列化 ModelBusReference 时,可相对某些上下文信息对字符串进行序列化。 当字符串进行反序列化时,可以提供相同上下文或不同的上下文。 ReferenceContext 是存储上下文信息的字典。 在上下文已存储的密钥和类型的集合取决于所使用 ModelBusAdapter 的类。

继承层次结构

System.Object
  Microsoft.VisualStudio.Modeling.Integration.ReferenceContext

命名空间:  Microsoft.VisualStudio.Modeling.Integration
程序集:  Microsoft.VisualStudio.Modeling.Sdk.Integration.12.0(在 Microsoft.VisualStudio.Modeling.Sdk.Integration.12.0.dll 中)

语法

声明
Public Class ReferenceContext
public class ReferenceContext

ReferenceContext 类型公开以下成员。

构造函数

  名称 说明
公共方法 ReferenceContext

页首

方法

  名称 说明
公共方法 Add 一个值与引用上下文中特定的密匙关联。
公共方法 Contains 询问该指定的键值是否与该上下文中的某个值关联
公共方法 Equals 确定指定的对象是否等于当前对象。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
公共方法 GetHashCode 作为默认哈希函数。 (继承自 Object。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法 Remove 从上下文移除该关联(在指定的键和它的值之间),如果有的话。
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)
公共方法 TryGetValue<T> 查找与上下文中指定的键相关联的值。

页首

备注

对于使用文件路径的 Modelbus 适配器,请使用 ModelBusReferencePropertySerializer.FilePathSaveContextKey 键和索引。ModelBusReferencePropertySerializer.FilePathLoadContextKey ReferenceContext 的文件夹名称。

有关详细信息,请参阅使用 Visual Studio Modelbus 集成模型

示例

序列化相对路径:

elementReference.ReferenceContext.Add(
   ModelBusReferencePropertySerializer.FilePathSaveContextKey, 
   currentProjectFilePath);
string serialized = modelBus.SerializeReference(elementReference);

从字符串中索引引用:

ReferenceContext context = new ReferenceContext();
context.Add(ModelBusReferencePropertySerializer.FilePathLoadContextKey,
    currentProjectFilePath);
ModelBusReference elementReferenceRestored =
    modelBus.DeserializeReference(serialized, context);

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参阅

参考

Microsoft.VisualStudio.Modeling.Integration 命名空间