Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / Runtime / Serialization / Json / JsonObjectDataContract.cs / 1 / JsonObjectDataContract.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Runtime.Serialization.Json
{
using System.Xml;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Globalization;
class JsonObjectDataContract : JsonDataContract
{
public JsonObjectDataContract(DataContract traditionalDataContract)
: base(traditionalDataContract)
{
}
public override object ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context)
{
object obj;
string contentMode = jsonReader.GetAttribute(JsonGlobals.typeString);
switch (contentMode)
{
case JsonGlobals.nullString:
jsonReader.Skip();
obj = null;
break;
case JsonGlobals.booleanString:
obj = jsonReader.ReadElementContentAsBoolean();
break;
case JsonGlobals.stringString:
case null:
obj = jsonReader.ReadElementContentAsString();
break;
case JsonGlobals.numberString:
obj = ParseJsonNumber(jsonReader.ReadElementContentAsString());
break;
case JsonGlobals.objectString:
jsonReader.Skip();
obj = new object();
break;
case JsonGlobals.arrayString:
// Read as object array
return DataContractJsonSerializer.ReadJsonValue(DataContract.GetDataContract(Globals.TypeOfObjectArray), jsonReader, context);
default:
throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(
XmlObjectSerializer.CreateSerializationException(SR2.GetString(SR2.JsonUnexpectedAttributeValue, contentMode)));
}
if (context != null)
{
context.AddNewObject(obj);
}
return obj;
}
public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
{
jsonWriter.WriteAttributeString(null, JsonGlobals.typeString, null, JsonGlobals.objectString);
}
internal static object ParseJsonNumber(string value, out TypeCode objectTypeCode)
{
if (value == null)
{
throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString(System.Runtime.Serialization.SR.XmlInvalidConversion, value, Globals.TypeOfInt)));
}
if (value.IndexOfAny(JsonGlobals.floatingPointCharacters) == -1)
{
int intValue;
if (Int32.TryParse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out intValue))
{
objectTypeCode = TypeCode.Int32;
return intValue;
}
long longValue;
if (Int64.TryParse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out longValue))
{
objectTypeCode = TypeCode.Int64;
return longValue;
}
}
decimal decimalValue;
if (Decimal.TryParse(value, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out decimalValue))
{
objectTypeCode = TypeCode.Decimal;
return decimalValue;
}
objectTypeCode = TypeCode.Double;
return XmlConverter.ToDouble(value);
}
static object ParseJsonNumber(string value)
{
TypeCode unusedTypeCode;
return ParseJsonNumber(value, out unusedTypeCode);
}
}
}
// 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
- PolyBezierSegment.cs
- StringWriter.cs
- CalculatedColumn.cs
- FakeModelItemImpl.cs
- TraceListener.cs
- ThumbAutomationPeer.cs
- Panel.cs
- ExpressionBuilderCollection.cs
- ColumnPropertiesGroup.cs
- Storyboard.cs
- QuotedStringFormatReader.cs
- ToolStripContainerDesigner.cs
- DeviceSpecificChoice.cs
- ListControl.cs
- MissingMethodException.cs
- XamlVector3DCollectionSerializer.cs
- ApplicationBuildProvider.cs
- CultureInfo.cs
- InlineCollection.cs
- XmlNamedNodeMap.cs
- WindowManager.cs
- IndexerReference.cs
- OleDbRowUpdatedEvent.cs
- propertytag.cs
- TextPointer.cs
- Stack.cs
- RepeaterDataBoundAdapter.cs
- DetailsViewRow.cs
- NavigationProperty.cs
- ExceptionHandlersDesigner.cs
- BaseInfoTable.cs
- AssemblyAssociatedContentFileAttribute.cs
- MsiStyleLogWriter.cs
- DispatchChannelSink.cs
- Style.cs
- ServiceReference.cs
- TextRange.cs
- SchemaNotation.cs
- RectIndependentAnimationStorage.cs
- FlowDocumentReaderAutomationPeer.cs
- SetUserLanguageRequest.cs
- CodeTryCatchFinallyStatement.cs
- InstalledVoice.cs
- StaticContext.cs
- Translator.cs
- StylusCollection.cs
- DataGridAutoFormatDialog.cs
- ConfigXmlComment.cs
- RowUpdatingEventArgs.cs
- EllipseGeometry.cs
- Point3DCollectionConverter.cs
- AssemblyCollection.cs
- CapabilitiesUse.cs
- OdbcConnectionOpen.cs
- ProgressBarAutomationPeer.cs
- IISMapPath.cs
- ComboBox.cs
- ObjectDataSourceDesigner.cs
- NativeWindow.cs
- ProjectedSlot.cs
- KeyTimeConverter.cs
- SchemaElement.cs
- Animatable.cs
- XsltContext.cs
- BackStopAuthenticationModule.cs
- ParseElementCollection.cs
- DateTimeFormatInfoScanner.cs
- StagingAreaInputItem.cs
- ItemAutomationPeer.cs
- CombinedTcpChannel.cs
- CaseInsensitiveComparer.cs
- WeakEventManager.cs
- SpellCheck.cs
- TickBar.cs
- DataGridViewRowStateChangedEventArgs.cs
- Point.cs
- ContextInformation.cs
- UnsafeNativeMethods.cs
- StrongNamePublicKeyBlob.cs
- Converter.cs
- UIElement3DAutomationPeer.cs
- MaskDescriptor.cs
- PlaceHolder.cs
- CommandPlan.cs
- JavaScriptString.cs
- RijndaelManagedTransform.cs
- ICspAsymmetricAlgorithm.cs
- CodeConditionStatement.cs
- PickBranchDesigner.xaml.cs
- RelatedPropertyManager.cs
- TreeNodeStyle.cs
- ObjectMemberMapping.cs
- CodeGenerator.cs
- PersonalizationStateQuery.cs
- SmiEventSink_DeferedProcessing.cs
- QilSortKey.cs
- ActivityInterfaces.cs
- CellParagraph.cs
- RequestDescription.cs
- TouchesCapturedWithinProperty.cs