Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / SurrogateDataContract.cs / 2 / SurrogateDataContract.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Runtime.Serialization { using System; using System.Reflection; using System.Xml; using DataContractDictionary=System.Collections.Generic.Dictionary; using System.Xml.Serialization; using System.Security; internal sealed class SurrogateDataContract : DataContract { /// /// Critical - holds instance of CriticalHelper which keeps state that is cached statically for serialization. /// Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] SurrogateDataContractCriticalHelper helper; ////// Critical - initializes SecurityCritical field 'helper' /// Safe - doesn't leak anything /// [SecurityCritical, SecurityTreatAsSafe] internal SurrogateDataContract(Type type, ISerializationSurrogate serializationSurrogate) : base(new SurrogateDataContractCriticalHelper(type, serializationSurrogate)) { helper = base.Helper as SurrogateDataContractCriticalHelper; } internal ISerializationSurrogate SerializationSurrogate { ////// Critical - fetches the critical serializationSurrogate field /// Safe - serializationSurrogate only needs to be protected for write /// [SecurityCritical, SecurityTreatAsSafe] get { return helper.SerializationSurrogate; } } public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context) { SerializationInfo serInfo = new SerializationInfo(UnderlyingType, XmlObjectSerializer.FormatterConverter); SerializationSurrogate.GetObjectData(obj, serInfo, context.GetStreamingContext()); context.WriteSerializationInfo(xmlWriter, UnderlyingType, serInfo); } public override object ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) { xmlReader.Read(); Type objType = UnderlyingType; object obj = objType.IsArray ? Array.CreateInstance(objType.GetElementType(), 0) : FormatterServices.GetUninitializedObject(objType); context.AddNewObject(obj); string objectId = context.GetObjectId(); SerializationInfo serInfo = context.ReadSerializationInfo(xmlReader, objType); object newObj = SerializationSurrogate.SetObjectData(obj, serInfo, context.GetStreamingContext(), null); if (newObj == null) newObj = obj; if (newObj is IDeserializationCallback) ((IDeserializationCallback)newObj).OnDeserialization(null); if (newObj is IObjectReference) newObj = ((IObjectReference)newObj).GetRealObject(context.GetStreamingContext()); context.ReplaceDeserializedObject(objectId, obj, newObj); xmlReader.ReadEndElement(); return newObj; } ////// Critical - holds all state used for for (de)serializing with ISerializationSurrogate. /// since it accesses data on the base type that is cached statically, we lock down access to it. /// [SecurityCritical(SecurityCriticalScope.Everything)] class SurrogateDataContractCriticalHelper : DataContract.DataContractCriticalHelper { ISerializationSurrogate serializationSurrogate; internal SurrogateDataContractCriticalHelper(Type type, ISerializationSurrogate serializationSurrogate) : base(type) { this.serializationSurrogate = serializationSurrogate; string name, ns; DataContract.GetDefaultStableName(DataContract.GetClrTypeFullName(type), out name, out ns); SetDataContractName(CreateQualifiedName(name, ns)); } internal ISerializationSurrogate SerializationSurrogate { get { return serializationSurrogate; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EncodingDataItem.cs
- TrackingRecordPreFilter.cs
- WindowsListViewItemCheckBox.cs
- NativeMethods.cs
- XmlDataSource.cs
- RoleManagerEventArgs.cs
- ConfigXmlComment.cs
- LineGeometry.cs
- DocumentXmlWriter.cs
- BlurBitmapEffect.cs
- ScaleTransform3D.cs
- VBIdentifierNameEditor.cs
- AssemblyBuilder.cs
- DropDownHolder.cs
- CaseExpr.cs
- EncodingTable.cs
- PersonalizableTypeEntry.cs
- versioninfo.cs
- CheckBoxPopupAdapter.cs
- SqlPersonalizationProvider.cs
- SHA512CryptoServiceProvider.cs
- DateTimeConstantAttribute.cs
- SaveFileDialog.cs
- Visual3D.cs
- RC2CryptoServiceProvider.cs
- AsynchronousChannel.cs
- Header.cs
- DataViewManagerListItemTypeDescriptor.cs
- TextChange.cs
- Vector3DCollection.cs
- diagnosticsswitches.cs
- TextFindEngine.cs
- SystemResourceHost.cs
- SystemParameters.cs
- RemotingException.cs
- MemberHolder.cs
- SQLBinaryStorage.cs
- MissingMemberException.cs
- _ListenerResponseStream.cs
- TimeSpanValidatorAttribute.cs
- DrawListViewSubItemEventArgs.cs
- Inline.cs
- BrowserCapabilitiesFactory35.cs
- DataBinding.cs
- IntegerValidator.cs
- DelegatingHeader.cs
- NameValuePermission.cs
- PrintingPermission.cs
- SplitContainer.cs
- HtmlInputReset.cs
- SmiContext.cs
- ZipArchive.cs
- AnnotationStore.cs
- DataErrorValidationRule.cs
- XmlSchemaValidationException.cs
- DocumentApplication.cs
- ConsoleKeyInfo.cs
- ScriptReferenceBase.cs
- ErrorEventArgs.cs
- PointLight.cs
- TreeViewImageKeyConverter.cs
- XdrBuilder.cs
- MetabaseServerConfig.cs
- ProfileModule.cs
- SQLMoneyStorage.cs
- CursorInteropHelper.cs
- X509RecipientCertificateServiceElement.cs
- FileDetails.cs
- TreeNodeCollection.cs
- AuthenticationModuleElement.cs
- DataGridViewAutoSizeModeEventArgs.cs
- MessageSecurityTokenVersion.cs
- DesignBindingPicker.cs
- ExecutionEngineException.cs
- Psha1DerivedKeyGeneratorHelper.cs
- SmiEventSink.cs
- UserUseLicenseDictionaryLoader.cs
- IPCCacheManager.cs
- Mapping.cs
- EmissiveMaterial.cs
- RemoveStoryboard.cs
- AVElementHelper.cs
- SaveFileDialog.cs
- MeshGeometry3D.cs
- DbDataRecord.cs
- TextFormatterHost.cs
- TimeSpanStorage.cs
- ResponseStream.cs
- EntityStoreSchemaGenerator.cs
- RegisteredArrayDeclaration.cs
- ProcessHostServerConfig.cs
- Parser.cs
- NumericUpDownAcceleration.cs
- XmlCDATASection.cs
- SimpleMailWebEventProvider.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- CompiledQueryCacheKey.cs
- assemblycache.cs
- Binding.cs
- XmlNamespaceDeclarationsAttribute.cs