Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / Runtime / Serialization / Json / JsonCollectionDataContract.cs / 2 / JsonCollectionDataContract.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Runtime.Serialization.Json { using System.Threading; using System.Xml; using System.Security; class JsonCollectionDataContract : JsonDataContract { //// 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] JsonCollectionDataContractCriticalHelper helper; //// Critical - initializes SecurityCritical field 'helper' // Safe - doesn't leak anything // [SecurityCritical, SecurityTreatAsSafe] public JsonCollectionDataContract(CollectionDataContract traditionalDataContract) : base(new JsonCollectionDataContractCriticalHelper(traditionalDataContract)) { this.helper = base.Helper as JsonCollectionDataContractCriticalHelper; } internal JsonFormatCollectionReaderDelegate JsonFormatReaderDelegate { //// Critical - fetches the critical JsonFormatReaderDelegate property // Safe - JsonFormatReaderDelegate only needs to be protected for write // [SecurityCritical, SecurityTreatAsSafe] get { if (helper.JsonFormatReaderDelegate == null) { lock (this) { if (helper.JsonFormatReaderDelegate == null) { JsonFormatCollectionReaderDelegate tempDelegate = new JsonFormatReaderGenerator().GenerateCollectionReader(TraditionalCollectionDataContract); Thread.MemoryBarrier(); helper.JsonFormatReaderDelegate = tempDelegate; } } } return helper.JsonFormatReaderDelegate; } } internal JsonFormatGetOnlyCollectionReaderDelegate JsonFormatGetOnlyReaderDelegate { ////// Critical - fetches the critical JsonFormatGetOnlyReaderDelegate property /// Safe - JsonFormatGetOnlyReaderDelegate only needs to be protected for write; initialized in getter if null /// [SecurityCritical, SecurityTreatAsSafe] get { if (helper.JsonFormatGetOnlyReaderDelegate == null) { lock (this) { if (helper.JsonFormatGetOnlyReaderDelegate == null) { JsonFormatGetOnlyCollectionReaderDelegate tempDelegate = new JsonFormatReaderGenerator().GenerateGetOnlyCollectionReader(TraditionalCollectionDataContract); Thread.MemoryBarrier(); helper.JsonFormatGetOnlyReaderDelegate = tempDelegate; } } } return helper.JsonFormatGetOnlyReaderDelegate; } } internal JsonFormatCollectionWriterDelegate JsonFormatWriterDelegate { //// Critical - fetches the critical JsonFormatWriterDelegate property // Safe - JsonFormatWriterDelegate only needs to be protected for write // [SecurityCritical, SecurityTreatAsSafe] get { if (helper.JsonFormatWriterDelegate == null) { lock (this) { if (helper.JsonFormatWriterDelegate == null) { JsonFormatCollectionWriterDelegate tempDelegate = new JsonFormatWriterGenerator().GenerateCollectionWriter(TraditionalCollectionDataContract); Thread.MemoryBarrier(); helper.JsonFormatWriterDelegate = tempDelegate; } } } return helper.JsonFormatWriterDelegate; } } CollectionDataContract TraditionalCollectionDataContract { //// Critical - fetches the critical TraditionalCollectionDataContract property // Safe - TraditionalCollectionDataContract only needs to be protected for write // [SecurityCritical, SecurityTreatAsSafe] get { return this.helper.TraditionalCollectionDataContract; } } public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { jsonReader.Read(); object o = null; if (context.IsGetOnlyCollection) { // IsGetOnlyCollection value has already been used to create current collectiondatacontract, value can now be reset. context.IsGetOnlyCollection = false; JsonFormatGetOnlyReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, JsonGlobals.itemDictionaryString, TraditionalCollectionDataContract); } else { o = JsonFormatReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, JsonGlobals.itemDictionaryString, TraditionalCollectionDataContract); } jsonReader.ReadEndElement(); return o; } public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle) { // IsGetOnlyCollection value has already been used to create current collectiondatacontract, value can now be reset. context.IsGetOnlyCollection = false; JsonFormatWriterDelegate(jsonWriter, obj, context, TraditionalCollectionDataContract); } //// Critical - holds all state used for (de)serializing types. // since the data is cached statically, we lock down access to it. // [SecurityCritical(SecurityCriticalScope.Everything)] class JsonCollectionDataContractCriticalHelper : JsonDataContractCriticalHelper { JsonFormatCollectionReaderDelegate jsonFormatReaderDelegate; JsonFormatGetOnlyCollectionReaderDelegate jsonFormatGetOnlyReaderDelegate; JsonFormatCollectionWriterDelegate jsonFormatWriterDelegate; CollectionDataContract traditionalCollectionDataContract; public JsonCollectionDataContractCriticalHelper(CollectionDataContract traditionalDataContract) : base(traditionalDataContract) { this.traditionalCollectionDataContract = traditionalDataContract; } internal JsonFormatCollectionReaderDelegate JsonFormatReaderDelegate { get { return this.jsonFormatReaderDelegate; } set { this.jsonFormatReaderDelegate = value; } } internal JsonFormatGetOnlyCollectionReaderDelegate JsonFormatGetOnlyReaderDelegate { get { return this.jsonFormatGetOnlyReaderDelegate; } set { this.jsonFormatGetOnlyReaderDelegate = value; } } internal JsonFormatCollectionWriterDelegate JsonFormatWriterDelegate { get { return this.jsonFormatWriterDelegate; } set { this.jsonFormatWriterDelegate = value; } } internal CollectionDataContract TraditionalCollectionDataContract { get { return this.traditionalCollectionDataContract; } } } } } // 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
- Label.cs
- SqlBuilder.cs
- ExtenderHelpers.cs
- ProfileParameter.cs
- TripleDESCryptoServiceProvider.cs
- DataGridViewSortCompareEventArgs.cs
- SqlInternalConnectionSmi.cs
- ApplicationBuildProvider.cs
- PlaceHolder.cs
- DependencySource.cs
- ManualResetEvent.cs
- GeometryCollection.cs
- SqlUtils.cs
- ScriptControl.cs
- CommandLibraryHelper.cs
- OutArgument.cs
- ChineseLunisolarCalendar.cs
- ReplyAdapterChannelListener.cs
- httpstaticobjectscollection.cs
- ImageEditor.cs
- SubtreeProcessor.cs
- Attributes.cs
- VirtualPath.cs
- EnterpriseServicesHelper.cs
- ToolStripHighContrastRenderer.cs
- TextTreeNode.cs
- TabPage.cs
- HighContrastHelper.cs
- StrokeFIndices.cs
- PackageStore.cs
- CustomCategoryAttribute.cs
- InternalPermissions.cs
- DispatcherObject.cs
- ValidationErrorCollection.cs
- TaiwanCalendar.cs
- BitmapSizeOptions.cs
- xsdvalidator.cs
- ClientWindowsAuthenticationMembershipProvider.cs
- SymLanguageType.cs
- _ContextAwareResult.cs
- XPathNode.cs
- ProvidersHelper.cs
- ScriptServiceAttribute.cs
- AxisAngleRotation3D.cs
- ItemsPanelTemplate.cs
- Oid.cs
- dsa.cs
- PlanCompilerUtil.cs
- OptimalTextSource.cs
- LicenseContext.cs
- DPAPIProtectedConfigurationProvider.cs
- EntityModelSchemaGenerator.cs
- DBBindings.cs
- OdbcConnectionHandle.cs
- WaitHandle.cs
- DataGridColumn.cs
- IndexingContentUnit.cs
- XmlArrayItemAttributes.cs
- ObservableDictionary.cs
- BridgeDataReader.cs
- CheckedListBox.cs
- HostedNamedPipeTransportManager.cs
- ViewSimplifier.cs
- NavigationService.cs
- SoapEnvelopeProcessingElement.cs
- GlyphingCache.cs
- GeneralTransform2DTo3DTo2D.cs
- SpinWait.cs
- BoundsDrawingContextWalker.cs
- MultiplexingFormatMapping.cs
- SafeFileMapViewHandle.cs
- DeferredReference.cs
- MachineKeyValidationConverter.cs
- autovalidator.cs
- ToolStripPanel.cs
- TextTreeInsertUndoUnit.cs
- DropShadowBitmapEffect.cs
- _DomainName.cs
- PublisherMembershipCondition.cs
- TraceSwitch.cs
- XPathMultyIterator.cs
- TransferMode.cs
- ToolboxBitmapAttribute.cs
- SqlConnectionManager.cs
- MailDefinition.cs
- Button.cs
- TabControlToolboxItem.cs
- Crypto.cs
- Visual3D.cs
- Boolean.cs
- TagNameToTypeMapper.cs
- FileEnumerator.cs
- ResourceDescriptionAttribute.cs
- Geometry.cs
- VirtualPathProvider.cs
- PersonalizationDictionary.cs
- _ConnectOverlappedAsyncResult.cs
- ResolveMatchesCD1.cs
- Menu.cs
- DbProviderFactoriesConfigurationHandler.cs