[reflection] Coop handles icalls in System.Reflection and System.RuntimeTypeHandle...
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / State / PropertyStateContainer.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing 
5 {
6     using System;
7     using System.Collections.Generic;
8     using System.Diagnostics;
9     using System.Text;
10
11     using System.Activities.Presentation.Internal.PropertyEditing.State;
12
13     // <summary>
14     // Simple wrapper around a dictionary of PropertyStates keyed by the property names.
15     // </summary>
16     internal class PropertyStateContainer : PersistedStateContainer 
17     {
18
19         private static PropertyStateContainer _instance;
20
21         // The ctor is private because we use this class as a singleton
22         private PropertyStateContainer() 
23         {
24         }
25
26         // <summary>
27         // Gets a static instance of this class
28         // </summary>
29         public static PropertyStateContainer Instance 
30         {
31             get {
32                 if (_instance == null)
33                 {
34                     _instance = new PropertyStateContainer();
35                 }
36
37                 return _instance;
38             }
39         }
40
41         // <summary>
42         // Gets the PropertyState for the specified category.  If one does not exist
43         // yet, it will be created automatically, guaranteeing a non-null return value.
44         // </summary>
45         // <param name="propertyName">Name of the property itself</param>
46         // <returns>A non-null instance of PropertyState</returns>
47         public PropertyState GetPropertyState(string propertyName) 
48         {
49             return (PropertyState)this.GetState(propertyName);
50         }
51
52         // <summary>
53         // Creates a default state object based on the specified key
54         // </summary>
55         // <param name="key">Key of the state object</param>
56         // <returns>Default state object</returns>
57         protected override PersistedState CreateDefaultState(object key) 
58         {
59             return new PropertyState(key as string);
60         }
61
62         // <summary>
63         // Deserializes the specified string value into a state object
64         // </summary>
65         // <param name="serializedValue">Serialized value of the state object</param>
66         // <returns>Deserialized instance of the state object</returns>
67         protected override PersistedState DeserializeState(string serializedValue) 
68         {
69             return PropertyState.Deserialize(serializedValue);
70         }
71     }
72 }