Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Serializer / ActivitySurrogateSelector.cs / 1305376 / ActivitySurrogateSelector.cs
namespace System.Workflow.ComponentModel.Serialization
{
using System;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Permissions;
public sealed class ActivitySurrogateSelector : SurrogateSelector
{
private ActivitySurrogate activitySurrogate = new ActivitySurrogate();
private ActivityExecutorSurrogate activityExecutorSurrogate = new ActivityExecutorSurrogate();
private ObjectSurrogate objectSurrogate = new ObjectSurrogate();
private DependencyStoreSurrogate dependencyStoreSurrogate = new DependencyStoreSurrogate();
private XmlDocumentSurrogate domDocSurrogate = new XmlDocumentSurrogate();
private DictionarySurrogate dictionarySurrogate = new DictionarySurrogate();
private GenericQueueSurrogate genericqueueSurrogate = new GenericQueueSurrogate();
private QueueSurrogate queueSurrogate = new QueueSurrogate();
private ListSurrogate listSurrogate = new ListSurrogate();
private SimpleTypesSurrogate simpleTypesSurrogate = new SimpleTypesSurrogate();
private static ActivitySurrogateSelector defaultActivitySurrogateSelector = new ActivitySurrogateSelector();
private static Dictionary surrogateCache = new Dictionary();
public static ActivitySurrogateSelector Default
{
get
{
return defaultActivitySurrogateSelector;
}
}
public override ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
{
if (type == null)
throw new ArgumentNullException("type");
selector = this;
ISerializationSurrogate result = null;
bool found;
lock (surrogateCache)
{
found = surrogateCache.TryGetValue(type, out result);
}
if (found)
{
return result == null ? base.GetSurrogate(type, context, out selector) : result;
}
// if type is assignable to activity, then return the surrogate
if (typeof(Activity).IsAssignableFrom(type))
{
result = this.activitySurrogate;
}
else if (typeof(ActivityExecutor).IsAssignableFrom(type))
{
result = this.activityExecutorSurrogate;
}
else if (typeof(IDictionary).IsAssignableFrom(type))
{
result = this.dependencyStoreSurrogate;
}
else if (typeof(XmlDocument).IsAssignableFrom(type))
{
result = this.domDocSurrogate;
}
/*else if (type.IsGenericType)
{
Type genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(Dictionary<,>))
{
result = this.dictionarySurrogate;
}
else if (genericType == typeof(Queue<>))
{
result = this.genericqueueSurrogate;
}
else if (genericType == typeof(List<>))
{
result = this.listSurrogate;
}
}*/
else if (typeof(Queue) == type)
{
result = this.queueSurrogate;
}
else if (typeof(Guid) == type)
{
result = this.simpleTypesSurrogate;
}
//
else if (typeof(ActivityBind).IsAssignableFrom(type))
{
result = this.objectSurrogate;
}
//
else if (typeof(DependencyObject).IsAssignableFrom(type))
{
result = this.objectSurrogate;
}
lock (surrogateCache)
{
surrogateCache[type] = result;
}
return result == null ? base.GetSurrogate(type, context, out selector) : result;
}
private sealed class ObjectSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
info.AddValue("type", obj.GetType());
string[] names = null;
MemberInfo[] members = FormatterServicesNoSerializableCheck.GetSerializableMembers(obj.GetType(), out names);
object[] memberDatas = FormatterServices.GetObjectData(obj, members);
info.AddValue("memberDatas", memberDatas);
info.SetType(typeof(ObjectSerializedRef));
}
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
return null;
}
[Serializable]
private sealed class ObjectSerializedRef : IObjectReference, IDeserializationCallback
{
private Type type = null;
private object[] memberDatas = null;
[NonSerialized]
private object returnedObject = null;
Object IObjectReference.GetRealObject(StreamingContext context)
{
if (this.returnedObject == null)
this.returnedObject = FormatterServices.GetUninitializedObject(this.type);
return this.returnedObject;
}
void IDeserializationCallback.OnDeserialization(object sender)
{
if (this.returnedObject != null)
{
string[] names = null;
MemberInfo[] members = FormatterServicesNoSerializableCheck.GetSerializableMembers(this.type, out names);
FormatterServices.PopulateObjectMembers(this.returnedObject, members, this.memberDatas);
this.returnedObject = null;
}
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Workflow.ComponentModel.Serialization
{
using System;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Permissions;
public sealed class ActivitySurrogateSelector : SurrogateSelector
{
private ActivitySurrogate activitySurrogate = new ActivitySurrogate();
private ActivityExecutorSurrogate activityExecutorSurrogate = new ActivityExecutorSurrogate();
private ObjectSurrogate objectSurrogate = new ObjectSurrogate();
private DependencyStoreSurrogate dependencyStoreSurrogate = new DependencyStoreSurrogate();
private XmlDocumentSurrogate domDocSurrogate = new XmlDocumentSurrogate();
private DictionarySurrogate dictionarySurrogate = new DictionarySurrogate();
private GenericQueueSurrogate genericqueueSurrogate = new GenericQueueSurrogate();
private QueueSurrogate queueSurrogate = new QueueSurrogate();
private ListSurrogate listSurrogate = new ListSurrogate();
private SimpleTypesSurrogate simpleTypesSurrogate = new SimpleTypesSurrogate();
private static ActivitySurrogateSelector defaultActivitySurrogateSelector = new ActivitySurrogateSelector();
private static Dictionary surrogateCache = new Dictionary();
public static ActivitySurrogateSelector Default
{
get
{
return defaultActivitySurrogateSelector;
}
}
public override ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
{
if (type == null)
throw new ArgumentNullException("type");
selector = this;
ISerializationSurrogate result = null;
bool found;
lock (surrogateCache)
{
found = surrogateCache.TryGetValue(type, out result);
}
if (found)
{
return result == null ? base.GetSurrogate(type, context, out selector) : result;
}
// if type is assignable to activity, then return the surrogate
if (typeof(Activity).IsAssignableFrom(type))
{
result = this.activitySurrogate;
}
else if (typeof(ActivityExecutor).IsAssignableFrom(type))
{
result = this.activityExecutorSurrogate;
}
else if (typeof(IDictionary).IsAssignableFrom(type))
{
result = this.dependencyStoreSurrogate;
}
else if (typeof(XmlDocument).IsAssignableFrom(type))
{
result = this.domDocSurrogate;
}
/*else if (type.IsGenericType)
{
Type genericType = type.GetGenericTypeDefinition();
if (genericType == typeof(Dictionary<,>))
{
result = this.dictionarySurrogate;
}
else if (genericType == typeof(Queue<>))
{
result = this.genericqueueSurrogate;
}
else if (genericType == typeof(List<>))
{
result = this.listSurrogate;
}
}*/
else if (typeof(Queue) == type)
{
result = this.queueSurrogate;
}
else if (typeof(Guid) == type)
{
result = this.simpleTypesSurrogate;
}
//
else if (typeof(ActivityBind).IsAssignableFrom(type))
{
result = this.objectSurrogate;
}
//
else if (typeof(DependencyObject).IsAssignableFrom(type))
{
result = this.objectSurrogate;
}
lock (surrogateCache)
{
surrogateCache[type] = result;
}
return result == null ? base.GetSurrogate(type, context, out selector) : result;
}
private sealed class ObjectSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
info.AddValue("type", obj.GetType());
string[] names = null;
MemberInfo[] members = FormatterServicesNoSerializableCheck.GetSerializableMembers(obj.GetType(), out names);
object[] memberDatas = FormatterServices.GetObjectData(obj, members);
info.AddValue("memberDatas", memberDatas);
info.SetType(typeof(ObjectSerializedRef));
}
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
return null;
}
[Serializable]
private sealed class ObjectSerializedRef : IObjectReference, IDeserializationCallback
{
private Type type = null;
private object[] memberDatas = null;
[NonSerialized]
private object returnedObject = null;
Object IObjectReference.GetRealObject(StreamingContext context)
{
if (this.returnedObject == null)
this.returnedObject = FormatterServices.GetUninitializedObject(this.type);
return this.returnedObject;
}
void IDeserializationCallback.OnDeserialization(object sender)
{
if (this.returnedObject != null)
{
string[] names = null;
MemberInfo[] members = FormatterServicesNoSerializableCheck.GetSerializableMembers(this.type, out names);
FormatterServices.PopulateObjectMembers(this.returnedObject, members, this.memberDatas);
this.returnedObject = null;
}
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TcpConnectionPoolSettings.cs
- TableSectionStyle.cs
- _AcceptOverlappedAsyncResult.cs
- WindowInteractionStateTracker.cs
- DateTimePicker.cs
- HtmlContainerControl.cs
- InstallerTypeAttribute.cs
- NameValueFileSectionHandler.cs
- CookieParameter.cs
- SystemIcmpV6Statistics.cs
- SqlConnectionString.cs
- EnvelopedPkcs7.cs
- GridProviderWrapper.cs
- HtmlInputPassword.cs
- CryptoProvider.cs
- InfoCardClaim.cs
- GroupBox.cs
- DecimalStorage.cs
- BufferAllocator.cs
- MessageDecoder.cs
- ProfileParameter.cs
- securitycriticaldataformultiplegetandset.cs
- Matrix3D.cs
- handlecollector.cs
- DbParameterHelper.cs
- PopupEventArgs.cs
- TypeForwardedToAttribute.cs
- SinglePageViewer.cs
- SmtpFailedRecipientException.cs
- GC.cs
- SymbolType.cs
- RemotingConfigParser.cs
- TextMarkerSource.cs
- CryptoConfig.cs
- SvcMapFile.cs
- RetrieveVirtualItemEventArgs.cs
- DataGridViewComboBoxEditingControl.cs
- ProfileSettings.cs
- WebPartVerbsEventArgs.cs
- RadioButtonFlatAdapter.cs
- ButtonFieldBase.cs
- PageParserFilter.cs
- MarginsConverter.cs
- TrackBarRenderer.cs
- MarshalByValueComponent.cs
- WizardStepBase.cs
- XamlTreeBuilder.cs
- HttpRuntimeSection.cs
- TextTreeRootNode.cs
- NullToBooleanConverter.cs
- TableParaClient.cs
- TemplateBaseAction.cs
- XmlSchemaSet.cs
- RTTrackingProfile.cs
- PasswordRecovery.cs
- MethodCallTranslator.cs
- RegistrationServices.cs
- CounterCreationDataConverter.cs
- _HTTPDateParse.cs
- COMException.cs
- CqlBlock.cs
- ProbeDuplexCD1AsyncResult.cs
- DataTransferEventArgs.cs
- ModuleConfigurationInfo.cs
- LiteralControl.cs
- InvalidAsynchronousStateException.cs
- DbBuffer.cs
- InputGestureCollection.cs
- EntityChangedParams.cs
- RecipientServiceModelSecurityTokenRequirement.cs
- TreeViewTemplateSelector.cs
- TypeLoadException.cs
- DataTableCollection.cs
- BitArray.cs
- DataControlField.cs
- ConstraintCollection.cs
- ProfilePropertySettingsCollection.cs
- HtmlTitle.cs
- _HeaderInfo.cs
- ConnectionPoolManager.cs
- PrimitiveType.cs
- TemplateNameScope.cs
- SelectedDatesCollection.cs
- DataMisalignedException.cs
- Int64AnimationUsingKeyFrames.cs
- XmlUtil.cs
- AdPostCacheSubstitution.cs
- ExtendedProtectionPolicyTypeConverter.cs
- TypedReference.cs
- Metadata.cs
- DataSourceHelper.cs
- BezierSegment.cs
- MenuItem.cs
- PropertyGrid.cs
- StaticContext.cs
- ObjectManager.cs
- XamlPathDataSerializer.cs
- DynamicDataManager.cs
- RequestDescription.cs
- DragDeltaEventArgs.cs