ReferenceContext Class
When a ModelBusReference is serialized, the serialized string can be made relative to some context information such as a file path. When the string is deserialized, you can provide the same context or a different context. ReferenceContext is a dictionary that stores the context information. The set of keys and types stored in a context depend on the class of ModelBusAdapter that you use.
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.Modeling.Integration.ReferenceContext
Namespace: Microsoft.VisualStudio.Modeling.Integration
Assembly: Microsoft.VisualStudio.Modeling.Sdk.Integration.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.Integration.10.0.dll)
Syntax
'Declaración
Public Class ReferenceContext
public class ReferenceContext
public ref class ReferenceContext
type ReferenceContext = class end
public class ReferenceContext
The ReferenceContext type exposes the following members.
Constructors
Name | Description | |
---|---|---|
ReferenceContext |
Top
Methods
Name | Description | |
---|---|---|
Add | Associate a value with a particular key in the reference context. | |
Contains | Query whether the specified key has been associated with a value in this context | |
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Remove | Remove the association between the specified key and its value from the context, if any. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
TryGetValue<T> | Lookup the value associated with a specified key in the context. |
Top
Remarks
For Modelbus Adapters that use file paths, use the keys ModelBusReferencePropertySerializer.FilePathSaveContextKey and ModelBusReferencePropertySerializer.FilePathLoadContextKey to index folder names in the ReferenceContext.
For more information, see Integrating Models by using Visual Studio Modelbus.
Examples
To serialize relative to a path:
elementReference.ReferenceContext.Add(
ModelBusReferencePropertySerializer.FilePathSaveContextKey,
currentProjectFilePath);
string serialized = modelBus.SerializeReference(elementReference);
To retrieve the reference from the string:
ReferenceContext context = new ReferenceContext();
context.Add(ModelBusReferencePropertySerializer.FilePathLoadContextKey,
currentProjectFilePath);
ModelBusReference elementReferenceRestored =
modelBus.DeserializeReference(serialized, context);
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.