mscorlib(4.0.0.0) API with additions
Site.cs
4 using System.Security.Util;
5 
7 {
10  [ComVisible(true)]
12  {
13  private SiteString m_name;
14 
17  public string Name => m_name.ToString();
18 
22  public Site(string name)
23  {
24  if (name == null)
25  {
26  throw new ArgumentNullException("name");
27  }
28  m_name = new SiteString(name);
29  }
30 
31  private Site(SiteString name)
32  {
33  m_name = name;
34  }
35 
40  public static Site CreateFromUrl(string url)
41  {
42  return new Site(ParseSiteFromUrl(url));
43  }
44 
45  private static SiteString ParseSiteFromUrl(string name)
46  {
47  URLString uRLString = new URLString(name);
48  if (string.Compare(uRLString.Scheme, "file", StringComparison.OrdinalIgnoreCase) == 0)
49  {
50  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSite"));
51  }
52  return new SiteString(new URLString(name).Host);
53  }
54 
55  internal SiteString GetSiteString()
56  {
57  return m_name;
58  }
59 
64  {
65  return new SiteIdentityPermission(Name);
66  }
67 
72  public override bool Equals(object o)
73  {
74  Site site = o as Site;
75  if (site == null)
76  {
77  return false;
78  }
79  return string.Equals(Name, site.Name, StringComparison.OrdinalIgnoreCase);
80  }
81 
84  public override int GetHashCode()
85  {
86  return Name.GetHashCode();
87  }
88 
91  public override EvidenceBase Clone()
92  {
93  return new Site(m_name);
94  }
95 
98  public object Copy()
99  {
100  return Clone();
101  }
102 
103  internal SecurityElement ToXml()
104  {
105  SecurityElement securityElement = new SecurityElement("System.Security.Policy.Site");
106  securityElement.AddAttribute("version", "1");
107  if (m_name != null)
108  {
109  securityElement.AddChild(new SecurityElement("Name", m_name.ToString()));
110  }
111  return securityElement;
112  }
113 
116  public override string ToString()
117  {
118  return ToXml().ToString();
119  }
120 
121  internal object Normalize()
122  {
123  return m_name.ToString().ToUpper(CultureInfo.InvariantCulture);
124  }
125  }
126 }
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override EvidenceBase Clone()
Creates a new object that is a copy of the current instance.
Definition: Site.cs:91
override bool Equals(object o)
Compares the current T:System.Security.Policy.Site to the specified object for equivalence.
Definition: Site.cs:72
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
Provides the Web site from which a code assembly originates as evidence for policy evaluation....
Definition: Site.cs:11
Definition: __Canon.cs:3
static Site CreateFromUrl(string url)
Creates a new T:System.Security.Policy.Site object from the specified URL.
Definition: Site.cs:40
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.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
override int GetHashCode()
Returns the hash code of the current website name.
Definition: Site.cs:84
Represents the XML object model for encoding security objects. This class cannot be inherited.
string Name
Gets the website from which the code assembly originates.
Definition: Site.cs:17
Defines the identity permission for the Web site from which the code originates. This class cannot be...
override string ToString()
Returns a string representation of the current T:System.Security.Policy.Site object.
Definition: Site.cs:116
object Copy()
Creates an equivalent copy of the T:System.Security.Policy.Site object.
Definition: Site.cs:98
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 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.
IPermission CreateIdentityPermission(Evidence evidence)
Creates an identity permission that corresponds to the current T:System.Security.Policy....
Definition: Site.cs:63
Specifies that the class can be serialized.
Site(string name)
Initializes a new instance of the T:System.Security.Policy.Site class with the website from which a c...
Definition: Site.cs:22
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
override string ToString()
Produces a string representation of an XML element and its constituent attributes,...