mscorlib(4.0.0.0) API with additions
Zone.cs
4 
6 {
9  [ComVisible(true)]
11  {
12  [OptionalField(VersionAdded = 2)]
13  private string m_url;
14 
15  private SecurityZone m_zone;
16 
17  private static readonly string[] s_names = new string[6]
18  {
19  "MyComputer",
20  "Intranet",
21  "Trusted",
22  "Internet",
23  "Untrusted",
24  "NoZone"
25  };
26 
30  {
31  [SecuritySafeCritical]
32  get
33  {
34  if (m_url != null)
35  {
36  m_zone = _CreateFromUrl(m_url);
37  }
38  return m_zone;
39  }
40  }
41 
45  public Zone(SecurityZone zone)
46  {
47  if (zone < SecurityZone.NoZone || zone > SecurityZone.Untrusted)
48  {
49  throw new ArgumentException(Environment.GetResourceString("Argument_IllegalZone"));
50  }
51  m_zone = zone;
52  }
53 
54  private Zone(Zone zone)
55  {
56  m_url = zone.m_url;
57  m_zone = zone.m_zone;
58  }
59 
60  private Zone(string url)
61  {
62  m_url = url;
63  m_zone = SecurityZone.NoZone;
64  }
65 
70  public static Zone CreateFromUrl(string url)
71  {
72  if (url == null)
73  {
74  throw new ArgumentNullException("url");
75  }
76  return new Zone(url);
77  }
78 
79  [DllImport("QCall", CharSet = CharSet.Unicode)]
80  [SecurityCritical]
81  [SuppressUnmanagedCodeSecurity]
82  private static extern SecurityZone _CreateFromUrl(string url);
83 
88  {
90  }
91 
97  public override bool Equals(object o)
98  {
99  Zone zone = o as Zone;
100  if (zone == null)
101  {
102  return false;
103  }
104  return SecurityZone == zone.SecurityZone;
105  }
106 
109  public override int GetHashCode()
110  {
111  return (int)SecurityZone;
112  }
113 
116  public override EvidenceBase Clone()
117  {
118  return new Zone(this);
119  }
120 
123  public object Copy()
124  {
125  return Clone();
126  }
127 
128  internal SecurityElement ToXml()
129  {
130  SecurityElement securityElement = new SecurityElement("System.Security.Policy.Zone");
131  securityElement.AddAttribute("version", "1");
132  if (SecurityZone != SecurityZone.NoZone)
133  {
134  securityElement.AddChild(new SecurityElement("Zone", s_names[(int)SecurityZone]));
135  }
136  else
137  {
138  securityElement.AddChild(new SecurityElement("Zone", s_names[s_names.Length - 1]));
139  }
140  return securityElement;
141  }
142 
145  public override string ToString()
146  {
147  return ToXml().ToString();
148  }
149 
150  internal object Normalize()
151  {
152  return s_names[(int)SecurityZone];
153  }
154  }
155 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
SecurityZone
Defines the integer values corresponding to security zones used by security policy.
Definition: SecurityZone.cs:8
Provides the security zone of a code assembly as evidence for policy evaluation. This class cannot be...
Definition: Zone.cs:10
override string ToString()
Returns a string representation of the current T:System.Security.Policy.Zone.
Definition: Zone.cs:145
Definition: __Canon.cs:3
object Copy()
Creates an equivalent copy of the evidence object.
Definition: Zone.cs:123
IPermission CreateIdentityPermission(Evidence evidence)
Creates an identity permission that corresponds to the current instance of the T:System....
Definition: Zone.cs:87
Zone(SecurityZone zone)
Initializes a new instance of the T:System.Security.Policy.Zone class with the zone from which a code...
Definition: Zone.cs:45
Provides a base class from which all objects to be used as evidence must derive.
Definition: EvidenceBase.cs:12
Defines the method that creates a new identity permission.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
static Zone CreateFromUrl(string url)
Creates a new zone with the specified URL.
Definition: Zone.cs:70
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents the XML object model for encoding security objects. This class cannot be inherited.
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
override bool Equals(object o)
Compares the current T:System.Security.Policy.Zone evidence object to the specified object for equiva...
Definition: Zone.cs:97
override EvidenceBase Clone()
Creates a new object that is a copy of the current instance.
Definition: Zone.cs:116
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.
Defines the identity permission for the zone from which the code originates. This class cannot be inh...
Defines the set of information that constitutes input to security policy decisions....
Definition: Evidence.cs:17
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
SecurityZone SecurityZone
Gets the zone from which the code assembly originates.
Definition: Zone.cs:30
override int GetHashCode()
Gets the hash code of the current zone.
Definition: Zone.cs:109
override string ToString()
Produces a string representation of an XML element and its constituent attributes,...