Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / Json / JsonEnumDataContract.cs / 1305376 / JsonEnumDataContract.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Runtime.Serialization.Json { using System.Xml; using System.Security; class JsonEnumDataContract : JsonDataContract { [Fx.Tag.SecurityNote(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] JsonEnumDataContractCriticalHelper helper; [Fx.Tag.SecurityNote(Critical = "Initializes SecurityCritical field 'helper'.", Safe = "Doesn't leak anything.")] [SecuritySafeCritical] public JsonEnumDataContract(EnumDataContract traditionalDataContract) : base(new JsonEnumDataContractCriticalHelper(traditionalDataContract)) { this.helper = base.Helper as JsonEnumDataContractCriticalHelper; } public bool IsULong { [Fx.Tag.SecurityNote(Critical = "Fetches the critical IsULong property.", Safe = "IsULong only needs to be protected for write.")] [SecuritySafeCritical] get { return this.helper.IsULong; } } public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object enumValue; if (IsULong) { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsUnsignedLong()); } else { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsLong()); } if (context != null) { context.AddNewObject(enumValue); } return enumValue; } public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle) { if (IsULong) { jsonWriter.WriteUnsignedLong(((IConvertible) obj).ToUInt64(null)); } else { jsonWriter.WriteLong(((IConvertible) obj).ToInt64(null)); } } [Fx.Tag.SecurityNote(Critical = "Holds all state used for (de)serializing types." + "Since the data is cached statically, we lock down access to it.")] #pragma warning disable 618 // have not moved to the v4 security model yet [SecurityCritical(SecurityCriticalScope.Everything)] #pragma warning restore 618 class JsonEnumDataContractCriticalHelper : JsonDataContractCriticalHelper { bool isULong; public JsonEnumDataContractCriticalHelper(EnumDataContract traditionalEnumDataContract) : base(traditionalEnumDataContract) { isULong = traditionalEnumDataContract.IsULong; } public bool IsULong { get { return this.isULong; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Runtime.Serialization.Json { using System.Xml; using System.Security; class JsonEnumDataContract : JsonDataContract { [Fx.Tag.SecurityNote(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] JsonEnumDataContractCriticalHelper helper; [Fx.Tag.SecurityNote(Critical = "Initializes SecurityCritical field 'helper'.", Safe = "Doesn't leak anything.")] [SecuritySafeCritical] public JsonEnumDataContract(EnumDataContract traditionalDataContract) : base(new JsonEnumDataContractCriticalHelper(traditionalDataContract)) { this.helper = base.Helper as JsonEnumDataContractCriticalHelper; } public bool IsULong { [Fx.Tag.SecurityNote(Critical = "Fetches the critical IsULong property.", Safe = "IsULong only needs to be protected for write.")] [SecuritySafeCritical] get { return this.helper.IsULong; } } public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { object enumValue; if (IsULong) { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsUnsignedLong()); } else { enumValue = Enum.ToObject(TraditionalDataContract.UnderlyingType, jsonReader.ReadElementContentAsLong()); } if (context != null) { context.AddNewObject(enumValue); } return enumValue; } public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle) { if (IsULong) { jsonWriter.WriteUnsignedLong(((IConvertible) obj).ToUInt64(null)); } else { jsonWriter.WriteLong(((IConvertible) obj).ToInt64(null)); } } [Fx.Tag.SecurityNote(Critical = "Holds all state used for (de)serializing types." + "Since the data is cached statically, we lock down access to it.")] #pragma warning disable 618 // have not moved to the v4 security model yet [SecurityCritical(SecurityCriticalScope.Everything)] #pragma warning restore 618 class JsonEnumDataContractCriticalHelper : JsonDataContractCriticalHelper { bool isULong; public JsonEnumDataContractCriticalHelper(EnumDataContract traditionalEnumDataContract) : base(traditionalEnumDataContract) { isULong = traditionalEnumDataContract.IsULong; } public bool IsULong { get { return this.isULong; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FrameSecurityDescriptor.cs
- DataSetMappper.cs
- MessageBox.cs
- MostlySingletonList.cs
- MonthCalendar.cs
- CheckBoxRenderer.cs
- GlobalAllocSafeHandle.cs
- ListSourceHelper.cs
- SafeProcessHandle.cs
- ByteStream.cs
- SystemIPGlobalStatistics.cs
- CookielessHelper.cs
- DocumentOutline.cs
- EntityDataSourceContainerNameItem.cs
- EntityDataSourceReferenceGroup.cs
- Internal.cs
- EntityProviderServices.cs
- ReadOnlyHierarchicalDataSourceView.cs
- GuidConverter.cs
- DBCSCodePageEncoding.cs
- WebPartTransformer.cs
- TransformConverter.cs
- Compilation.cs
- SmiMetaDataProperty.cs
- BaseValidator.cs
- COM2IManagedPerPropertyBrowsingHandler.cs
- ExpressionBuilderContext.cs
- SqlBulkCopyColumnMappingCollection.cs
- ImportCatalogPart.cs
- MultipartContentParser.cs
- Site.cs
- DataMisalignedException.cs
- TextServicesContext.cs
- OdbcFactory.cs
- EpmTargetTree.cs
- DataServiceQueryProvider.cs
- StructureChangedEventArgs.cs
- ObjectStorage.cs
- TransactionProtocolConverter.cs
- AccessDataSourceView.cs
- BuildResult.cs
- SiteMapHierarchicalDataSourceView.cs
- GuidTagList.cs
- NonceCache.cs
- DataMisalignedException.cs
- CharAnimationBase.cs
- BreakSafeBase.cs
- TransformProviderWrapper.cs
- HMACSHA256.cs
- UniqueEventHelper.cs
- ElementUtil.cs
- SafeTokenHandle.cs
- FileDataSource.cs
- BasePattern.cs
- SqlLiftWhereClauses.cs
- OleDbCommandBuilder.cs
- RotateTransform3D.cs
- SafeRegistryHandle.cs
- CultureInfoConverter.cs
- X509Certificate.cs
- RoleService.cs
- DataAdapter.cs
- DetailsViewPageEventArgs.cs
- XmlWriterSettings.cs
- Enlistment.cs
- FixedSOMLineRanges.cs
- AvTraceFormat.cs
- CurrentChangingEventManager.cs
- PasswordRecoveryAutoFormat.cs
- _emptywebproxy.cs
- GeometryModel3D.cs
- XmlSchemaSimpleTypeUnion.cs
- XPathNodeInfoAtom.cs
- SliderAutomationPeer.cs
- DropDownButton.cs
- ContainerSelectorGlyph.cs
- UpdatePanel.cs
- TypeDescriptor.cs
- SingleConverter.cs
- PropertyPathWorker.cs
- CodeEventReferenceExpression.cs
- MatrixCamera.cs
- FileStream.cs
- LinqDataSourceInsertEventArgs.cs
- BaseCodeDomTreeGenerator.cs
- XmlSerializerOperationBehavior.cs
- RenderingBiasValidation.cs
- Attributes.cs
- Blend.cs
- WebServiceTypeData.cs
- IndexerNameAttribute.cs
- WebPartConnectionsCloseVerb.cs
- ValueQuery.cs
- RawKeyboardInputReport.cs
- Span.cs
- Selector.cs
- Property.cs
- SecurityContextSecurityToken.cs
- BrushConverter.cs
- CodeAttributeArgument.cs