예제 #1
0
 /// <summary>
 /// Constructs a serializer to (de)serialize the given type using the
 /// specified configuration section.
 /// </summary>
 /// <param name="t">the type to serialize/deserialize</param>
 public JsonExSerializer(Type type, string configSection)
 {
     if (type == null)
         throw new ArgumentNullException("type");
     _serializedType = type;
     _context = new SerializationContext();
     _context.SerializerInstance = this;
     XmlConfigurator.Configure(_context, configSection);
 }
예제 #2
0
        /// <summary>
        /// Constructs a serializer with an existing context  to (de)serialize the given type
        /// </summary>
        /// <param name="t">the type to serialize/deserialize</param>
        /// <param name="context"></param>
        public JsonExSerializer(Type type, SerializationContext context)
        {
            if (type == null)
                throw new ArgumentNullException("type");
            if (context == null)
                throw new ArgumentNullException("context");

            _serializedType = type;
            _context = context;
            _context.SerializerInstance = this;
        }
예제 #3
0
        private XmlConfigurator(XmlReader reader, SerializationContext context, string sectionName)
        {
            this.reader = reader;
            this.context = context;
            this.sectionName = sectionName;

            handlers["IsCompact"] = delegate() { context.IsCompact = reader.ReadElementContentAsBoolean(); };
            handlers["OutputTypeComment"] = delegate() { context.OutputTypeComment = reader.ReadElementContentAsBoolean(); };
            handlers["OutputTypeInformation"] = delegate() { context.OutputTypeInformation = reader.ReadElementContentAsBoolean(); };
            handlers["ReferenceWritingType"] = new MapHandler(HandleReferenceWritingType);
            handlers["TypeBindings"] = new MapHandler(HandleTypeBindings);
            handlers["TypeConverters"] = new MapHandler(HandleTypeConverters);
            handlers["CollectionHandlers"] = new MapHandler(HandleCollectionHandlers);
            handlers["IgnoreProperties"] = new MapHandler(HandleIgnoreProperties);
        }
예제 #4
0
        public static void Configure(SerializationContext context, string configSection)
        {
            XmlConfigSection section = (XmlConfigSection)ConfigurationManager.GetSection(configSection);
            if (section == null && configSection != "JsonExSerializer")
                throw new ArgumentException("Unable to find config section " + configSection);
            if (section == null)
                return;

            string xml = section.RawXml;
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            Configure(context, XmlReader.Create(new StringReader(xml)), configSection);
        }
예제 #5
0
 public static void Configure(SerializationContext context, XmlReader reader, string sectionName)
 {
     new XmlConfigurator(reader, context, sectionName).Configure();
 }
예제 #6
0
 public static JsonExSerializer GetSerializer(Type type, SerializationContext context)
 {
     return new JsonExSerializer(type, context);
 }