Partager via


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.

Namespace:   Microsoft.VisualStudio.Modeling.Integration
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.Integration.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.Integration.12.0.dll)

Inheritance Hierarchy

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

Syntax

public class ReferenceContext
public ref class ReferenceContext 
type ReferenceContext = class end
Public Class ReferenceContext

Constructors

Name Description
System_CAPS_pubmethod ReferenceContext()

Methods

Name Description
System_CAPS_pubmethod Add(Object, Object)

Associate a value with a particular key in the reference context.

System_CAPS_pubmethod Contains(Object)

Query whether the specified key has been associated with a value in this context

System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethod Remove(Object)

Remove the association between the specified key and its value from the context, if any.

System_CAPS_pubmethod ToString()

(Inherited from Object.)

System_CAPS_pubmethod TryGetValue<T>(Object, T)

Lookup the value associated with a specified key in the context.

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.

See Also

Microsoft.VisualStudio.Modeling.Integration Namespace

Return to top