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
- XmlSchemaSimpleTypeList.cs
- AppliedDeviceFiltersEditor.cs
- SerialStream.cs
- columnmapfactory.cs
- WriteableBitmap.cs
- SiteMapNodeCollection.cs
- BaseDataList.cs
- FilterQuery.cs
- TemplateColumn.cs
- NTAccount.cs
- HintTextConverter.cs
- GroupStyle.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- LocalizableAttribute.cs
- SecurityDescriptor.cs
- TypeEnumerableViewSchema.cs
- ClientReliableChannelBinder.cs
- XMLSchema.cs
- InstrumentationTracker.cs
- TreeNodeStyle.cs
- BinaryObjectWriter.cs
- Recipient.cs
- SqlCacheDependencySection.cs
- XmlSchemaComplexType.cs
- securitycriticaldataClass.cs
- GridEntryCollection.cs
- TdsValueSetter.cs
- ComponentEditorForm.cs
- ApplyHostConfigurationBehavior.cs
- JournalEntry.cs
- StylusLogic.cs
- Geometry.cs
- Trace.cs
- FillErrorEventArgs.cs
- DrawingVisual.cs
- EtwTrace.cs
- ServiceProviders.cs
- ConditionChanges.cs
- HtmlValidatorAdapter.cs
- LogEntryDeserializer.cs
- SEHException.cs
- RequestCachePolicy.cs
- CryptoApi.cs
- ICspAsymmetricAlgorithm.cs
- WebPartConnectionsConnectVerb.cs
- LinqDataSourceView.cs
- NamespaceList.cs
- TextEvent.cs
- SiteMapHierarchicalDataSourceView.cs
- LocatorPartList.cs
- NotImplementedException.cs
- RuleSetDialog.Designer.cs
- MouseGestureConverter.cs
- AssociatedControlConverter.cs
- TextEditorLists.cs
- CodeAccessPermission.cs
- mediaeventshelper.cs
- CompiledRegexRunnerFactory.cs
- PartialArray.cs
- NotSupportedException.cs
- SiteMapDataSource.cs
- ActionMessageFilterTable.cs
- Clause.cs
- Baml2006SchemaContext.cs
- HostedHttpRequestAsyncResult.cs
- RsaKeyIdentifierClause.cs
- FilterException.cs
- ServerValidateEventArgs.cs
- InputGestureCollection.cs
- BitVector32.cs
- XmlReflectionImporter.cs
- WizardPanel.cs
- SerializerDescriptor.cs
- ObjectAnimationUsingKeyFrames.cs
- QuerySafeNavigator.cs
- CodeThrowExceptionStatement.cs
- ResXResourceSet.cs
- WindowHideOrCloseTracker.cs
- CacheRequest.cs
- ResourceReferenceExpressionConverter.cs
- CodePageUtils.cs
- DataKey.cs
- ToolBar.cs
- PropertyGridView.cs
- ParameterRefs.cs
- COM2PropertyPageUITypeConverter.cs
- NamedObject.cs
- EventProvider.cs
- FamilyMapCollection.cs
- BinaryWriter.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- MatrixAnimationUsingKeyFrames.cs
- MailWebEventProvider.cs
- ListItemConverter.cs
- Utils.cs
- WebPartUserCapability.cs
- Condition.cs
- GregorianCalendarHelper.cs
- CompiledRegexRunner.cs
- SchemaMapping.cs