protected virtual string SerializePrimitiveProfileValue(SyncProfileProperty profileProperty) { string value = profileProperty.Content.ToString(); if (value == null) { throw new SerializationException($"Can't serialize the profile property. Property name: {profileProperty.Name}"); } return(value); }
protected virtual string SerializeSerializableProfileValue(SyncProfileProperty profileProperty) { MemoryStream memoryStream = new MemoryStream(); try { new BinaryFormatter().Serialize(memoryStream, profileProperty.Content); return(System.Convert.ToBase64String(memoryStream.ToArray())); } catch (SerializationException ex) { throw new SerializationException($"Can't serialize the profile property. Property name: {profileProperty.Name}", ex); } finally { memoryStream.Close(); } }
protected virtual string GetSerializedProfileContent(SyncProfileProperty profileProperty) { if (profileProperty.Content == null) { return(string.Empty); } if (profileProperty.Content.GetType().IsPrimitive || profileProperty.Content is string) { return(SerializePrimitiveProfileValue(profileProperty)); } if (profileProperty.Content.GetType().IsSerializable) { return(SerializeSerializableProfileValue(profileProperty)); } throw new Exception($"Can't serialize the profile property. Property name: {profileProperty.Name}"); }
protected virtual string SerializeSerializableProfileValue(SyncProfileProperty profileProperty) { MemoryStream memoryStream = new MemoryStream(); try { new BinaryFormatter().Serialize(memoryStream, profileProperty.Content); return System.Convert.ToBase64String(memoryStream.ToArray()); } catch (SerializationException ex) { throw new SerializationException($"Can't serialize the profile property. Property name: {profileProperty.Name}", ex); } finally { memoryStream.Close(); } }
protected virtual string SerializePrimitiveProfileValue(SyncProfileProperty profileProperty) { string value = profileProperty.Content.ToString(); if (value == null) throw new SerializationException($"Can't serialize the profile property. Property name: {profileProperty.Name}"); return value; }
protected virtual string GetSerializedProfileContent(SyncProfileProperty profileProperty) { if (profileProperty.Content == null) return string.Empty; if (profileProperty.Content.GetType().IsPrimitive || profileProperty.Content is string) return SerializePrimitiveProfileValue(profileProperty); if (profileProperty.Content.GetType().IsSerializable) return SerializeSerializableProfileValue(profileProperty); throw new Exception($"Can't serialize the profile property. Property name: {profileProperty.Name}"); }