[runtime] Actually clean up context-static data segments.
[mono.git] / mcs / class / System.ServiceModel.Web / System.Runtime.Serialization.Json / DataContractJsonSerializer.cs
index 355ea31dadb87c57ef8a008949b9fc245fbf2cfe..8077136394dedb755b886df4689ac4d8d3f71912 100644 (file)
@@ -84,14 +84,23 @@ namespace System.Runtime.Serialization.Json
                                throw new ArgumentOutOfRangeException ("maxItemsInObjectGraph");
 
                        this.type = type;
-                       known_types = new ReadOnlyCollection<Type> (knownTypes != null ? knownTypes.ToArray () : Type.EmptyTypes);
+
+                       var knownTypesFromAttributes = new List<Type> ();
+
+                       foreach (var attr in type.GetCustomAttributes (typeof (KnownTypeAttribute), false))
+                               knownTypesFromAttributes.Add ((attr as KnownTypeAttribute).Type);
+
+                       if (knownTypes != null)
+                               knownTypesFromAttributes.AddRange (knownTypes);
+
+                       known_types = new ReadOnlyCollection<Type> (knownTypesFromAttributes);
+
                        root = rootName;
                        max_items = maxItemsInObjectGraph;
                        ignore_extension = ignoreExtensionDataObject;
                        always_emit_type = alwaysEmitTypeInformation;
                }
 
-#if !MOONLIGHT
                public DataContractJsonSerializer (Type type, IEnumerable<Type> knownTypes, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, IDataContractSurrogate dataContractSurrogate, bool alwaysEmitTypeInformation)
             : this (type, default_root_name, knownTypes, maxItemsInObjectGraph, ignoreExtensionDataObject, alwaysEmitTypeInformation)
                {
@@ -107,7 +116,12 @@ namespace System.Runtime.Serialization.Json
                        : this (type, rootName != null ? rootName.Value : default_root_name, knownTypes, maxItemsInObjectGraph, ignoreExtensionDataObject, dataContractSurrogate, alwaysEmitTypeInformation)
                {
                }
-#endif
+
+               public DataContractJsonSerializer (Type type, DataContractJsonSerializerSettings settings)
+                       : this (type, settings.RootName, settings.KnownTypes, settings.MaxItemsInObjectGraph, settings.IgnoreExtensionDataObject,
+                               settings.DataContractSurrogate, false)
+               {
+               }
 
         #endregion
 
@@ -117,21 +131,17 @@ namespace System.Runtime.Serialization.Json
                int max_items;
                bool ignore_extension;
                bool always_emit_type;
-#if !MOONLIGHT
                IDataContractSurrogate surrogate;
 
                [MonoTODO]
                public IDataContractSurrogate DataContractSurrogate {
                        get { return surrogate; }
                }
-#endif
 
                [MonoTODO]
                public bool IgnoreExtensionDataObject {
                        get { return ignore_extension; }
                }
-
-               [MonoTODO]
                public ReadOnlyCollection<Type> KnownTypes {
                        get { return known_types; }
                }
@@ -190,6 +200,10 @@ namespace System.Runtime.Serialization.Json
                                return new JsonSerializationReader (this, reader, type, verifyObjectName).ReadRoot ();
                        } catch (SerializationException) {
                                throw;
+                       } catch (InvalidDataContractException) {
+                               throw;
+                       } catch (System.Reflection.TargetInvocationException ex) {
+                               throw ex.InnerException;
                        } catch (Exception ex) {
                                throw new SerializationException ("Deserialization has failed", ex);
                        }
@@ -254,5 +268,26 @@ namespace System.Runtime.Serialization.Json
                                throw new ArgumentNullException ("writer");
                        writer.WriteEndElement ();
                }
+
+               [MonoTODO]
+               public DateTimeFormat DateTimeFormat {
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public EmitTypeInformation EmitTypeInformation {
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public bool SerializeReadOnlyTypes {
+                       get { throw new NotImplementedException (); }
+               }
+
+               [MonoTODO]
+               public bool UseSimpleDictionaryFormat {
+                       get { throw new NotImplementedException (); }
+               }
+
        }
 }