Gets a context object that can help you write and read various values.
Namespace: MindFusion.Scheduling
Assembly: MindFusion.Scheduling
Syntax
Example
The following example demonstrates how to use the Context object in order to write and read complex tag values in the XML document.
C#
Copy Code
|
---|
class MyTag { public MyTag(int intValue, string stringValue) { IntValue = intValue; StringValue = stringValue; }
public int IntValue; public string StringValue; }
// ...
private void OnSerializeTag(object sender, SerializeTagEventArgs e) { if (e.Tag is MyTag) { e.Handled = true; e.Context.WriteBool(true, "mytag", e.Representation);
MyTag tag = e.Tag as MyTag; e.Context.WriteInt(tag.IntValue, "intValue", e.Representation); e.Context.WriteString(tag.StringValue, "stringValue", e.Representation); } }
private void OnDeserializeTag(object sender, SerializeTagEventArgs e) { if (e.Context.ReadBool("mytag", e.Representation, false)) { e.Handled = true;
int intValue = e.Context.ReadInt("intValue", e.Representation); string stringValue = e.Context.ReadString("stringValue", e.Representation);
e.Tag = new MyTag(intValue, stringValue); } } |
Visual Basic
Copy Code
|
---|
Class MyTag
Public Sub New(ByVal intValue As Integer, ByVal stringValue As String)
IntValue = intValue; StringValue = stringValue;
End Sub
Public IntValue As Integer Public StringValue As String
End Class
Private Sub OnSerializeTag(ByVal sender As Object, ByVal e As SerializeTagEventArgs)
If TypeOf e.Tag Is MyTag Then
e.Handled = True e.Context.WriteBool(True, "mytag", e.Representation)
Dim tag As MyTag = CType(e.Tag, MyTag) e.Context.WriteInt(tag.IntValue, "intValue", e.Representation) e.Context.WriteString(tag.StringValue, "stringValue", e.Representation)
End If
End Sub
Private Sub OnDeserializeTag(ByVal sender As Object, ByVal e As SerializeTagEventArgs)
If e.Context.ReadBool("mytag", e.Representation, False) Then
e.Handled = True
Dim intValue As Integer = e.Context.ReadInt("intValue", e.Representation) Dim stringValue As String = e.Context.ReadString("stringValue", e.Representation)
e.Tag = New MyTag(intValue, stringValue)
End If
End Sub |
See Also