CSharpTest.Net
SetContext Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Serialization Namespace > Storage Class : SetContext Method

contextPath
The full context path to change to

Glossary Item Box

Replaces the context path of the storage, dispose of the returned IDisposable to restore the Storage's previous ContextPath.

Syntax

Visual Basic (Declaration) 
Public Function SetContext( _
   ByVal contextPath As String _
) As IDisposable
C# 
public IDisposable SetContext( 
   string contextPath
)

Parameters

contextPath
The full context path to change to

Return Value

Context can be disposed to restore the previous state

Example

Library/Library.Test/TestStorage.cs

C#Copy Code
Assert.IsNull(Store.ContextPath);

using (Store.SetContext("a"))
{
    Assert.AreEqual("a", Store.ContextPath);
    using (Store.SetContext("b"))
        Assert.AreEqual("b", Store.ContextPath);
    Assert.AreEqual("a", Store.ContextPath);
}

Assert.IsNull(Store.ContextPath);

using (Store.SetContext("a"))
{
    Assert.AreEqual("a", Store.ContextPath);
    Store.SetContext("b");
    Assert.AreEqual("b", Store.ContextPath);
}

Assert.IsNull(Store.ContextPath);
VB.NETCopy Code
Assert.IsNull(Store.ContextPath)

Using Store.SetContext("a")
    Assert.AreEqual("a", Store.ContextPath)
    Using Store.SetContext("b")
        Assert.AreEqual("b", Store.ContextPath)
    End Using
    Assert.AreEqual("a", Store.ContextPath)
End Using

Assert.IsNull(Store.ContextPath)

Using Store.SetContext("a")
    Assert.AreEqual("a", Store.ContextPath)
    Store.SetContext("b")
    Assert.AreEqual("b", Store.ContextPath)
End Using

Assert.IsNull(Store.ContextPath)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys