1 //------------------------------------------------------------------------------
2 // <copyright file="PersistenceTypeAttribute.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.UI {
8     using System.Runtime.InteropServices;
9 
10     using System;
11     using System.ComponentModel;
12 
13     /// <devdoc>
14     ///     LiteralContentAttribute indicates whether the contents within a tag representing
15     ///     a custom/web control should be treated by Trident as a "literal/text" content.
16     ///     Web controls supporting complex properties (like Templates, etc.) typically
17     ///     mark themselves as "literals", thereby letting the designer infra-structure
18     ///     and Trident deal with the persistence of those attributes.
19     ///
20     ///     If LiteralContentAttribute.No is present or no LiteralContentAttribute marking
21     ///     exists, then the tag corresponding to the web control is not treated as a literal
22     ///     content tag.
23     ///     If LiteralContentAttribute.Yes is present, then the tag corresponding to the web
24     ///     control is treated as a literal content tag.
25     /// </devdoc>
26     [AttributeUsage(AttributeTargets.All)]
27     public sealed class PersistenceModeAttribute : Attribute {
28 
29 
30         /// <devdoc>
31         ///     This marks a property or event as persistable in the HTML tag as an attribute.
32         /// </devdoc>
33         public static readonly PersistenceModeAttribute Attribute = new PersistenceModeAttribute(PersistenceMode.Attribute);
34 
35 
36         /// <devdoc>
37         ///     This marks a property or event as persistable within the HTML tag as a nested tag.
38         /// </devdoc>
39         public static readonly PersistenceModeAttribute InnerProperty = new PersistenceModeAttribute(PersistenceMode.InnerProperty);
40 
41 
42         /// <devdoc>
43         ///     This marks a property or event as persistable within the HTML tag as a child.
44         /// </devdoc>
45         public static readonly PersistenceModeAttribute InnerDefaultProperty = new PersistenceModeAttribute(PersistenceMode.InnerDefaultProperty);
46 
47 
48         /// <devdoc>
49         ///     This marks a property or event as persistable within the HTML tag as a child.
50         /// </devdoc>
51         public static readonly PersistenceModeAttribute EncodedInnerDefaultProperty = new PersistenceModeAttribute(PersistenceMode.EncodedInnerDefaultProperty);
52 
53 
54 
55         /// <devdoc>
56         /// </devdoc>
57         public static readonly PersistenceModeAttribute Default = Attribute;
58 
59         private PersistenceMode mode = PersistenceMode.Attribute;
60 
61 
62 
63         /// <internalonly/>
PersistenceModeAttribute(PersistenceMode mode)64         public PersistenceModeAttribute(PersistenceMode mode) {
65             if (mode < PersistenceMode.Attribute || mode > PersistenceMode.EncodedInnerDefaultProperty) {
66                 throw new ArgumentOutOfRangeException("mode");
67             }
68             this.mode = mode;
69         }
70 
71 
72 
73         /// <devdoc>
74         /// </devdoc>
75         public PersistenceMode Mode {
76             get {
77                 return mode;
78             }
79         }
80 
81 
82         /// <internalonly/>
GetHashCode()83         public override int GetHashCode() {
84             return Mode.GetHashCode();
85         }
86 
87 
88         /// <devdoc>
89         /// </devdoc>
90         /// <internalonly/>
Equals(object obj)91         public override bool Equals(object obj) {
92             if (obj == this) {
93                 return true;
94             }
95             if ((obj != null) && (obj is PersistenceModeAttribute)) {
96                 return((PersistenceModeAttribute)obj).Mode == mode;
97             }
98 
99             return false;
100         }
101 
102 
103         /// <devdoc>
104         /// </devdoc>
105         /// <internalonly/>
IsDefaultAttribute()106         public override bool IsDefaultAttribute() {
107             return this.Equals(Default);
108         }
109     }
110 }
111