Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Constants.cs
- EntityDescriptor.cs
- CachedResourceDictionaryExtension.cs
- EffectiveValueEntry.cs
- SendActivityDesigner.cs
- TextBoxAutoCompleteSourceConverter.cs
- Mapping.cs
- ListSortDescription.cs
- FamilyMapCollection.cs
- ProfileGroupSettings.cs
- IndexOutOfRangeException.cs
- ClientUrlResolverWrapper.cs
- TextEditorDragDrop.cs
- BoundsDrawingContextWalker.cs
- DesignerLinkAdapter.cs
- BuildProvider.cs
- FixedSOMImage.cs
- UIElement3D.cs
- Int16KeyFrameCollection.cs
- OwnerDrawPropertyBag.cs
- SslStream.cs
- MasterPageCodeDomTreeGenerator.cs
- XamlUtilities.cs
- SQLMoney.cs
- WindowsToolbar.cs
- UIntPtr.cs
- ConfigurationElement.cs
- ProfileGroupSettings.cs
- BinarySerializer.cs
- LongCountAggregationOperator.cs
- ReadOnlyCollectionBase.cs
- HttpCacheParams.cs
- Compiler.cs
- HttpContextServiceHost.cs
- XamlDesignerSerializationManager.cs
- DataBinding.cs
- FunctionGenerator.cs
- PriorityQueue.cs
- StandardOleMarshalObject.cs
- DataRecordObjectView.cs
- ExpandCollapseProviderWrapper.cs
- ReflectEventDescriptor.cs
- NamespaceMapping.cs
- AnimatedTypeHelpers.cs
- DisposableCollectionWrapper.cs
- Helpers.cs
- InitializerFacet.cs
- IODescriptionAttribute.cs
- CompareValidator.cs
- Binding.cs
- ConstrainedDataObject.cs
- UserMapPath.cs
- EntityDataSourceChangingEventArgs.cs
- DesignerHelpers.cs
- DefaultEventAttribute.cs
- IPAddressCollection.cs
- ObjectRef.cs
- EmptyStringExpandableObjectConverter.cs
- TdsValueSetter.cs
- EdmValidator.cs
- VisualStyleRenderer.cs
- AvTraceFormat.cs
- EncoderBestFitFallback.cs
- ViewgenGatekeeper.cs
- CustomAttribute.cs
- SocketElement.cs
- StorageRoot.cs
- HostExecutionContextManager.cs
- ObjectItemCachedAssemblyLoader.cs
- PerformanceCounterPermission.cs
- Pen.cs
- TypeInfo.cs
- SmtpReplyReaderFactory.cs
- ConfigurationLocationCollection.cs
- DataObjectMethodAttribute.cs
- XmlSerializerFactory.cs
- HashCryptoHandle.cs
- QueryStringHandler.cs
- XmlAnyElementAttribute.cs
- MappingMetadataHelper.cs
- EllipseGeometry.cs
- NameScopePropertyAttribute.cs
- HtmlAnchor.cs
- BidOverLoads.cs
- XamlClipboardData.cs
- SafeEventHandle.cs
- NameTable.cs
- MenuItemCollection.cs
- ResourceReader.cs
- ResourceExpressionEditor.cs
- DataSourceHelper.cs
- ClientSettings.cs
- SqlMethodAttribute.cs
- CanonicalXml.cs
- ScrollViewerAutomationPeer.cs
- TextReader.cs
- MultiBindingExpression.cs
- WhileDesigner.cs
- AppearanceEditorPart.cs
- AdornerPresentationContext.cs