9e02f9b45f7d0bc2f60dc7fa6c022ae4da1c28ec
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / ViewState / WorkflowViewState.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.ViewState
8 {
9     using System.Diagnostics.CodeAnalysis;
10     using System.Runtime;
11     using System.Xaml;
12
13     /// <summary>
14     /// Class defining ViewStateManager and ViewStateId attached properties.
15     /// </summary>
16     public static class WorkflowViewState
17     {
18         /// <summary>
19         /// Attachable property for ViewStateManager
20         /// </summary>
21         [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes, Justification = "XAML attached property declaration.")]
22         public static readonly AttachableMemberIdentifier ViewStateManagerProperty = new AttachableMemberIdentifier(typeof(WorkflowViewState), "ViewStateManager");
23
24         /// <summary>
25         /// Attachable property for IdRef
26         /// </summary>
27         [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes, Justification = "XAML attached property declaration.")]
28         public static readonly AttachableMemberIdentifier IdRefProperty = new AttachableMemberIdentifier(typeof(WorkflowViewState), "IdRef");
29
30         /// <summary>
31         /// Set ViewStateManager as an attached property on an object. This method is for XAML serialization purpose only and is not expected to be used by developers.
32         /// </summary>
33         /// <param name="instance">Instance object to attach ViewStateManager property on</param>
34         /// <param name="viewStateManager">ViewStateManager object to attach</param>
35         public static void SetViewStateManager(object instance, ViewStateManager viewStateManager)
36         {
37             AttachablePropertyServices.SetProperty(instance, ViewStateManagerProperty, viewStateManager);
38         }
39
40         /// <summary>
41         /// Get ViewStateManager attached property value from an object if set
42         /// </summary>
43         /// <param name="instance">Instance object to retrieve ViewStateManager attached property from</param>
44         /// <returns>ViewStateManager object if set; null otherise</returns>
45         public static ViewStateManager GetViewStateManager(object instance)
46         {
47             ViewStateManager viewStateManager;
48             if (AttachablePropertyServices.TryGetProperty(instance, ViewStateManagerProperty, out viewStateManager))
49             {
50                 return viewStateManager;
51             }
52
53             return null;
54         }
55
56         /// <summary>
57         /// Set IdRef as an attached property on an object. This method is for XAML serialization purpose only and is not expected to be used by developers.
58         /// </summary>
59         /// <param name="instance">Instance object to attach IdRef property on</param>
60         /// <param name="idRef">refId value to attach</param>
61         public static void SetIdRef(object instance, string idRef)
62         {
63             AttachablePropertyServices.SetProperty(instance, IdRefProperty, idRef);
64         }
65
66         /// <summary>
67         /// Get RefId attached property value from an object if set
68         /// </summary>
69         /// <param name="instance">Instance object to retrieve RefId attached property from</param>
70         /// <returns>RefId value if set; null otherise</returns>
71         public static string GetIdRef(object instance)
72         {
73             string idRef;
74             if (AttachablePropertyServices.TryGetProperty(instance, IdRefProperty, out idRef))
75             {
76                 return idRef;
77             }
78
79             return null;
80         }
81     }
82 }