Esempio n. 1
0
        public static void WriteObject(IExportable instance, REDBinaryWriter red)
        {
            red.Write((byte)0);

            var fields = REDReflection.GetREDFields(instance.GetType());

            foreach (var field in fields)
            {
                var value = field.GetValue(instance);

                if (value == null || value == default)
                {
                    continue;
                }

                var(name, type) = REDReflection.GetREDNameTypePair(field);
                red.Write((CName)name);
                red.Write((CName)type);

                var start = red.BaseStream.Position;
                red.Write(0u);
                WriteProperty(value, red);

                var end = red.BaseStream.Position;
                red.BaseStream.Seek(start, SeekOrigin.Begin);
                red.Write(Convert.ToUInt32(end - start));
                red.BaseStream.Seek(end, SeekOrigin.Begin);
            }

            red.Write((ushort)0);
        }
        public void WriteRecord(TextWriter writer, IExportable objectToRecord)
        {
            EnsureWriterCreated(writer);

            AddClassMap(objectToRecord.GetType());

            _csvWriter.WriteRecords(new object[] { objectToRecord });
        }
Esempio n. 3
0
        public static void Export(IExportable source, string fileTitle = null)
        {
            if (fileTitle == null)
            {
                fileTitle = source.GetType().Name;
            }

            var timestamp  = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            var serializer = JsonSerializer.CreateDefault();
            var filePath   = Resources.exportPath + $"{fileTitle}_{timestamp}.json";

            using (var sw = new StreamWriter(filePath))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, source.ExportData);
                }
        }