~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/Simias.log4net/src/Util/.svn/text-base/LogicalThreadContextProperties.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#region Copyright & License
2
 
//
3
 
// Copyright 2001-2005 The Apache Software Foundation
4
 
//
5
 
// Licensed under the Apache License, Version 2.0 (the "License");
6
 
// you may not use this file except in compliance with the License.
7
 
// You may obtain a copy of the License at
8
 
//
9
 
// http://www.apache.org/licenses/LICENSE-2.0
10
 
//
11
 
// Unless required by applicable law or agreed to in writing, software
12
 
// distributed under the License is distributed on an "AS IS" BASIS,
13
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
// See the License for the specific language governing permissions and
15
 
// limitations under the License.
16
 
//
17
 
#endregion
18
 
 
19
 
// .NET Compact Framework 1.0 has no support for System.Runtime.Remoting.Messaging.CallContext
20
 
#if !NETCF
21
 
 
22
 
using System;
23
 
using System.Collections;
24
 
 
25
 
using System.Runtime.Remoting.Messaging;
26
 
 
27
 
namespace log4net.Util
28
 
{
29
 
        /// <summary>
30
 
        /// Implementation of Properties collection for the <see cref="log4net.LogicalThreadContext"/>
31
 
        /// </summary>
32
 
        /// <remarks>
33
 
        /// <para>
34
 
        /// Class implements a collection of properties that is specific to each thread.
35
 
        /// The class is not synchronized as each thread has its own <see cref="PropertiesDictionary"/>.
36
 
        /// </para>
37
 
        /// </remarks>
38
 
        /// <author>Nicko Cadell</author>
39
 
        public sealed class LogicalThreadContextProperties : ContextPropertiesBase
40
 
        {
41
 
                #region Public Instance Constructors
42
 
 
43
 
                /// <summary>
44
 
                /// Constructor
45
 
                /// </summary>
46
 
                /// <remarks>
47
 
                /// <para>
48
 
                /// Initializes a new instance of the <see cref="LogicalThreadContextProperties" /> class.
49
 
                /// </para>
50
 
                /// </remarks>
51
 
                internal LogicalThreadContextProperties()
52
 
                {
53
 
                }
54
 
 
55
 
                #endregion Public Instance Constructors
56
 
 
57
 
                #region Public Instance Properties
58
 
 
59
 
                /// <summary>
60
 
                /// Gets or sets the value of a property
61
 
                /// </summary>
62
 
                /// <value>
63
 
                /// The value for the property with the specified key
64
 
                /// </value>
65
 
                /// <remarks>
66
 
                /// <para>
67
 
                /// Get or set the property value for the <paramref name="key"/> specified.
68
 
                /// </para>
69
 
                /// </remarks>
70
 
                override public object this[string key]
71
 
                {
72
 
                        get 
73
 
                        { 
74
 
                                // Don't create the dictionary if it does not already exist
75
 
                                PropertiesDictionary dictionary = GetProperties(false);
76
 
                                if (dictionary != null)
77
 
                                {
78
 
                                        return dictionary[key]; 
79
 
                                }
80
 
                                return null;
81
 
                        }
82
 
                        set 
83
 
                        { 
84
 
                                // Force the dictionary to be created
85
 
                                GetProperties(true)[key] = value; 
86
 
                        }
87
 
                }
88
 
 
89
 
                #endregion Public Instance Properties
90
 
 
91
 
                #region Public Instance Methods
92
 
 
93
 
                /// <summary>
94
 
                /// Remove a property
95
 
                /// </summary>
96
 
                /// <param name="key">the key for the entry to remove</param>
97
 
                /// <remarks>
98
 
                /// <para>
99
 
                /// Remove the value for the specified <paramref name="key"/> from the context.
100
 
                /// </para>
101
 
                /// </remarks>
102
 
                public void Remove(string key)
103
 
                {
104
 
                        PropertiesDictionary dictionary = GetProperties(false);
105
 
                        if (dictionary != null)
106
 
                        {
107
 
                                dictionary.Remove(key);
108
 
                        }
109
 
                }
110
 
 
111
 
                /// <summary>
112
 
                /// Clear all the context properties
113
 
                /// </summary>
114
 
                /// <remarks>
115
 
                /// <para>
116
 
                /// Clear all the context properties
117
 
                /// </para>
118
 
                /// </remarks>
119
 
                public void Clear()
120
 
                {
121
 
                        PropertiesDictionary dictionary = GetProperties(false);
122
 
                        if (dictionary != null)
123
 
                        {
124
 
                                dictionary.Clear();
125
 
                        }
126
 
                }
127
 
 
128
 
                #endregion Public Instance Methods
129
 
 
130
 
                #region Internal Instance Methods
131
 
 
132
 
                /// <summary>
133
 
                /// Get the PropertiesDictionary stored in the LocalDataStoreSlot for this thread.
134
 
                /// </summary>
135
 
                /// <param name="create">create the dictionary if it does not exist, otherwise return null if is does not exist</param>
136
 
                /// <returns>the properties for this thread</returns>
137
 
                /// <remarks>
138
 
                /// <para>
139
 
                /// The collection returned is only to be used on the calling thread. If the
140
 
                /// caller needs to share the collection between different threads then the 
141
 
                /// caller must clone the collection before doings so.
142
 
                /// </para>
143
 
                /// </remarks>
144
 
                internal PropertiesDictionary GetProperties(bool create)
145
 
                {
146
 
                        PropertiesDictionary properties = (PropertiesDictionary)CallContext.GetData("log4net.Util.LogicalThreadContextProperties");
147
 
                        if (properties == null && create)
148
 
                        {
149
 
                                properties  = new PropertiesDictionary();
150
 
                                CallContext.SetData("log4net.Util.LogicalThreadContextProperties", properties);
151
 
                        }
152
 
                        return properties;
153
 
                }
154
 
 
155
 
                #endregion Internal Instance Methods
156
 
        }
157
 
}
158
 
 
159
 
#endif