2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / CallContext.cs
index accaa6ff0315d747af53eb5c988c0d48a4720fbd..a8f218111f26b3acccde060241fd9a35bd838d92 100644 (file)
@@ -77,16 +77,21 @@ namespace System.Runtime.Remoting.Messaging
                        Headers = headers;
                }
 
-               internal static LogicalCallContext CreateLogicalCallContext ()
+               internal static LogicalCallContext CreateLogicalCallContext (bool createEmpty)
                {
-                       LogicalCallContext ctx = new LogicalCallContext ();
-                       
-                       if (datastore != null)
+                       LogicalCallContext ctx = null;
+                       if (datastore != null) {
                                foreach (DictionaryEntry entry in datastore)
-                                       if (entry.Value is ILogicalThreadAffinative)
+                                       if (entry.Value is ILogicalThreadAffinative) {
+                                               if (ctx == null) ctx = new LogicalCallContext ();
                                                ctx.SetData ((string)entry.Key, entry.Value);
+                                       }
+                       }
 
-                       return ctx;
+                       if (ctx == null && createEmpty)
+                               return new LogicalCallContext ();
+                       else
+                               return ctx;
                }
 
                internal static object SetCurrentCallContext (LogicalCallContext ctx)
@@ -94,7 +99,7 @@ namespace System.Runtime.Remoting.Messaging
                        object oldData = datastore;
 
                        if (ctx != null && ctx.HasInfo)
-                               datastore = ctx.Datastore.Clone ();
+                               datastore = (Hashtable) ctx.Datastore.Clone ();
                        else
                                datastore = null;