コード例 #1
0
 void SerializeCustomSerializable(object instance, TypeSerializationArgs args)
 {
     if (instance == null)
     {
         throw new ArgumentNullException("Cannot serialize null object with ICustomSerializable");
     }
     else
     {
         ICustomSerializable ics = instance as ICustomSerializable;
         ics.Serialize(args.Writer);
     }
 }
コード例 #2
0
        public void Serialize(Contact contact, bool overwrite, string dateFormat)
        {
            _Overwrite = overwrite;
            if (_OutputFormat == OutputFormat.Xml)
            {
                _Serializer = new SerializerToXml();
            }
            else if (_OutputFormat == OutputFormat.Csv)
            {
                _Serializer = new SerializerToCsv();
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            string fileName = GetNewFileName();

            using (var writer = new StreamWriter(fileName, false))
            {
                _Serializer.Serialize(writer, contact, dateFormat);
            }
        }