Initial commit
[mono.git] / mcs / class / referencesource / System / compmod / system / collections / specialized / casesensitivestringdictionary.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="CaseSensitiveStringDictionary.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 /*
8 On UNIX systems the environment variable names are case sensitive (as the opposite from Windows). 
9 Thus using StringDictionary to store the environment settings is wrong 
10 (StringDictionary converts key values to lower case).
11 CaseSensitiveStringDictionary is derived from the StringDictionary and it does the same thing, 
12 except the conversion of the key to lower case. So its fully usable for UNIX systems.
13 This class is used to create the StringDictionary object everywhere 
14 its used for environment settings storage (only ProcessStartInfo.cs and Executor.cs). 
15 This change enables the correct UNIX behavior along with not changing public API.
16 Author: [....]
17 */
18
19 #if PLATFORM_UNIX
20
21 namespace System.Collections.Specialized
22 {
23     using System.Runtime.InteropServices;
24     using System.Diagnostics;
25     using System;
26     using System.Collections;
27     using System.ComponentModel.Design.Serialization;
28     using System.Globalization;
29     using System.Security.Permissions;
30
31     // This subclass of StringDictionary ensures that we do the lookups in a case-sensitive manner,
32     // so we can match any string comparisons that are done on Unix.
33     internal class CaseSensitiveStringDictionary : StringDictionary
34     {
35         public CaseSensitiveStringDictionary () {
36         }
37
38         public override string this[ string key ]
39         {
40             get
41             {
42                 if ( key == null )
43                 {
44                     throw new ArgumentNullException ( "key" );
45                 }
46
47                 return (string) contents[ key ];
48             }
49             set
50             {
51                 if ( key == null )
52                 {
53                     throw new ArgumentNullException ( "key" );
54                 }
55
56                 contents[ key ] = value;
57             }
58         }
59
60         public override void Add ( string key, string value )
61         {
62             if ( key == null )
63             {
64                 throw new ArgumentNullException ( "key" );
65             }
66
67             contents.Add ( key , value );
68         }
69
70         public override bool ContainsKey ( string key )
71         {
72             if ( key == null )
73             {
74                 throw new ArgumentNullException ( "key" );
75             }
76
77             return contents.ContainsKey ( key );
78         }
79
80         public override void Remove ( string key )
81         {
82             if ( key == null )
83             {
84                 throw new ArgumentNullException ( "key" );
85             }
86
87             contents.Remove ( key );
88         }
89     }
90 }
91
92
93 #endif // PLATFORM_UNIX