Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / Runtime / Serialization / Json / JsonClassDataContract.cs / 1 / JsonClassDataContract.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Runtime.Serialization.Json { using System.Threading; using System.Xml; using System.Diagnostics; using System.ServiceModel; using System.Collections.Generic; using System.Security; class JsonClassDataContract : 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] JsonClassDataContractCriticalHelper helper; //// Critical - initializes SecurityCritical field 'helper' // Safe - doesn't leak anything // [SecurityCritical, SecurityTreatAsSafe] public JsonClassDataContract(ClassDataContract traditionalDataContract) : base(new JsonClassDataContractCriticalHelper(traditionalDataContract)) { this.helper = base.Helper as JsonClassDataContractCriticalHelper; } internal JsonFormatClassReaderDelegate 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) { JsonFormatClassReaderDelegate tempDelegate = new JsonFormatReaderGenerator().GenerateClassReader(TraditionalClassDataContract); Thread.MemoryBarrier(); helper.JsonFormatReaderDelegate = tempDelegate; } } } return helper.JsonFormatReaderDelegate; } } internal JsonFormatClassWriterDelegate 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) { JsonFormatClassWriterDelegate tempDelegate = new JsonFormatWriterGenerator().GenerateClassWriter(TraditionalClassDataContract); Thread.MemoryBarrier(); helper.JsonFormatWriterDelegate = tempDelegate; } } } return helper.JsonFormatWriterDelegate; } } internal XmlDictionaryString[] MemberNames { //// Critical - fetches the critical MemberNames property // Safe - MemberNames only needs to be protected for write // [SecurityCritical, SecurityTreatAsSafe] get { return this.helper.MemberNames; } } internal override string TypeName { //// Critical - fetches the critical TypeName property // Safe - TypeName only needs to be protected for write // [SecurityCritical, SecurityTreatAsSafe] get { return this.helper.TypeName; } } ClassDataContract TraditionalClassDataContract { //// Critical - fetches the critical TraditionalClassDataContract property // Safe - TraditionalClassDataContract only needs to be protected for write // [SecurityCritical, SecurityTreatAsSafe] get { return this.helper.TraditionalClassDataContract; } } public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) { jsonReader.Read(); object o = JsonFormatReaderDelegate(jsonReader, context, XmlDictionaryString.Empty, MemberNames); jsonReader.ReadEndElement(); return o; } public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle) { jsonWriter.WriteAttributeString(null, JsonGlobals.typeString, null, JsonGlobals.objectString); JsonFormatWriterDelegate(jsonWriter, obj, context, TraditionalClassDataContract, MemberNames); } //// 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 JsonClassDataContractCriticalHelper : JsonDataContractCriticalHelper { JsonFormatClassReaderDelegate jsonFormatReaderDelegate; JsonFormatClassWriterDelegate jsonFormatWriterDelegate; XmlDictionaryString[] memberNames; ClassDataContract traditionalClassDataContract; string typeName; public JsonClassDataContractCriticalHelper(ClassDataContract traditionalDataContract) : base(traditionalDataContract) { this.typeName = string.IsNullOrEmpty(traditionalDataContract.Namespace.Value) ? traditionalDataContract.Name.Value : string.Concat(traditionalDataContract.Name.Value, JsonGlobals.NameValueSeparatorString, XmlObjectSerializerWriteContextComplexJson.TruncateDefaultDataContractNamespace(traditionalDataContract.Namespace.Value)); this.traditionalClassDataContract = traditionalDataContract; CopyMembersAndCheckDuplicateNames(); } internal JsonFormatClassReaderDelegate JsonFormatReaderDelegate { get { return this.jsonFormatReaderDelegate; } set { this.jsonFormatReaderDelegate = value; } } internal JsonFormatClassWriterDelegate JsonFormatWriterDelegate { get { return this.jsonFormatWriterDelegate; } set { this.jsonFormatWriterDelegate = value; } } internal XmlDictionaryString[] MemberNames { get { return this.memberNames; } } internal ClassDataContract TraditionalClassDataContract { get { return this.traditionalClassDataContract; } } void CopyMembersAndCheckDuplicateNames() { if (traditionalClassDataContract.MemberNames != null) { int memberCount = traditionalClassDataContract.MemberNames.Length; DictionarymemberTable = new Dictionary (memberCount); XmlDictionaryString[] decodedMemberNames = new XmlDictionaryString[memberCount]; for (int i = 0; i < memberCount; i++) { if (memberTable.ContainsKey(traditionalClassDataContract.MemberNames[i].Value)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR2.GetString(SR2.JsonDuplicateMemberNames, DataContract.GetClrTypeFullName(traditionalClassDataContract.UnderlyingType), traditionalClassDataContract.MemberNames[i].Value))); } else { memberTable.Add(traditionalClassDataContract.MemberNames[i].Value, null); decodedMemberNames[i] = DataContractJsonSerializer.ConvertXmlNameToJsonName(traditionalClassDataContract.MemberNames[i]); } } this.memberNames = decodedMemberNames; } } } } } // 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
- MessageBox.cs
- CodeAttachEventStatement.cs
- HtmlControlPersistable.cs
- httpapplicationstate.cs
- QilLiteral.cs
- WindowsListViewGroupHelper.cs
- PageParserFilter.cs
- ExpressionBuilderCollection.cs
- Completion.cs
- SmtpSection.cs
- CollectionViewGroupRoot.cs
- ThumbButtonInfo.cs
- BinaryParser.cs
- RouteParameter.cs
- XmlSchemaNotation.cs
- returneventsaver.cs
- GetLedgerEntryForRecipientRequest.cs
- TemplateKey.cs
- IdentitySection.cs
- EnumMemberAttribute.cs
- EmptyEnumerator.cs
- Perspective.cs
- MsmqHostedTransportConfiguration.cs
- DbConnectionStringBuilder.cs
- StringUtil.cs
- ProviderConnectionPoint.cs
- CacheDependency.cs
- DesignerSerializationOptionsAttribute.cs
- DesignerHierarchicalDataSourceView.cs
- FacetChecker.cs
- ArrayHelper.cs
- ServiceReflector.cs
- PropertyIDSet.cs
- ToolStripDropDownMenu.cs
- ToolStripDropDownClosedEventArgs.cs
- Policy.cs
- RichTextBox.cs
- IBuiltInEvidence.cs
- WebMethodAttribute.cs
- SelectedPathEditor.cs
- PointLight.cs
- RowParagraph.cs
- ToolStripItemTextRenderEventArgs.cs
- HelpKeywordAttribute.cs
- CompositeActivityTypeDescriptorProvider.cs
- FixedTextPointer.cs
- MultiBinding.cs
- CodeTypeDeclarationCollection.cs
- ObjectAssociationEndMapping.cs
- ProcessThreadCollection.cs
- FontStretch.cs
- TextBoxRenderer.cs
- fixedPageContentExtractor.cs
- TextWriter.cs
- PrefixHandle.cs
- RadioButtonList.cs
- ParamArrayAttribute.cs
- GeneralTransform2DTo3D.cs
- TraceFilter.cs
- Scripts.cs
- CorrelationManager.cs
- Mouse.cs
- MetafileHeader.cs
- ButtonPopupAdapter.cs
- ConfigurationElementProperty.cs
- FreezableDefaultValueFactory.cs
- indexingfiltermarshaler.cs
- TreeNodeStyleCollection.cs
- WorkflowInstanceQuery.cs
- CodeAccessPermission.cs
- WebResponse.cs
- BinaryConverter.cs
- SecurityCriticalDataForSet.cs
- TemplateKey.cs
- ResourceKey.cs
- NamespaceMapping.cs
- PathSegmentCollection.cs
- WhitespaceRule.cs
- WasNotInstalledException.cs
- LicFileLicenseProvider.cs
- TemplateNameScope.cs
- altserialization.cs
- ReferencedType.cs
- StateItem.cs
- SqlDataSourceConfigureSelectPanel.cs
- EpmSourceTree.cs
- Int64AnimationBase.cs
- ContextInformation.cs
- _AuthenticationState.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- CodeCommentStatementCollection.cs
- XsdDataContractExporter.cs
- CriticalFinalizerObject.cs
- SuppressMergeCheckAttribute.cs
- UtilityExtension.cs
- figurelengthconverter.cs
- TextDecorationCollection.cs
- AspCompat.cs
- AccessDataSourceView.cs
- WebPartAuthorizationEventArgs.cs