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
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Site.cs
- ComponentDispatcher.cs
- _ConnectOverlappedAsyncResult.cs
- UMPAttributes.cs
- Logging.cs
- XmlHelper.cs
- VSDExceptions.cs
- Line.cs
- RectAnimationUsingKeyFrames.cs
- TextContainerChangedEventArgs.cs
- KeyboardDevice.cs
- ExceptionHandlersDesigner.cs
- DataGridHeadersVisibilityToVisibilityConverter.cs
- BitVec.cs
- SoundPlayer.cs
- SimpleWebHandlerParser.cs
- __TransparentProxy.cs
- DataDocumentXPathNavigator.cs
- HeaderedContentControl.cs
- CultureTable.cs
- LazyLoadBehavior.cs
- DrawItemEvent.cs
- ClickablePoint.cs
- Logging.cs
- WebPartConnectionCollection.cs
- PeerNameRecord.cs
- StylusEventArgs.cs
- RtfControls.cs
- RtfToXamlLexer.cs
- ThousandthOfEmRealDoubles.cs
- Quad.cs
- TreeChangeInfo.cs
- XmlUnspecifiedAttribute.cs
- DataGridViewCell.cs
- HttpProtocolImporter.cs
- StdRegProviderWrapper.cs
- SmiContextFactory.cs
- VirtualDirectoryMappingCollection.cs
- QilGenerator.cs
- PrintingPermissionAttribute.cs
- DataTableNewRowEvent.cs
- SqlInfoMessageEvent.cs
- Control.cs
- HtmlToClrEventProxy.cs
- ConfigsHelper.cs
- AtomServiceDocumentSerializer.cs
- Imaging.cs
- ModelItemCollectionImpl.cs
- TextPointerBase.cs
- BaseValidator.cs
- XmlSchema.cs
- DataGridViewCellMouseEventArgs.cs
- StateMachineHelpers.cs
- SimpleBitVector32.cs
- SqlDataSourceStatusEventArgs.cs
- LifetimeServices.cs
- HeaderElement.cs
- SourceSwitch.cs
- XmlSchemaComplexContent.cs
- CodeBinaryOperatorExpression.cs
- Run.cs
- OdbcDataReader.cs
- QilName.cs
- LinkedList.cs
- HandleScope.cs
- CompletionProxy.cs
- TextDpi.cs
- PkcsUtils.cs
- Crypto.cs
- WebPartEditorCancelVerb.cs
- Choices.cs
- AppSecurityManager.cs
- ImageDrawing.cs
- RegexCaptureCollection.cs
- RuleSettings.cs
- CopyNodeSetAction.cs
- PageContentCollection.cs
- LocalizedNameDescriptionPair.cs
- SoapEnumAttribute.cs
- RectAnimationClockResource.cs
- GatewayIPAddressInformationCollection.cs
- EmptyEnumerator.cs
- SoapConverter.cs
- StringFunctions.cs
- OlePropertyStructs.cs
- ControllableStoryboardAction.cs
- DataViewListener.cs
- isolationinterop.cs
- Main.cs
- TextBreakpoint.cs
- StylusCollection.cs
- RewritingValidator.cs
- DataSpaceManager.cs
- MediaSystem.cs
- Documentation.cs
- FlowDocumentPageViewerAutomationPeer.cs
- JsonReaderDelegator.cs
- HyperLinkField.cs
- ProjectionPruner.cs
- SystemTcpStatistics.cs