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
- FrugalList.cs
- UIntPtr.cs
- AddInEnvironment.cs
- TypeExtensionConverter.cs
- MembershipUser.cs
- MetadataSerializer.cs
- ListBox.cs
- Timer.cs
- CodeNamespaceCollection.cs
- PersonalizableAttribute.cs
- ChameleonKey.cs
- RSAOAEPKeyExchangeFormatter.cs
- NameService.cs
- ProcessThread.cs
- SendDesigner.xaml.cs
- PixelFormatConverter.cs
- WebPartCatalogAddVerb.cs
- WebPartAuthorizationEventArgs.cs
- BoundColumn.cs
- Deserializer.cs
- EntityDataSourceEntitySetNameItem.cs
- TreeView.cs
- NamedPermissionSet.cs
- ContainerCodeDomSerializer.cs
- MimeFormImporter.cs
- ShapingWorkspace.cs
- DesignerView.xaml.cs
- SerialPort.cs
- FileDataSourceCache.cs
- Rotation3DKeyFrameCollection.cs
- TimeoutTimer.cs
- ProfilePropertyMetadata.cs
- SettingsAttributes.cs
- EventToken.cs
- SoapSchemaExporter.cs
- WpfWebRequestHelper.cs
- MetafileHeader.cs
- ColorPalette.cs
- ConcatQueryOperator.cs
- CodeCastExpression.cs
- Label.cs
- ECDsa.cs
- HtmlInputRadioButton.cs
- Rect.cs
- KeyNotFoundException.cs
- RectKeyFrameCollection.cs
- ObjectView.cs
- LineProperties.cs
- DataViewListener.cs
- QueryOpcode.cs
- PeerCustomResolverBindingElement.cs
- NullableLongMinMaxAggregationOperator.cs
- Policy.cs
- InputReport.cs
- SQLBinaryStorage.cs
- CollectionDataContract.cs
- GridViewDeleteEventArgs.cs
- CommandBindingCollection.cs
- TreeViewCancelEvent.cs
- DocumentReference.cs
- EntityContainerEmitter.cs
- StylusButton.cs
- UpdateTracker.cs
- BaseValidatorDesigner.cs
- RenderDataDrawingContext.cs
- UdpChannelListener.cs
- EncoderBestFitFallback.cs
- StringReader.cs
- Point.cs
- precedingsibling.cs
- _FtpControlStream.cs
- Char.cs
- CorePropertiesFilter.cs
- HttpServerUtilityWrapper.cs
- SizeLimitedCache.cs
- MessageDescriptionCollection.cs
- TransformGroup.cs
- LexicalChunk.cs
- BindUriHelper.cs
- SqlParameterCollection.cs
- DummyDataSource.cs
- DeflateStreamAsyncResult.cs
- AttachmentService.cs
- CacheOutputQuery.cs
- ProxyWebPartConnectionCollection.cs
- WebPartAddingEventArgs.cs
- ControlEvent.cs
- SiteOfOriginContainer.cs
- LabelAutomationPeer.cs
- FormClosedEvent.cs
- HttpCacheVaryByContentEncodings.cs
- RuleAction.cs
- ReadOnlyMetadataCollection.cs
- ByteStreamGeometryContext.cs
- AttributeEmitter.cs
- BamlBinaryWriter.cs
- XAMLParseException.cs
- Adorner.cs
- SchemaImporterExtensionsSection.cs
- ImmutableDispatchRuntime.cs