added samples
[windows-sources.git] / sdk / samples / WFSamples / Technologies / Markup / CustomSerialization / VB / CollectionActivities / StackSerializer.vb
blob857cf681603930ecc09b4c51be100c6a7956d515
1 '---------------------------------------------------------------------
2 ' This file is part of the Windows Workflow Foundation SDK Code Samples.
3 '
4 ' Copyright (C) Microsoft Corporation. All rights reserved.
5 '
6 'This source code is intended only as a supplement to Microsoft
7 'Development Tools and/or on-line documentation. See these other
8 'materials for detailed information regarding Microsoft code samples.
9 '
10 'THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
11 'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12 'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
13 'PARTICULAR PURPOSE.
14 '---------------------------------------------------------------------
17 Imports System
18 Imports System.Collections
19 Imports System.ComponentModel.Design.Serialization
20 Imports System.Workflow.ComponentModel.Serialization
21 Imports System.Runtime.InteropServices
23 <ComVisible(False)> _
24 Public Class StackSerializer
25 Inherits WorkflowMarkupSerializer
26 Implements IDesignerSerializationProvider
28 Protected Overrides Sub AddChild(ByVal serializationManager As WorkflowMarkupSerializationManager, ByVal parentObject As Object, ByVal childObject As Object)
30 If parentObject Is Nothing Then
31 Throw New ArgumentNullException("parentObject")
32 End If
34 If (childObject Is Nothing) Then
35 Throw New ArgumentNullException("childObject")
36 End If
38 Dim stack As Stack = TryCast(parentObject, Stack)
40 If stack Is Nothing Then
41 Throw New Exception(String.Format("The type of parentObject is not {0}", GetType(Stack).FullName))
42 End If
44 stack.Push(childObject)
45 End Sub
47 Protected Overrides Function GetChildren(ByVal serializationManager As WorkflowMarkupSerializationManager, ByVal obj As Object) As IList
49 If obj Is Nothing Then
50 Throw New ArgumentNullException("obj")
51 End If
53 Dim stack As Stack = TryCast(obj, Stack)
55 If stack Is Nothing Then
56 Throw New Exception(String.Format("The type of obj is not {0}", GetType(Stack).FullName))
57 End If
59 Dim arrayList As New ArrayList(stack.ToArray())
60 arrayList.Reverse()
62 Return arrayList
63 End Function
65 #Region "IDesignerSerializationProvider Members"
66 Public Function GetSerializer(ByVal manager As System.ComponentModel.Design.Serialization.IDesignerSerializationManager, ByVal currentSerializer As Object, ByVal objectType As System.Type, ByVal serializerType As System.Type) As Object Implements System.ComponentModel.Design.Serialization.IDesignerSerializationProvider.GetSerializer
67 If objectType Is GetType(Stack) Then
68 Return Me
69 Else
70 Return currentSerializer
71 End If
72 End Function
73 #End Region
75 End Class