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 : IBuiltInEvidence {
44 private string directory;
47 // Public Constructors
50 public ApplicationDirectory (string name)
53 throw new ArgumentNullException ("name");
55 throw new FormatException (Locale.GetText ("Empty"));
63 public string Directory {
64 get { return directory; }
73 return new ApplicationDirectory (this.Directory);
76 public override bool Equals (object o)
78 ApplicationDirectory compare = (o as ApplicationDirectory);
79 if (compare != null) {
80 // MS "by design" behaviour (see FDBK14362)
81 ThrowOnInvalid (compare.directory);
82 // no C14N or other mojo here (it's done elsewhere)
83 return (directory == compare.directory);
88 public override int GetHashCode ()
90 return Directory.GetHashCode ();
93 public override string ToString ()
95 // MS "by design" behaviour (see FDBK14362)
96 ThrowOnInvalid (Directory);
97 SecurityElement element = new SecurityElement ("System.Security.Policy.ApplicationDirectory");
98 element.AddAttribute ("version", "1");
99 element.AddChild (new SecurityElement ("Directory", directory));
100 return element.ToString ();
103 // interface IBuiltInEvidence
105 int IBuiltInEvidence.GetRequiredSize (bool verbose)
107 return ((verbose) ? 3 : 1) + directory.Length;
110 [MonoTODO ("IBuiltInEvidence")]
111 int IBuiltInEvidence.InitFromBuffer (char [] buffer, int position)
116 [MonoTODO ("IBuiltInEvidence")]
117 int IBuiltInEvidence.OutputToBuffer (char [] buffer, int position, bool verbose)
124 private void ThrowOnInvalid (string appdir)
126 if (appdir.IndexOfAny (Path.InvalidPathChars) != -1) {
127 string msg = Locale.GetText ("Invalid character(s) in directory {0}");
128 throw new ArgumentException (String.Format (msg, appdir), "other");