Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / XmlObjectSerializerContext.cs / 3 / XmlObjectSerializerContext.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Runtime.Serialization { using System; using System.Collections; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Text; using System.Xml; using System.Collections.Generic; using DataContractDictionary = System.Collections.Generic.Dictionary; using System.Security; #if USE_REFEMIT public class XmlObjectSerializerContext #else internal class XmlObjectSerializerContext #endif { protected XmlObjectSerializer serializer; protected DataContract rootTypeDataContract; internal ScopedKnownTypes scopedKnownTypes = new ScopedKnownTypes(); protected DataContractDictionary serializerKnownDataContracts; protected IList serializerKnownTypeList; /// /// Critical - We base the decision whether to Demand SerializationFormatterPermission on this value /// [SecurityCritical] bool demandedSerializationFormatterPermission; ////// Critical - We base the decision whether to Demand MemberAccess permission on this value /// [SecurityCritical] bool demandedMemberAccessPermission; int itemCount; int maxItemsInObjectGraph; StreamingContext streamingContext; bool ignoreExtensionDataObject; internal XmlObjectSerializerContext(XmlObjectSerializer serializer, int maxItemsInObjectGraph, StreamingContext streamingContext, bool ignoreExtensionDataObject) { this.serializer = serializer; this.itemCount = 1; this.maxItemsInObjectGraph = maxItemsInObjectGraph; this.streamingContext = streamingContext; this.ignoreExtensionDataObject = ignoreExtensionDataObject; } internal XmlObjectSerializerContext(DataContractSerializer serializer, DataContract rootTypeDataContract) : this(serializer, serializer.MaxItemsInObjectGraph, new StreamingContext(StreamingContextStates.All), serializer.IgnoreExtensionDataObject) { this.rootTypeDataContract = rootTypeDataContract; this.serializerKnownTypeList = serializer.knownTypeList; this.serializerKnownDataContracts = serializer.KnownDataContracts; } internal XmlObjectSerializerContext(NetDataContractSerializer serializer) : this(serializer, serializer.MaxItemsInObjectGraph, serializer.Context, serializer.IgnoreExtensionDataObject) { } internal virtual SerializationMode Mode { get { return SerializationMode.SharedContract; } } internal virtual bool IsGetOnlyCollection { get { return false; } set { } } ////// Critical - Demands SerializationFormatter permission. demanding the right permission is critical /// Safe - no data or control leaks in or out, must be callable from transparent generated IL /// [SecurityCritical, SecurityTreatAsSafe] public void DemandSerializationFormatterPermission() { if (!demandedSerializationFormatterPermission) { Globals.SerializationFormatterPermission.Demand(); demandedSerializationFormatterPermission = true; } } ////// Critical - Demands MemberAccess permission. demanding the right permission is critical /// Safe - no data or control leaks in or out, must be callable from transparent generated IL /// [SecurityCritical, SecurityTreatAsSafe] public void DemandMemberAccessPermission() { if (!demandedMemberAccessPermission) { Globals.MemberAccessPermission.Demand(); demandedMemberAccessPermission = true; } } #if USE_REFEMIT public StreamingContext GetStreamingContext() #else internal StreamingContext GetStreamingContext() #endif { return streamingContext; } #if USE_REFEMIT public void IncrementItemCount(int count) #else internal void IncrementItemCount(int count) #endif { if (count > maxItemsInObjectGraph - itemCount) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.ExceededMaxItemsQuota, maxItemsInObjectGraph))); itemCount += count; } internal int RemainingItemCount { get { return maxItemsInObjectGraph - itemCount; } } internal bool IgnoreExtensionDataObject { get { return ignoreExtensionDataObject; } } internal DataContract GetDataContract(Type type) { return GetDataContract(type.TypeHandle, type); } internal virtual DataContract GetDataContract(RuntimeTypeHandle typeHandle, Type type) { if (IsGetOnlyCollection) { return DataContract.GetGetOnlyCollectionDataContract(DataContract.GetId(typeHandle), typeHandle, type, Mode); } else { return DataContract.GetDataContract(typeHandle, type, Mode); } } internal virtual DataContract GetDataContractSkipValidation(int typeId, RuntimeTypeHandle typeHandle, Type type) { if (IsGetOnlyCollection) { return DataContract.GetGetOnlyCollectionDataContractSkipValidation(typeId, typeHandle, type); } else { return DataContract.GetDataContractSkipValidation(typeId, typeHandle, type); } } internal virtual DataContract GetDataContract(int id, RuntimeTypeHandle typeHandle) { if (IsGetOnlyCollection) { return DataContract.GetGetOnlyCollectionDataContract(id, typeHandle, null /*type*/, Mode); } else { return DataContract.GetDataContract(id, typeHandle, Mode); } } internal virtual void CheckIfTypeSerializable(Type memberType, bool isMemberTypeSerializable) { if (!isMemberTypeSerializable) throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.GetString(SR.TypeNotSerializable, memberType))); } internal virtual Type GetSurrogatedType(Type type) { return type; } DataContractDictionary SerializerKnownDataContracts { get { // This field must be initialized during construction by serializers using data contracts. return this.serializerKnownDataContracts; } } DataContract GetDataContractFromSerializerKnownTypes(XmlQualifiedName qname) { DataContractDictionary serializerKnownDataContracts = this.SerializerKnownDataContracts; if (serializerKnownDataContracts == null) return null; DataContract outDataContract; return serializerKnownDataContracts.TryGetValue(qname, out outDataContract) ? outDataContract : null; } internal static DataContractDictionary GetDataContractsForKnownTypes(IListknownTypeList) { if (knownTypeList == null) return null; DataContractDictionary dataContracts = new DataContractDictionary(); Dictionary typesChecked = new Dictionary (); for (int i = 0; i < knownTypeList.Count; i++) { Type knownType = knownTypeList[i]; if (knownType == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.NullKnownType, "knownTypes"))); DataContract.CheckAndAdd(knownType, typesChecked, ref dataContracts); } return dataContracts; } protected DataContract ResolveDataContractFromKnownTypes(string typeName, string typeNs, DataContract memberTypeContract) { DataContract dataContract = PrimitiveDataContract.GetPrimitiveDataContract(typeName, typeNs); if (dataContract == null) { XmlQualifiedName qname = new XmlQualifiedName(typeName, typeNs); dataContract = scopedKnownTypes.GetDataContract(qname); if (dataContract == null) { dataContract = GetDataContractFromSerializerKnownTypes(qname); } if (dataContract == null && memberTypeContract != null && !memberTypeContract.UnderlyingType.IsInterface && memberTypeContract.StableName == qname) { dataContract = memberTypeContract; } if (dataContract == null && rootTypeDataContract != null) { if (rootTypeDataContract.StableName == qname) dataContract = rootTypeDataContract; else { CollectionDataContract collectionContract = rootTypeDataContract as CollectionDataContract; while (collectionContract != null) { DataContract itemContract = GetDataContract(GetSurrogatedType(collectionContract.ItemType)); if (itemContract.StableName == qname) { dataContract = itemContract; break; } collectionContract = itemContract as CollectionDataContract; } } } } return dataContract; } } } // 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
- RegexBoyerMoore.cs
- SR.cs
- ForeignKeyConstraint.cs
- OptimalTextSource.cs
- OrCondition.cs
- WSFederationHttpBinding.cs
- SimpleTableProvider.cs
- InputLanguageEventArgs.cs
- TemplateEditingService.cs
- Debugger.cs
- LogExtent.cs
- TextCollapsingProperties.cs
- OleDbConnection.cs
- OutputCacheProfileCollection.cs
- EventPrivateKey.cs
- MenuItemBinding.cs
- RemoteWebConfigurationHostServer.cs
- DataKey.cs
- XmlRawWriterWrapper.cs
- DocumentScope.cs
- InlineUIContainer.cs
- TextSearch.cs
- PolyLineSegmentFigureLogic.cs
- InputScopeConverter.cs
- InternalBase.cs
- SafeRegistryKey.cs
- Object.cs
- SQLInt32.cs
- FileDialog.cs
- MappingSource.cs
- ListChangedEventArgs.cs
- WsdlInspector.cs
- DataRowComparer.cs
- XmlNodeList.cs
- OdbcConnectionString.cs
- ProviderConnectionPoint.cs
- ButtonFlatAdapter.cs
- CustomError.cs
- StatusBarAutomationPeer.cs
- ImplicitInputBrush.cs
- SqlInfoMessageEvent.cs
- formatter.cs
- SmtpSection.cs
- TemplateBindingExtension.cs
- WorkItem.cs
- KeyValueSerializer.cs
- CodeAttributeDeclarationCollection.cs
- SpeechSeg.cs
- RotateTransform3D.cs
- _LocalDataStoreMgr.cs
- AliasGenerator.cs
- InstanceKeyCollisionException.cs
- XsdCachingReader.cs
- DesignerTransaction.cs
- GridEntry.cs
- XmlBaseReader.cs
- JavaScriptSerializer.cs
- XmlTextAttribute.cs
- EmptyEnumerator.cs
- InertiaExpansionBehavior.cs
- TrailingSpaceComparer.cs
- WhitespaceRuleLookup.cs
- TreeChangeInfo.cs
- ReachDocumentReferenceSerializerAsync.cs
- WindowsTab.cs
- SectionInformation.cs
- DataSourceDescriptorCollection.cs
- assemblycache.cs
- SiteOfOriginContainer.cs
- xdrvalidator.cs
- CodeExpressionCollection.cs
- TextEffect.cs
- ViewDesigner.cs
- ProfilePropertySettingsCollection.cs
- ActivityUtilities.cs
- ChannelServices.cs
- SortKey.cs
- ComplusTypeValidator.cs
- TextProviderWrapper.cs
- ChangeConflicts.cs
- EventBindingService.cs
- InfiniteIntConverter.cs
- WmlValidationSummaryAdapter.cs
- BoolLiteral.cs
- BrowserInteropHelper.cs
- ModelVisual3D.cs
- ListItemCollection.cs
- _ConnectOverlappedAsyncResult.cs
- XpsSerializationManagerAsync.cs
- UnsupportedPolicyOptionsException.cs
- BasicHttpBindingElement.cs
- SqlMultiplexer.cs
- TableAdapterManagerMethodGenerator.cs
- IsolatedStoragePermission.cs
- GlobalItem.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- ReadOnlyTernaryTree.cs
- WriteStateInfoBase.cs
- ObjectDataSourceFilteringEventArgs.cs
- MLangCodePageEncoding.cs