Registers a schedule item class for serialization support.
Namespace: MindFusion.Scheduling
Assembly: MindFusion.Scheduling.Wpf
Syntax
C#
Copy Code
|
---|
public static void RegisterItemClass ( Type itemClass, string classId, int classVersion ) |
Visual Basic
Copy Code
|
---|
Public Shared Sub RegisterItemClass( _ itemClass As Type, _ classId As String, _ classVersion As Integer _ ) |
Parameters
Example
The following example demonstrates how to use custom item classes with the schedule and how to load and save a schedule containing custom items. The example presumes that schedule already references an existing Schedule object.
Running the example should dump the following line to the output console:
Hello, friend!
C#
Copy Code
|
---|
/// <summary> /// The declaration of the custom item class. /// </summary> class CustomItem : Appointment { /// <summary> /// The parameterless constructor, required by the Schedule. /// </summary> public CustomItem() { _customField = "This is my field."; }
public override void LoadFrom( System.Xml.XmlReader reader, SerializationContext context) { // Don't forget to invoke LoadFrom on the base class base.LoadFrom(reader, context);
_customField = reader.ReadElementString("customField"); }
public override void SaveTo( System.Xml.XmlWriter writer, SerializationContext context) { base.SaveTo(writer, context);
writer.WriteElementString("customField", _customField); }
public string CustomField { get { return _customField; } set { _customField = value; } }
private string _customField; }
// ...
// Register our custom item class for use with the schedule Schedule.RegisterItemClass(typeof(CustomItem), "customItemId", 1);
// Create a new custom item and add it to the schedule CustomItem customItem = new CustomItem(); customItem.CustomField = "Hello, friend!"; schedule.Items.Add(customItem);
// Save the schedule to a file. // Make sure the specified path exists on your drive schedule.SaveTo(@"c:\schedule.save");
// Clear the schedule schedule.Items.Clear();
// Load the previously saved schedule data schedule.LoadFrom(@"c:\schedule.save");
// Test the data foreach (Item item in schedule.Items) { if (item is CustomItem) { System.Diagnostics.Debug.WriteLine( (item as CustomItem).CustomField); } } |
Visual Basic
Copy Code
|
---|
' <summary> ' The declaration of the custom item class. ' </summary> Class CustomItem Inherits Appointment
' <summary> ' The parameterless constructor, required by the Schedule. ' </summary> Public Sub New()
_customField = "This is my field."
End Sub
Public Overloads Overrides Sub LoadFrom( _ ByVal reader As System.Xml.XmlReader, _ ByVal context As SerializationContext)
' Don't forget to invoke LoadFrom on the base class MyBase.LoadFrom(reader, context)
_customField = reader.ReadElementString("customField")
End Sub
Public Overloads Overrides Sub SaveTo( _ ByVal writer As System.Xml.XmlWriter, _ ByVal context As SerializationContext)
MyBase.SaveTo(writer, context)
writer.WriteElementString("customField", _customField)
End Sub
Public Property CustomField() As String
Get Return _customField End Get
Set(ByVal Value As String) _customField = Value End Set
End Property
Private _customField As String
End Class
' ...
' Register our custom item class for use with the schedule schedule.RegisterItemClass(GetType(CustomItem), "customItemId", 1)
' Create a new custom item and add it to the schedule Dim customItem As New CustomItem customItem.CustomField = "Hello, friend!" schedule.Items.Add(customItem)
' Save the schedule to a file. ' Make sure the specified path exists on your drive schedule.SaveTo("c:\schedule.save")
' Clear the schedule schedule.Items.Clear()
' Load the previously saved schedule data schedule.LoadFrom("c:\schedule.save")
' Test the data Dim item As Item For Each item In schedule.Items
If TypeOf item Is CustomItem Then
System.Diagnostics.Debug.WriteLine( _ CType(item, CustomItem).CustomField)
End If
Next item |
See Also