private object SerializeValuePrivate(object value)
        {
            if (this.PropertyDefinition == null)
            {
                return(value);
            }
            if (SerializationTypeConverter.TypeIsSerializable(this.PropertyDefinition.Type))
            {
                return(value);
            }
            object result;

            try
            {
                result = this.SerializeValue(value);
            }
            catch (FormatException innerException)
            {
                throw new SerializationException(DataStrings.ErrorConversionFailed(this.PropertyDefinition, value), innerException);
            }
            catch (NotImplementedException innerException2)
            {
                throw new SerializationException(DataStrings.ErrorConversionFailed(this.PropertyDefinition, value), innerException2);
            }
            return(result);
        }
        private object DeserializeValuePrivate(object value)
        {
            if (this.PropertyDefinition == null)
            {
                return(value);
            }
            if (SerializationTypeConverter.TypeIsSerializable(this.PropertyDefinition.Type))
            {
                return(value);
            }
            object result;

            try
            {
                result = this.DeserializeValue(value);
            }
            catch (FormatException ex)
            {
                throw new DataValidationException(new PropertyConversionError(DataStrings.ErrorConversionFailed(this.PropertyDefinition, value), this.PropertyDefinition, value, ex), ex);
            }
            return(result);
        }
Esempio n. 3
0
 public static bool TypeIsSerializable(Type type)
 {
     if (null == type)
     {
         throw new ArgumentNullException("type");
     }
     if (!type.GetTypeInfo().IsSerializable)
     {
         return(false);
     }
     if (!type.GetTypeInfo().IsGenericType)
     {
         return(true);
     }
     foreach (Type type2 in type.GetTypeInfo().GetGenericArguments())
     {
         if (!SerializationTypeConverter.TypeIsSerializable(type2))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 4
0
 public static bool CanSerialize(Type type)
 {
     return(SerializationTypeConverter.TypeIsSerializable(type) && !type.GetTypeInfo().IsEnum&& (type.GetTypeInfo().FullName.StartsWith("Microsoft.Exchange.", StringComparison.OrdinalIgnoreCase) || type.GetTypeInfo().FullName.StartsWith("Microsoft.Office.CompliancePolicy.", StringComparison.OrdinalIgnoreCase) || (type.GetTypeInfo().Equals(typeof(Exception)) || type.GetTypeInfo().IsSubclassOf(typeof(Exception)))));
 }