コード例 #1
0
        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);
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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}");
        }
コード例 #4
0
 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();
     }
 }
コード例 #5
0
        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;
        }
コード例 #6
0
        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}");
        }