ca4eef79adf9589933c5a1129fdc9caf11767bba
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Annotations / Annotation.cs
1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //----------------------------------------------------------------
6
7 namespace System.Activities.Presentation.Annotations
8 {
9     using System.Diagnostics.CodeAnalysis;
10     using System.Runtime;
11     using System.Xaml;
12
13     /// <summary>
14     /// Annotation class that contains methods to access annotation attached property
15     /// </summary>
16     public static class Annotation
17     {
18         /// <summary>
19         /// attachable property for annotation text
20         /// </summary>
21         [SuppressMessage(FxCop.Category.Security, FxCop.Rule.DoNotDeclareReadOnlyMutableReferenceTypes, Justification = "XAML attached property declaration.")]
22         public static readonly AttachableMemberIdentifier AnnotationTextProperty = new AttachableMemberIdentifier(typeof(Annotation), "AnnotationText");
23
24         /// <summary>
25         /// property name to access annotation in a ModelItem
26         /// </summary>
27         public static readonly string AnnotationTextPropertyName = "AnnotationText";
28
29         /// <summary>
30         /// property name to access dock annoation view state
31         /// </summary>
32         internal static readonly string IsAnnotationDockedViewStateName = "IsAnnotationDocked";
33
34         /// <summary>
35         /// Get annotation text of an object
36         /// </summary>
37         /// <param name="instance">instance to get annotation</param>
38         /// <returns>annoation text</returns>
39         public static string GetAnnotationText(object instance)
40         {
41             if (instance == null)
42             {
43                 throw FxTrace.Exception.AsError(new ArgumentNullException("instance"));
44             }
45
46             string annotationText;
47             AttachablePropertyServices.TryGetProperty<string>(instance, Annotation.AnnotationTextProperty, out annotationText);
48             return annotationText;
49         }
50
51         /// <summary>
52         /// Set annotation of an object
53         /// </summary>
54         /// <param name="instance">instance to set annotation text</param>
55         /// <param name="annotationText">annoatation text to be set</param>
56         public static void SetAnnotationText(object instance, string annotationText)
57         {
58             if (instance == null)
59             {
60                 throw FxTrace.Exception.AsError(new ArgumentNullException("instance"));
61             }
62
63             if (annotationText != null)
64             {
65                 AttachablePropertyServices.SetProperty(instance, Annotation.AnnotationTextProperty, annotationText);
66             }
67             else
68             {
69                 AttachablePropertyServices.RemoveProperty(instance, Annotation.AnnotationTextProperty);
70             }
71         }
72     }
73 }