mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 03:51:19 -10:00
implementation of converters for serialization
svn path=/trunk/mcs/; revision=80486
This commit is contained in:
1 parent
e5f6dc0ce4
commit
db56e73b59
3 files changed
+157
-88
No files matched your search
+22
-3
@@ -41,6 +41,8 @@ namespace System.Web.Script.Serialization
|
||||
{
|
||||
public class JavaScriptSerializer
|
||||
{
|
||||
List<IEnumerable<JavaScriptConverter>> _converterList;
|
||||
|
||||
public JavaScriptSerializer () {
|
||||
}
|
||||
|
||||
@@ -104,7 +106,7 @@ namespace System.Web.Script.Serialization
|
||||
}
|
||||
|
||||
public T Deserialize<T> (string input) {
|
||||
JsonSerializer ser = new JsonSerializer ();
|
||||
JsonSerializer ser = new JsonSerializer (this);
|
||||
return ConvertToType<T> (ser.Deserialize (new StringReader (input)));
|
||||
}
|
||||
|
||||
@@ -212,7 +214,24 @@ namespace System.Web.Script.Serialization
|
||||
}
|
||||
|
||||
public void RegisterConverters (IEnumerable<JavaScriptConverter> converters) {
|
||||
throw new NotImplementedException ();
|
||||
if (converters == null)
|
||||
throw new ArgumentNullException ("converters");
|
||||
|
||||
if (_converterList == null)
|
||||
_converterList = new List<IEnumerable<JavaScriptConverter>> ();
|
||||
_converterList.Add (converters);
|
||||
}
|
||||
|
||||
internal JavaScriptConverter GetConverter (Type type) {
|
||||
if (_converterList != null)
|
||||
for (int i = 0; i < _converterList.Count; i++) {
|
||||
foreach (JavaScriptConverter converter in _converterList [i])
|
||||
foreach (Type supportedType in converter.SupportedTypes)
|
||||
if (supportedType == type)
|
||||
return converter;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string Serialize (object obj) {
|
||||
@@ -222,7 +241,7 @@ namespace System.Web.Script.Serialization
|
||||
}
|
||||
|
||||
public void Serialize (object obj, StringBuilder output) {
|
||||
JsonSerializer ser = new JsonSerializer ();
|
||||
JsonSerializer ser = new JsonSerializer (this);
|
||||
ser.Serialize (new StringWriter (output), obj);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user