mscorlib(4.0.0.0) API with additions
DnsPermission.cs
1 using System.Security;
3 
4 namespace System.Net
5 {
9  {
10  private bool m_noRestriction;
11 
17  {
18  m_noRestriction = (state == PermissionState.Unrestricted);
19  }
20 
21  internal DnsPermission(bool free)
22  {
23  m_noRestriction = free;
24  }
25 
29  public bool IsUnrestricted()
30  {
31  return m_noRestriction;
32  }
33 
36  public override IPermission Copy()
37  {
38  return new DnsPermission(m_noRestriction);
39  }
40 
46  public override IPermission Union(IPermission target)
47  {
48  if (target == null)
49  {
50  return Copy();
51  }
52  DnsPermission dnsPermission = target as DnsPermission;
53  if (dnsPermission == null)
54  {
55  throw new ArgumentException(SR.GetString("net_perm_target"), "target");
56  }
57  return new DnsPermission(m_noRestriction || dnsPermission.m_noRestriction);
58  }
59 
65  public override IPermission Intersect(IPermission target)
66  {
67  if (target == null)
68  {
69  return null;
70  }
71  DnsPermission dnsPermission = target as DnsPermission;
72  if (dnsPermission == null)
73  {
74  throw new ArgumentException(SR.GetString("net_perm_target"), "target");
75  }
76  if (m_noRestriction && dnsPermission.m_noRestriction)
77  {
78  return new DnsPermission(free: true);
79  }
80  return null;
81  }
82 
89  public override bool IsSubsetOf(IPermission target)
90  {
91  if (target == null)
92  {
93  return !m_noRestriction;
94  }
95  DnsPermission dnsPermission = target as DnsPermission;
96  if (dnsPermission == null)
97  {
98  throw new ArgumentException(SR.GetString("net_perm_target"), "target");
99  }
100  if (m_noRestriction)
101  {
102  return dnsPermission.m_noRestriction;
103  }
104  return true;
105  }
106 
113  public override void FromXml(SecurityElement securityElement)
114  {
115  if (securityElement == null)
116  {
117  throw new ArgumentNullException("securityElement");
118  }
119  if (!securityElement.Tag.Equals("IPermission"))
120  {
121  throw new ArgumentException(SR.GetString("net_no_classname"), "securityElement");
122  }
123  string text = securityElement.Attribute("class");
124  if (text == null)
125  {
126  throw new ArgumentException(SR.GetString("net_no_classname"), "securityElement");
127  }
128  if (text.IndexOf(GetType().FullName) < 0)
129  {
130  throw new ArgumentException(SR.GetString("net_no_typename"), "securityElement");
131  }
132  string text2 = securityElement.Attribute("Unrestricted");
133  m_noRestriction = (text2 != null && string.Compare(text2, "true", StringComparison.OrdinalIgnoreCase) == 0);
134  }
135 
138  public override SecurityElement ToXml()
139  {
140  SecurityElement securityElement = new SecurityElement("IPermission");
141  securityElement.AddAttribute("class", GetType().FullName + ", " + GetType().Module.Assembly.FullName.Replace('"', '\''));
142  securityElement.AddAttribute("version", "1");
143  if (m_noRestriction)
144  {
145  securityElement.AddAttribute("Unrestricted", "true");
146  }
147  return securityElement;
148  }
149  }
150 }
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...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Definition: __Canon.cs:3
override void FromXml(SecurityElement securityElement)
Reconstructs a T:System.Net.DnsPermission instance from an XML encoding.
override IPermission Intersect(IPermission target)
Creates a permission instance that is the intersection of the current permission instance and the spe...
string Tag
Gets or sets the tag name of an XML element.
override IPermission Union(IPermission target)
Creates a permission instance that is the union of the current permission instance and the specified ...
Represents the XML object model for encoding security objects. This class cannot be inherited.
Defines the underlying structure of all code access permissions.
override SecurityElement ToXml()
Creates an XML encoding of a T:System.Net.DnsPermission instance and its current state.
Controls rights to access Domain Name System (DNS) servers on the network.
Definition: DnsPermission.cs:8
override bool IsSubsetOf(IPermission target)
Determines whether the current permission instance is a subset of the specified permission instance.
Defines methods implemented by permission types.
Definition: IPermission.cs:7
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.
Specifies that the class can be serialized.
bool IsUnrestricted()
Checks the overall permission state of the object.
override IPermission Copy()
Creates an identical copy of the current permission instance.
DnsPermission(PermissionState state)
Creates a new instance of the T:System.Net.DnsPermission class that either allows unrestricted DNS ac...