mscorlib(4.0.0.0) API with additions
StorePermission.cs
2 
4 {
8  {
9  private StorePermissionFlags m_flags;
10 
15  {
16  get
17  {
18  return m_flags;
19  }
20  set
21  {
22  VerifyFlags(value);
23  m_flags = value;
24  }
25  }
26 
32  {
33  switch (state)
34  {
35  case PermissionState.Unrestricted:
36  m_flags = StorePermissionFlags.AllFlags;
37  break;
38  case PermissionState.None:
39  m_flags = StorePermissionFlags.NoFlags;
40  break;
41  default:
42  throw new ArgumentException(SR.GetString("Argument_InvalidPermissionState"));
43  }
44  }
45 
51  {
52  VerifyFlags(flag);
53  m_flags = flag;
54  }
55 
59  public bool IsUnrestricted()
60  {
61  return m_flags == StorePermissionFlags.AllFlags;
62  }
63 
69  public override IPermission Union(IPermission target)
70  {
71  if (target == null)
72  {
73  return Copy();
74  }
75  try
76  {
77  StorePermission storePermission = (StorePermission)target;
78  StorePermissionFlags storePermissionFlags = m_flags | storePermission.m_flags;
79  if (storePermissionFlags == StorePermissionFlags.NoFlags)
80  {
81  return null;
82  }
83  return new StorePermission(storePermissionFlags);
84  }
85  catch (InvalidCastException)
86  {
87  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Argument_WrongType"), new object[1]
88  {
89  GetType().FullName
90  }));
91  }
92  }
93 
100  public override bool IsSubsetOf(IPermission target)
101  {
102  if (target == null)
103  {
104  return m_flags == StorePermissionFlags.NoFlags;
105  }
106  try
107  {
108  StorePermission storePermission = (StorePermission)target;
109  StorePermissionFlags flags = m_flags;
110  StorePermissionFlags flags2 = storePermission.m_flags;
111  return (flags & flags2) == flags;
112  }
113  catch (InvalidCastException)
114  {
115  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Argument_WrongType"), new object[1]
116  {
117  GetType().FullName
118  }));
119  }
120  }
121 
127  public override IPermission Intersect(IPermission target)
128  {
129  if (target == null)
130  {
131  return null;
132  }
133  try
134  {
135  StorePermission storePermission = (StorePermission)target;
136  StorePermissionFlags storePermissionFlags = storePermission.m_flags & m_flags;
137  if (storePermissionFlags == StorePermissionFlags.NoFlags)
138  {
139  return null;
140  }
141  return new StorePermission(storePermissionFlags);
142  }
143  catch (InvalidCastException)
144  {
145  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Argument_WrongType"), new object[1]
146  {
147  GetType().FullName
148  }));
149  }
150  }
151 
154  public override IPermission Copy()
155  {
156  return new StorePermission(m_flags);
157  }
158 
161  public override SecurityElement ToXml()
162  {
163  SecurityElement securityElement = new SecurityElement("IPermission");
164  securityElement.AddAttribute("class", GetType().FullName + ", " + GetType().Module.Assembly.FullName.Replace('"', '\''));
165  securityElement.AddAttribute("version", "1");
166  if (!IsUnrestricted())
167  {
168  securityElement.AddAttribute("Flags", m_flags.ToString());
169  }
170  else
171  {
172  securityElement.AddAttribute("Unrestricted", "true");
173  }
174  return securityElement;
175  }
176 
183  public override void FromXml(SecurityElement securityElement)
184  {
185  if (securityElement == null)
186  {
187  throw new ArgumentNullException("securityElement");
188  }
189  string text = securityElement.Attribute("class");
190  if (text == null || text.IndexOf(GetType().FullName, StringComparison.Ordinal) == -1)
191  {
192  throw new ArgumentException(SR.GetString("Argument_InvalidClassAttribute"), "securityElement");
193  }
194  string text2 = securityElement.Attribute("Unrestricted");
195  if (text2 != null && string.Compare(text2, "true", StringComparison.OrdinalIgnoreCase) == 0)
196  {
197  m_flags = StorePermissionFlags.AllFlags;
198  return;
199  }
200  m_flags = StorePermissionFlags.NoFlags;
201  string text3 = securityElement.Attribute("Flags");
202  if (text3 != null)
203  {
205  VerifyFlags(flags);
206  m_flags = flags;
207  }
208  }
209 
210  internal static void VerifyFlags(StorePermissionFlags flags)
211  {
212  if ((flags & ~(StorePermissionFlags.CreateStore | StorePermissionFlags.DeleteStore | StorePermissionFlags.EnumerateStores | StorePermissionFlags.OpenStore | StorePermissionFlags.AddToStore | StorePermissionFlags.RemoveFromStore | StorePermissionFlags.EnumerateCertificates)) != 0)
213  {
214  throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Arg_EnumIllegalVal"), new object[1]
215  {
216  (int)flags
217  }));
218  }
219  }
220  }
221 }
Allows a permission to expose an unrestricted state.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override bool IsSubsetOf(IPermission target)
Determines whether the current permission is a subset of the specified permission.
StorePermission(PermissionState state)
Initializes a new instance of the T:System.Security.Permissions.StorePermission class with either ful...
override IPermission Intersect(IPermission target)
Creates and returns a permission that is the intersection of the current permission and the specified...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
bool IsUnrestricted()
Returns a value indicating whether the current permission is unrestricted.
Definition: __Canon.cs:3
The exception that is thrown for invalid casting or explicit conversion.
override void FromXml(SecurityElement securityElement)
Reconstructs a permission with a specified state from an XML encoding.
static object Parse(Type enumType, string value)
Converts the string representation of the name or numeric value of one or more enumerated constants t...
Definition: Enum.cs:298
Provides the base class for enumerations.
Definition: Enum.cs:14
Represents the XML object model for encoding security objects. This class cannot be inherited.
Controls access to stores containing X.509 certificates. This class cannot be inherited.
Defines the underlying structure of all code access permissions.
StorePermissionFlags Flags
Gets or sets the type of T:System.Security.Cryptography.X509Certificates.X509Store access allowed by ...
Defines methods implemented by permission types.
Definition: IPermission.cs:7
StorePermissionFlags
Specifies the permitted access to X.509 certificate stores.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when one of the arguments provided to a method is not valid.
Attribute can be applied to a module.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
StorePermission(StorePermissionFlags flag)
Initializes a new instance of the T:System.Security.Permissions.StorePermission class with the specif...
override SecurityElement ToXml()
Creates an XML encoding of the permission and its current state.
Specifies that the class can be serialized.
override IPermission Copy()
Creates and returns an identical copy of the current permission.
override IPermission Union(IPermission target)
Creates a permission that is the union of the current permission and the specified permission.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16