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);
        }
Esempio n. 2
0
        private bool CanConvert(object sourceValue, Type destinationType, out byte[] serializationData, out string stringValue, out Exception error)
        {
            serializationData = null;
            stringValue       = null;
            error             = null;
            ExTraceGlobals.SerializationTracer.TraceFunction((long)this.GetHashCode(), "SerializationTypeConverter.CanConvert({0}, {1})", new object[]
            {
                sourceValue ?? "<null>",
                destinationType ?? "<null>"
            });
            if (null == destinationType)
            {
                error = new ArgumentNullException("destinationType");
                return(false);
            }
            if (sourceValue == null)
            {
                error = new ArgumentNullException("sourceValue");
                return(false);
            }
            PSObject psobject = sourceValue as PSObject;

            if (psobject == null)
            {
                error = new NotSupportedException(DataStrings.ExceptionUnsupportedSourceType(sourceValue, sourceValue.GetType()));
                return(false);
            }
            if (!SerializationTypeConverter.CanSerialize(destinationType))
            {
                error = new NotSupportedException(DataStrings.ExceptionUnsupportedTypeConversion(destinationType.FullName));
                return(false);
            }
            if (psobject.Properties["SerializationData"] == null)
            {
                error = new NotSupportedException(DataStrings.ExceptionSerializationDataAbsent);
                return(false);
            }
            object value = psobject.Properties["SerializationData"].Value;

            if (!(value is byte[]))
            {
                error = new NotSupportedException(DataStrings.ExceptionUnsupportedDataFormat(value));
                return(false);
            }
            stringValue       = psobject.ToString();
            serializationData = (value as byte[]);
            return(true);
        }
        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. 4
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. 5
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)))));
 }
Esempio n. 6
0
 public static bool CanSerialize(object obj)
 {
     return(obj != null && SerializationTypeConverter.CanSerialize(obj.GetType()));
 }