|
|
@@ -6,10 +6,29 @@
|
|
|
// (C) Ximian, Inc.
|
|
|
//
|
|
|
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+
|
|
|
namespace System.Runtime.Serialization
|
|
|
{
|
|
|
public class SurrogateSelector : ISurrogateSelector
|
|
|
{
|
|
|
+ // Fields
|
|
|
+ Hashtable Surrogates = new Hashtable ();
|
|
|
+ string currentKey = null; // current key of Surrogates
|
|
|
+
|
|
|
+ internal struct Bundle
|
|
|
+ {
|
|
|
+ public ISerializationSurrogate surrogate;
|
|
|
+ public ArrayList selectors;
|
|
|
+
|
|
|
+ public Bundle (ISerializationSurrogate surrogate)
|
|
|
+ {
|
|
|
+ this.surrogate = surrogate;
|
|
|
+ selectors = new ArrayList ();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Constructor
|
|
|
public SurrogateSelector()
|
|
|
: base ()
|
|
|
@@ -17,37 +36,57 @@ namespace System.Runtime.Serialization
|
|
|
}
|
|
|
|
|
|
// Methods
|
|
|
- [MonoTODO]
|
|
|
public virtual void AddSurrogate (Type type,
|
|
|
StreamingContext context, ISerializationSurrogate surrogate)
|
|
|
{
|
|
|
if (type == null || surrogate == null)
|
|
|
- throw new ArgumentNullException ("Null reference");
|
|
|
+ throw new ArgumentNullException ("Null reference.");
|
|
|
+
|
|
|
+ currentKey = type.FullName + "#" + context.ToString ();
|
|
|
+
|
|
|
+ if (Surrogates.ContainsKey (key))
|
|
|
+ throw new ArgumentException ("A surrogate for " + type.FullName + " already exists.");
|
|
|
+
|
|
|
+ Bundle values = new Bundle (surrogate);
|
|
|
+
|
|
|
+ Surrogates.Add (currentKey, values);
|
|
|
}
|
|
|
|
|
|
- [MonoTODO]
|
|
|
public virtual void ChainSelector (ISurrogateSelector selector)
|
|
|
{
|
|
|
+ if (selector == null)
|
|
|
+ throw new ArgumentNullException ("Selector is null.");
|
|
|
+
|
|
|
+ Bundle current = (Bundle) Surrogates [currentKey];
|
|
|
+ current.selectors.Add (selector);
|
|
|
}
|
|
|
|
|
|
- [MonoTODO]
|
|
|
public virtual ISurrogateSelector GetNextSelector ()
|
|
|
{
|
|
|
- return null;
|
|
|
+ Bundle current = (Bundle) Surrogates [currentKey];
|
|
|
+ return (ISurrogateSelector) current.selectors [current.selectors.Count];
|
|
|
}
|
|
|
|
|
|
- [MonoTODO]
|
|
|
public virtual ISerializationSurrogate GetSurrogate (Type type,
|
|
|
StreamingContext context, out ISurrogateSelector selector)
|
|
|
{
|
|
|
- selector = null;
|
|
|
- return null;
|
|
|
+ if (type == null)
|
|
|
+ throw new ArgumentNullException ("type is null.");
|
|
|
+
|
|
|
+ string key = type.FullName + "#" + context.ToString ();
|
|
|
+ Bundle current = (Bundle) Surrogates [key];
|
|
|
+ selector = (ISurrogateSelector) current.selectors [current.selectors.Count - 1];
|
|
|
+
|
|
|
+ return (ISerializationSurrogate) current.surrogate;
|
|
|
}
|
|
|
|
|
|
- [MonoTODO]
|
|
|
public virtual void RemoveSurrogate (Type type, StreamingContext context)
|
|
|
{
|
|
|
+ if (type == null)
|
|
|
+ throw new ArgumentNullException ("type is null.");
|
|
|
+
|
|
|
+ string key = type.FullName + "#" + context.ToString ();
|
|
|
+ Surrogates.Remove (key);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|