Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
AppSettings.cs
Go to the documentation of this file.
1 /*
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements. See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership. The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied. See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20 */
21 
22 using System;
23 using System.Configuration;
24 
25 namespace Lucene.Net.Support
26 {
27  /// <summary>
28  ///
29  /// </summary>
30  public class AppSettings
31  {
32  static System.Collections.Specialized.ListDictionary settings = new System.Collections.Specialized.ListDictionary();
33 
34  /// <summary>
35  ///
36  /// </summary>
37  /// <param name="key"></param>
38  /// <param name="defValue"></param>
39  public static void Set(System.String key, int defValue)
40  {
41  settings[key] = defValue;
42  }
43 
44  /// <summary>
45  ///
46  /// </summary>
47  /// <param name="key"></param>
48  /// <param name="defValue"></param>
49  public static void Set(System.String key, long defValue)
50  {
51  settings[key] = defValue;
52  }
53 
54  /// <summary>
55  ///
56  /// </summary>
57  /// <param name="key"></param>
58  /// <param name="defValue"></param>
59  public static void Set(System.String key, System.String defValue)
60  {
61  settings[key] = defValue;
62  }
63 
64  /// <summary>
65  ///
66  /// </summary>
67  /// <param name="key"></param>
68  /// <param name="defValue"></param>
69  public static void Set(System.String key, bool defValue)
70  {
71  settings[key] = defValue;
72  }
73 
74  /// <summary>
75  ///
76  /// </summary>
77  /// <param name="key"></param>
78  /// <param name="defValue"></param>
79  /// <returns></returns>
80  public static int Get(System.String key, int defValue)
81  {
82  if (settings[key] != null)
83  {
84  return (int)settings[key];
85  }
86 
87  System.String theValue = ConfigurationManager.AppSettings.Get(key);
88  if (theValue == null)
89  {
90  return defValue;
91  }
92  int retValue = Convert.ToInt32(theValue.Trim());
93  settings[key] = retValue;
94  return retValue;
95  }
96 
97  /// <summary>
98  ///
99  /// </summary>
100  /// <param name="key"></param>
101  /// <param name="defValue"></param>
102  /// <returns></returns>
103  public static long Get(System.String key, long defValue)
104  {
105  if (settings[key] != null)
106  {
107  return (long)settings[key];
108  }
109 
110  System.String theValue = ConfigurationManager.AppSettings.Get(key);
111  if (theValue == null)
112  {
113  return defValue;
114  }
115  long retValue = Convert.ToInt64(theValue.Trim());
116  settings[key] = retValue;
117  return retValue;
118  }
119 
120  /// <summary>
121  ///
122  /// </summary>
123  /// <param name="key"></param>
124  /// <param name="defValue"></param>
125  /// <returns></returns>
126  public static System.String Get(System.String key, System.String defValue)
127  {
128  if (settings[key] != null)
129  {
130  return (System.String)settings[key];
131  }
132 
133  System.String theValue = ConfigurationManager.AppSettings.Get(key);
134  if (theValue == null)
135  {
136  return defValue;
137  }
138  settings[key] = theValue;
139  return theValue;
140  }
141 
142  public static bool Get(System.String key, bool defValue)
143  {
144  if (settings[key] != null)
145  {
146  return (bool)settings[key];
147  }
148 
149  System.String theValue = ConfigurationManager.AppSettings.Get(key);
150  if (theValue == null)
151  {
152  return defValue;
153  }
154  bool retValue = Convert.ToBoolean(theValue.Trim());
155  settings[key] = retValue;
156  return retValue;
157  }
158  }
159 }