public object GetObjectToSerialize(object obj, Type targetType) { if ((targetType == typeof(object)) || targetType.IsInterface) { IPersistStream persistableObject = obj as IPersistStream; if (persistableObject != null) { PersistStreamTypeWrapper wrapper = new PersistStreamTypeWrapper(); persistableObject.GetClassID(out wrapper.clsid); wrapper.dataStream = PersistHelper.PersistIPersistStreamToByteArray(persistableObject); return(wrapper); } if (targetType.IsInterface) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("TargetObjectDoesNotSupportIPersistStream"))); } } return(obj); }
public object GetObjectToSerialize(object obj, Type targetType) { if (targetType == typeof(object) || (targetType.IsInterface)) { IPersistStream streamableObject = obj as IPersistStream; if (null != streamableObject) { PersistStreamTypeWrapper objToSerialize = new PersistStreamTypeWrapper(); streamableObject.GetClassID(out objToSerialize.clsid); objToSerialize.dataStream = PersistHelper.PersistIPersistStreamToByteArray(streamableObject); return(objToSerialize); } if (targetType.IsInterface) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TargetObjectDoesNotSupportIPersistStream))); } return(obj); } return(obj); }
public object GetDeserializedObject(object obj, Type targetType) { if ((targetType == typeof(object)) || targetType.IsInterface) { PersistStreamTypeWrapper wrapper = obj as PersistStreamTypeWrapper; if (wrapper != null) { if (!this.IsAllowedClass(wrapper.clsid)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("NotAllowedPersistableCLSID", new object[] { wrapper.clsid.ToString("B") }))); } return(PersistHelper.ActivateAndLoadFromByteStream(wrapper.clsid, wrapper.dataStream)); } if (targetType.IsInterface) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("TargetTypeIsAnIntefaceButCorrespoindingTypeIsNotPersistStreamTypeWrapper"))); } } return(obj); }
public object GetDeserializedObject(object obj, Type targetType) { if (targetType == typeof(object) || (targetType.IsInterface)) { PersistStreamTypeWrapper streamWrapper = obj as PersistStreamTypeWrapper; if (null != streamWrapper) { if (IsAllowedClass(streamWrapper.clsid)) { return(PersistHelper.ActivateAndLoadFromByteStream(streamWrapper.clsid, streamWrapper.dataStream)); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.NotAllowedPersistableCLSID, streamWrapper.clsid.ToString("B")))); } } if (targetType.IsInterface) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.TargetTypeIsAnIntefaceButCorrespoindingTypeIsNotPersistStreamTypeWrapper))); } } return(obj); }