2 // System.Security.Policy.ApplicationDirectory.cs
5 // Jackson Harper (Jackson@LatitudeGeo.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2002 Jackson Harper, All rights reserved.
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Globalization;
33 using System.Runtime.InteropServices;
38 namespace System.Security.Policy {
42 public sealed class ApplicationDirectory :
48 private string directory;
51 // Public Constructors
54 public ApplicationDirectory (string name)
57 throw new ArgumentNullException ("name");
59 throw new FormatException (Locale.GetText ("Empty"));
67 public string Directory {
68 get { return directory; }
77 return new ApplicationDirectory (this.Directory);
80 public override bool Equals (object o)
82 ApplicationDirectory compare = (o as ApplicationDirectory);
83 if (compare != null) {
84 // MS "by design" behaviour (see FDBK14362)
85 ThrowOnInvalid (compare.directory);
86 // no C14N or other mojo here (it's done elsewhere)
87 return (directory == compare.directory);
92 public override int GetHashCode ()
94 return Directory.GetHashCode ();
97 public override string ToString ()
99 // MS "by design" behaviour (see FDBK14362)
100 ThrowOnInvalid (Directory);
101 SecurityElement element = new SecurityElement ("System.Security.Policy.ApplicationDirectory");
102 element.AddAttribute ("version", "1");
103 element.AddChild (new SecurityElement ("Directory", directory));
104 return element.ToString ();
107 // interface IBuiltInEvidence
109 int IBuiltInEvidence.GetRequiredSize (bool verbose)
111 return ((verbose) ? 3 : 1) + directory.Length;
114 [MonoTODO ("IBuiltInEvidence")]
115 int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position)
120 [MonoTODO ("IBuiltInEvidence")]
121 int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose)
128 private void ThrowOnInvalid (string appdir)
130 if (appdir.IndexOfAny (Path.InvalidPathChars) != -1) {
131 string msg = Locale.GetText ("Invalid character(s) in directory {0}");
132 throw new ArgumentException (String.Format (msg, appdir), "other");