public GuidObject Clone(Guid newGuid, string newID) { var oldGuid = this.Guid; this.Guid = newGuid; GuidObject clone = null; try { SerializationSettings settings; if (UnityEngine.Application.isPlaying) { settings = new SerializationSettings(SerializationFlags.Runtime | SerializationFlags.Binary); } else { settings = new SerializationSettings(SerializationFlags.Static | SerializationFlags.Binary); } var bytes = Serializer.Instance.Serialize(this, settings); clone = Serializer.Instance.Deserialize <GuidObject>(bytes, settings); clone.ID = newID; } catch (Exception ex) { Logger.Instance.Error(ex.ToString()); } finally { this.Guid = oldGuid; } return(clone); }
public void SettingsIsCloned() { var settings = new SerializationSettings(); var ignoredMemberList = new List <string>(); settings.ignoredMembers.Add(GetType(), ignoredMemberList); var ignoredInstances = new List <Func <object, bool> >(); settings.ignoredInstances.Add(GetType(), ignoredInstances); var memberConverterList = new Dictionary <string, ConvertMember>(); settings.membersConverters.Add(GetType(), memberConverterList); settings.ignoredByNameMembers.Add("ignored"); var clone = settings.Clone(); Assert.NotSame(settings, clone); Assert.NotSame(settings.ignoredMembers, clone.ignoredMembers); Assert.NotSame(settings.ignoredMembers.First().Value, clone.ignoredMembers.First().Value); Assert.NotSame(settings.ignoredInstances, clone.ignoredInstances); Assert.NotSame(settings.ignoredInstances.First().Value, clone.ignoredInstances.First().Value); Assert.NotSame(settings.ignoredByNameMembers, clone.ignoredByNameMembers); Assert.NotSame(settings.membersConverters, clone.membersConverters); Assert.NotSame(settings.membersConverters.First().Value, clone.membersConverters.First().Value); }
public ExcelWriter(Stream streamWriter, SerializationSettings settings, string[] fields) : base(settings) { var basicExcelWriter = new BasicExcelWriter(streamWriter, base.Settings); writer = new FlatMatrixTransformWriter(basicExcelWriter, base.Settings, fields); }
public void LoadInitialState() { Clear(); GameData = new GameData(); byte[] bytes; SerializationSettings settings; #if UNITY_EDITOR if (Application.isPlaying) { bytes = File.ReadAllBytes(Config.TempEditorStateFile); settings = new SerializationSettings(SerializationMode.LoadStaticPackage); } else { bytes = File.ReadAllBytes(Config.StaticDistributedFile); settings = new SerializationSettings(SerializationMode.LoadStaticFolder); settings.DistributedFolder = Config.StaticDistributedFolder; EditorOptions.LastDataBaseSyncTime = DateTime.UtcNow; } #else bytes = File.ReadAllBytes(StaticBuildPackageFile); settings = new SerializationSettings(SerializationMode.LoadStaticPackage); #endif Serializer.Instance.Deserialize <GameState>(bytes, settings, KeepOriginalState); }
/// <summary> /// Gets the data from this component, serialized to the specified type. The data is /// retrieved from the base component, serialized with JSON, and reconstituted as type /// T in the memory space of the caller. /// /// The target type must exist and be a [JsonObject] in both this assembly and the /// target component's assembly. /// /// This method is somewhat slow and memory intensive, and should be used sparingly. /// </summary> /// <typeparam name="T">The data type to retrieve and into which to convert.</typeparam> /// <param name="defValue">The default value if the instance data is unset.</param> /// <returns>The data, or defValue if the instance data has not been set or cannot be serialized.</returns> public T GetInstanceDataSerialized <T>(T defValue = default) { var remoteData = InstanceData; T result = defValue; using (var buffer = new MemoryStream(1024)) { try { var writer = new StreamWriter(buffer, Encoding.UTF8); SerializationSettings.Serialize(writer, remoteData); writer.Flush(); buffer.Position = 0L; var reader = new StreamReader(buffer, Encoding.UTF8); if (SerializationSettings.Deserialize(reader, typeof(T)) is T decoded) { result = decoded; } } catch (JsonException e) { PUtil.LogError("Unable to serialize instance data for component " + ID + ":"); PUtil.LogException(e); result = defValue; } } return(result); }
public ExcelWriter(Stream streamWriter, SerializationSettings settings, Func <string, bool> fieldFilter) : base(settings) { var basicExcelWriter = new BasicExcelWriter(streamWriter, base.Settings); writer = new FlatMatrixTransformWriter(basicExcelWriter, base.Settings, fieldFilter); }
public ExcelWriter(Stream streamWriter, SerializationSettings settings) : base(settings) { var basicExcelWriter = new BasicExcelWriter(streamWriter, base.Settings); writer = new FlatMatrixWriter(basicExcelWriter, base.Settings); }
public IEnumerable <Datom> Serialize <T>(IEnumerable <T> objects) { var visited = new HashSet <Reference>(); var settings = new SerializationSettings(); return(objects.SelectMany(x => SerializeRecurse(x, settings, visited))); }
public void AddressJsonConvertorShouldDeserializeCorrectly(IEnumerable <Address> addresses, AddressConverter converter) { // Arrange var serializedAddresses = new List <string>(); var deserializedAddresses = new List <Address>(); var settings = SerializationSettings.GetJsonSettings(); settings.Converters.Add(converter); // Act foreach (var address in addresses) { serializedAddresses.Add(JsonConvert.SerializeObject(address, settings)); } foreach (var address in serializedAddresses) { deserializedAddresses.Add(JsonConvert.DeserializeObject <Address>(address, settings)); } // Assert foreach (var address in deserializedAddresses) { addresses .FirstOrDefault(a => a.EMail == address.EMail && a.Name == address.Name) .ShouldNotBeNull("Address converter serialization/deserialization failed."); } }
private static void FromSequenceToJson(IList obj, SerializationSettings options) { options.resultStore.Append('['); if (!options.compactOutput) { AdvanceLine(options); } if (obj.Count > 0) { IEnumerator iterator = obj.GetEnumerator(); int count = 0; while (iterator.MoveNext()) { if (count > 0) { options.resultStore.Append(','); if (!options.compactOutput) { NewLine(options); } } ++count; ToJson(iterator.Current, options); } } if (!options.compactOutput) { ReturnLine(options); } options.resultStore.Append(']'); }
public CsvWriter(Stream textStream, SerializationSettings settings, string[] fields) : base(settings, TextCase.KeepOriginal) { var writer = new StreamWriter(textStream, settings.Encoding, 1024, true); Initialize(writer, true, fields); }
public void ComplexClassNullValue() { ComplexTestClass a = new ComplexTestClass { A = 123, B = "testString", C = NanoState.Ignore, }; JObject target = new JObject(); SerializationSettings settings = new SerializationSettings(); settings.SerializeNull = true; new Serializer(settings).SerializeObject((NewtonsoftJsonAdapter)target, a); AssertChildren(4, target); AssertAttribute("123", "A_", target); AssertAttribute("testString", "B", target); AssertAttribute("Ignore", "C", target); Assert.AreEqual(JTokenType.Null, target["F"].Type); ComplexTestClass b = Deserializer.Deserialize <ComplexTestClass>((NewtonsoftJsonAdapter)target); Assert.AreEqual(a.A, b.A); Assert.AreEqual(a.B, b.B); Assert.AreEqual(a.C, b.C); Assert.AreEqual(a.D, b.D); }
public CsvWriter(Stream textStream, SerializationSettings settings, string[] fields) : base(settings) { var writer = new StreamWriter(textStream, Encoding.UTF8, 1024, true); Initialize(writer, true, fields); }
private HashMap ParseArgs(HttpContext httpContext) { DocumentModel document = null; using (var stream = httpContext.Request.Body) { var settings = new SerializationSettings { IsFragment = true, IsLenient = true, TextCase = TextCase.KeepOriginal }; var documentWriter = new DocumentWriter(settings); var jsonReader = new JsonReader(stream, settings); jsonReader.CopyTo(documentWriter); document = documentWriter.TargetDocument; } var map = new HashMap(); foreach (var property in document.Root.ChildProperties()) { map[property.Name] = property.Value.SerializationValue; } return(map); }
public CsvReader(Stream textStream, SerializationSettings settings, string[] fields) : base(settings) { var reader = new StreamReader(textStream, Encoding.UTF8, false, 1024, true); Initialize(reader, true, fields); }
public XmlDocumentWriter(XmlWriter textWriter, SerializationSettings settings) : base(settings, TextCase.PascalCase) { this.writer = textWriter; this.stack = new Stack <NodeType>(); base.IsValid = true; }
public CsvWriter(Stream textStream, SerializationSettings settings, Func <string, bool> fieldFilter) : base(settings) { var writer = new StreamWriter(textStream, settings.Encoding, 1024, true); Initialize(writer, true, fieldFilter); }
public CsvReader(Stream textStream, SerializationSettings settings, Func <string, bool> fieldFilter) : base(settings) { var reader = new StreamReader(textStream, Encoding.UTF8, false, 1024, true); Initialize(reader, true, fieldFilter); }
public BasicCsvReader(TextReader textReader, SerializationSettings settings) : base(settings) { this.textReader = textReader; this.queue = new Queue <Node>(); this.colNamesAlgorithm = CreateColNames(); }
public CsvWriter(Stream textStream, SerializationSettings settings) : base(settings) { var writer = new StreamWriter(textStream, settings.Encoding, 1024, true); Initialize(writer, true); }
public ExcelWriter(Stream streamWriter, SerializationSettings settings, string[] fields) : base(settings, TextCase.KeepOriginal) { var basicExcelWriter = new BasicExcelWriter(streamWriter, base.Settings); writer = new FlatMatrixWriter(basicExcelWriter, base.Settings, fields); }
public XmlDocumentWriter(System.Xml.XmlWriter writer, SerializationSettings settings) : base(settings) { this.writer = writer; this.stack = new Stack <NodeType>(); base.IsValid = true; }
public JoinReader(SerializationSettings settings, IEnumerable <Reader> readers) : base(settings ?? new SerializationSettings()) { this.settings = settings; this.readers = readers.ToArray(); this.enumerator = EnumerateNodes().GetEnumerator(); }
public static void RunEntityTest() { var entityA = new Entity(); entityA.ID = "EntityA"; entityA.Fields.SetValue(StringField.Country, "Russia"); entityA.Fields.SetValue(StringField.City, "Kaliningrad"); entityA.Fields.SetValue(IntField.AppleCount, 4); entityA.Fields.SetValue(IntField.OrangeCount, 3); var entityB = new Entity(); entityB.Fields.SetValue(StringField.Country, "China"); entityB.Fields.SetValue(IntField.BananaCount, 77); entityB.Fields.SetValue(StringField.Notes, "this is notes"); entityA.Fields.SetValue(EntityField.Link, entityB); entityB.Fields.SetValue(EntityField.Link, entityA); var settings = new SerializationSettings(SerializationFlags.Binary); var bytes = Serializer.Instance.Serialize(entityA, settings); var json = Serializer.Instance.ToJson(bytes); Logger.Instance.Print(json); entityA.Release(); entityB.Release(); var deserializedEntity = Serializer.Instance.Deserialize <Entity>(bytes, settings); Logger.Instance.Print("Deserialized"); }
public JsonWriter(TextWriter writer, SerializationSettings settings) : base(settings) { this.writer = writer; this.stack = new Stack <Children>(); base.IsValid = true; }
public JsonReader(TextReader textReader, SerializationSettings settings) : base(settings) { this.reader = textReader; this.nodeEnumerator = EnumerateNodes().GetEnumerator(); base.IsValid = true; }
public GraphWriter(Type type, IEnumerable <Type> knownTypes, SerializationSettings settings) : base(settings is GraphSerializationSettings ? (GraphSerializationSettings)settings : new GraphSerializationSettings(settings)) { this.GraphType = type; this.graphs = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(type)); this.scopes = new Stack <Scope>(); }
public XmlDocumentReader(System.Xml.XmlReader reader, SerializationSettings settings) : base(settings) { this.reader = reader; this.stack = new Stack <NodeType>(); this.enumerator = EnumerateNodes().GetEnumerator(); base.IsValid = true; }
public static void Serialize(object obj, JsonOptions options, StringBuilder resultStore) { options.ThrowIfNull(nameof(options)); resultStore.ThrowIfNull(nameof(resultStore)); SerializationSettings serializationSettings = new SerializationSettings(resultStore); serializationSettings.ApplyOptions(options); ToJson(obj, serializationSettings); }
private static void CleanStringToJson(string str, SerializationSettings options) { // Regex.Escape is too agressive in removing characters. // builder.Append(Regex.Escape(str)); for (int i = 0; i < str.Length; ++i) { CleanCharToJson(str[i], options); } }
public CsvSerializationSettings() { Separator = ";"; SerializationSettings = new SerializationSettings(); DeserializationSettings = new DeserializationSettings(); }