mscorlib(4.0.0.0) API with additions
NamedPermissionSet.cs
4 using System.Threading;
5 
6 namespace System.Security
7 {
10  [ComVisible(true)]
11  public sealed class NamedPermissionSet : PermissionSet
12  {
13  private string m_name;
14 
15  private string m_description;
16 
17  [OptionalField(VersionAdded = 2)]
18  internal string m_descrResource;
19 
20  private static object s_InternalSyncObject;
21 
25  public string Name
26  {
27  get
28  {
29  return m_name;
30  }
31  set
32  {
33  CheckName(value);
34  m_name = value;
35  }
36  }
37 
40  public string Description
41  {
42  get
43  {
44  if (m_descrResource != null)
45  {
46  m_description = Environment.GetResourceString(m_descrResource);
47  m_descrResource = null;
48  }
49  return m_description;
50  }
51  set
52  {
53  m_description = value;
54  m_descrResource = null;
55  }
56  }
57 
58  private static object InternalSyncObject
59  {
60  get
61  {
62  if (s_InternalSyncObject == null)
63  {
64  object value = new object();
65  Interlocked.CompareExchange(ref s_InternalSyncObject, value, null);
66  }
67  return s_InternalSyncObject;
68  }
69  }
70 
71  internal NamedPermissionSet()
72  {
73  }
74 
78  public NamedPermissionSet(string name)
79  {
80  CheckName(name);
81  m_name = name;
82  }
83 
88  public NamedPermissionSet(string name, PermissionState state)
89  : base(state)
90  {
91  CheckName(name);
92  m_name = name;
93  }
94 
99  public NamedPermissionSet(string name, PermissionSet permSet)
100  : base(permSet)
101  {
102  CheckName(name);
103  m_name = name;
104  }
105 
109  : base(permSet)
110  {
111  m_name = permSet.m_name;
112  m_description = permSet.Description;
113  }
114 
115  internal NamedPermissionSet(SecurityElement permissionSetXml)
116  : base(PermissionState.None)
117  {
118  FromXml(permissionSetXml);
119  }
120 
121  private static void CheckName(string name)
122  {
123  if (name == null || name.Equals(""))
124  {
125  throw new ArgumentException(Environment.GetResourceString("Argument_NPMSInvalidName"));
126  }
127  }
128 
131  public override PermissionSet Copy()
132  {
133  return new NamedPermissionSet(this);
134  }
135 
140  public NamedPermissionSet Copy(string name)
141  {
142  NamedPermissionSet namedPermissionSet = new NamedPermissionSet(this);
143  namedPermissionSet.Name = name;
144  return namedPermissionSet;
145  }
146 
149  public override SecurityElement ToXml()
150  {
151  SecurityElement securityElement = ToXml("System.Security.NamedPermissionSet");
152  if (m_name != null && !m_name.Equals(""))
153  {
154  securityElement.AddAttribute("Name", SecurityElement.Escape(m_name));
155  }
156  if (Description != null && !Description.Equals(""))
157  {
158  securityElement.AddAttribute("Description", SecurityElement.Escape(Description));
159  }
160  return securityElement;
161  }
162 
167  public override void FromXml(SecurityElement et)
168  {
169  FromXml(et, allowInternalOnly: false, ignoreTypeLoadFailures: false);
170  }
171 
172  internal override void FromXml(SecurityElement et, bool allowInternalOnly, bool ignoreTypeLoadFailures)
173  {
174  if (et == null)
175  {
176  throw new ArgumentNullException("et");
177  }
178  string text = et.Attribute("Name");
179  m_name = ((text == null) ? null : text);
180  text = et.Attribute("Description");
181  m_description = ((text == null) ? "" : text);
182  m_descrResource = null;
183  base.FromXml(et, allowInternalOnly, ignoreTypeLoadFailures);
184  }
185 
186  internal void FromXmlNameOnly(SecurityElement et)
187  {
188  string text = et.Attribute("Name");
189  m_name = ((text == null) ? null : text);
190  }
191 
196  [ComVisible(false)]
197  public override bool Equals(object obj)
198  {
199  return base.Equals(obj);
200  }
201 
204  [ComVisible(false)]
205  public override int GetHashCode()
206  {
207  return base.GetHashCode();
208  }
209  }
210 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
NamedPermissionSet(string name, PermissionSet permSet)
Initializes a new instance of the T:System.Security.NamedPermissionSet class with the specified name ...
Definition: __Canon.cs:3
string Name
Gets or sets the name of the current named permission set.
override void FromXml(SecurityElement et)
Reconstructs a named permission set with a specified state from an XML encoding.
Use none of the security policy components.
NamedPermissionSet(string name, PermissionState state)
Initializes a new instance of the T:System.Security.NamedPermissionSet class with the specified name ...
static string Escape(string str)
Replaces invalid XML characters in a string with their valid XML equivalent.
Defines a permission set that has a name and description associated with it. This class cannot be inh...
NamedPermissionSet(string name)
Initializes a new, empty instance of the T:System.Security.NamedPermissionSet class with the specifie...
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a collection that can contain many different types of permissions.
Represents the XML object model for encoding security objects. This class cannot be inherited.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
override int GetHashCode()
Gets a hash code for the T:System.Security.NamedPermissionSet object that is suitable for use in hash...
override PermissionSet Copy()
Creates a permission set copy from a named permission set.
NamedPermissionSet(NamedPermissionSet permSet)
Initializes a new instance of the T:System.Security.NamedPermissionSet class from another named permi...
The exception that is thrown when one of the arguments provided to a method is not valid.
override bool Equals(object obj)
Determines whether the specified T:System.Security.NamedPermissionSet object is equal to the current ...
override SecurityElement ToXml()
Creates an XML element description of the named permission set.
NamedPermissionSet Copy(string name)
Creates a copy of the named permission set with a different name but the same permissions.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
string Description
Gets or sets the text description of the current named permission set.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10