Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / DateTimeOffsetAdapter.cs / 1305376 / DateTimeOffsetAdapter.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Runtime.Serialization { using System; using System.Reflection; using System.Xml; using System.Globalization; [DataContract(Name = "DateTimeOffset", Namespace = "http://schemas.datacontract.org/2004/07/System")] #if USE_REFEMIT public struct DateTimeOffsetAdapter #else internal struct DateTimeOffsetAdapter #endif { DateTime utcDateTime; short offsetMinutes; public DateTimeOffsetAdapter(DateTime dateTime, short offsetMinutes) { this.utcDateTime = dateTime; this.offsetMinutes = offsetMinutes; } [DataMember(Name = "DateTime", IsRequired = true)] public DateTime UtcDateTime { get { return utcDateTime; } set { utcDateTime = value; } } [DataMember(Name = "OffsetMinutes", IsRequired = true)] public short OffsetMinutes { get { return offsetMinutes; } set { offsetMinutes = value; } } public static DateTimeOffset GetDateTimeOffset(DateTimeOffsetAdapter value) { try { switch (value.UtcDateTime.Kind) { case DateTimeKind.Unspecified: return new DateTimeOffset(value.UtcDateTime, new TimeSpan(0, value.OffsetMinutes, 0)); //DateTimeKind.Utc and DateTimeKind.Local //Read in deserialized DateTime portion of the DateTimeOffsetAdapter and convert DateTimeKind to Unspecified. //Apply ofset information read from OffsetMinutes portion of the DateTimeOffsetAdapter. //Return converted DateTimeoffset object. default: DateTimeOffset deserialized = new DateTimeOffset(value.UtcDateTime); return deserialized.ToOffset(new TimeSpan(0, value.OffsetMinutes, 0)); } } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception)); } } public static DateTimeOffsetAdapter GetDateTimeOffsetAdapter(DateTimeOffset value) { return new DateTimeOffsetAdapter(value.UtcDateTime, (short)value.Offset.TotalMinutes); } public string ToString(IFormatProvider provider) { return "DateTime: " + this.UtcDateTime + ", Offset: " + this.OffsetMinutes; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Runtime.Serialization { using System; using System.Reflection; using System.Xml; using System.Globalization; [DataContract(Name = "DateTimeOffset", Namespace = "http://schemas.datacontract.org/2004/07/System")] #if USE_REFEMIT public struct DateTimeOffsetAdapter #else internal struct DateTimeOffsetAdapter #endif { DateTime utcDateTime; short offsetMinutes; public DateTimeOffsetAdapter(DateTime dateTime, short offsetMinutes) { this.utcDateTime = dateTime; this.offsetMinutes = offsetMinutes; } [DataMember(Name = "DateTime", IsRequired = true)] public DateTime UtcDateTime { get { return utcDateTime; } set { utcDateTime = value; } } [DataMember(Name = "OffsetMinutes", IsRequired = true)] public short OffsetMinutes { get { return offsetMinutes; } set { offsetMinutes = value; } } public static DateTimeOffset GetDateTimeOffset(DateTimeOffsetAdapter value) { try { switch (value.UtcDateTime.Kind) { case DateTimeKind.Unspecified: return new DateTimeOffset(value.UtcDateTime, new TimeSpan(0, value.OffsetMinutes, 0)); //DateTimeKind.Utc and DateTimeKind.Local //Read in deserialized DateTime portion of the DateTimeOffsetAdapter and convert DateTimeKind to Unspecified. //Apply ofset information read from OffsetMinutes portion of the DateTimeOffsetAdapter. //Return converted DateTimeoffset object. default: DateTimeOffset deserialized = new DateTimeOffset(value.UtcDateTime); return deserialized.ToOffset(new TimeSpan(0, value.OffsetMinutes, 0)); } } catch (ArgumentException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(value.ToString(CultureInfo.InvariantCulture), "DateTimeOffset", exception)); } } public static DateTimeOffsetAdapter GetDateTimeOffsetAdapter(DateTimeOffset value) { return new DateTimeOffsetAdapter(value.UtcDateTime, (short)value.Offset.TotalMinutes); } public string ToString(IFormatProvider provider) { return "DateTime: " + this.UtcDateTime + ", Offset: " + this.OffsetMinutes; } } } // 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
- AsyncOperationContext.cs
- RegisteredHiddenField.cs
- TableAdapterManagerMethodGenerator.cs
- DataGridViewCellLinkedList.cs
- ContextMenuStripActionList.cs
- DataGridSortCommandEventArgs.cs
- PartialArray.cs
- PenThreadWorker.cs
- JsonDeserializer.cs
- Point4DValueSerializer.cs
- ProfilePropertyNameValidator.cs
- HtmlWindowCollection.cs
- DrawingVisual.cs
- LookupNode.cs
- EditorZone.cs
- ControlAdapter.cs
- GestureRecognizer.cs
- WindowsFormsLinkLabel.cs
- MimeMapping.cs
- ScopelessEnumAttribute.cs
- SecurityKeyUsage.cs
- CustomError.cs
- WindowsPrincipal.cs
- StyleBamlRecordReader.cs
- SplitterPanelDesigner.cs
- SmiMetaDataProperty.cs
- HttpConfigurationContext.cs
- ConditionalAttribute.cs
- XmlTextReader.cs
- HttpBrowserCapabilitiesWrapper.cs
- DefaultAuthorizationContext.cs
- DynamicArgumentDialog.cs
- HttpValueCollection.cs
- WizardStepCollectionEditor.cs
- CurrencyManager.cs
- XmlSchemaExporter.cs
- SqlXmlStorage.cs
- PointCollection.cs
- Visual3DCollection.cs
- ILGenerator.cs
- XmlEntity.cs
- XmlReaderSettings.cs
- CompilerErrorCollection.cs
- MultilineStringConverter.cs
- JsonQueryStringConverter.cs
- CharacterBufferReference.cs
- PtsHelper.cs
- FullTextBreakpoint.cs
- AbstractSvcMapFileLoader.cs
- PersonalizationStateQuery.cs
- XmlChildNodes.cs
- AttributeQuery.cs
- DefaultAutoFieldGenerator.cs
- ObjectDataSourceMethodEventArgs.cs
- OdbcCommandBuilder.cs
- TypeConstant.cs
- XamlFigureLengthSerializer.cs
- RtfNavigator.cs
- EventDescriptorCollection.cs
- NamedPipeChannelFactory.cs
- TabControl.cs
- SnapLine.cs
- Axis.cs
- SpeechRecognizer.cs
- XmlSchemaObjectCollection.cs
- HelpProvider.cs
- XmlQueryTypeFactory.cs
- DragCompletedEventArgs.cs
- _ListenerResponseStream.cs
- XPathSingletonIterator.cs
- TextRangeSerialization.cs
- StreamWriter.cs
- LoopExpression.cs
- TemplateControlCodeDomTreeGenerator.cs
- ThemeableAttribute.cs
- ScopedMessagePartSpecification.cs
- ReflectPropertyDescriptor.cs
- TypeHelpers.cs
- FontSizeConverter.cs
- EntityTypeEmitter.cs
- PerformanceCountersElement.cs
- DataControlCommands.cs
- TransformedBitmap.cs
- XmlIlVisitor.cs
- ConfigurationValues.cs
- KeyPressEvent.cs
- TypeConverterHelper.cs
- TCEAdapterGenerator.cs
- StateRuntime.cs
- _AcceptOverlappedAsyncResult.cs
- InvokeWebService.cs
- ParallelTimeline.cs
- DataDocumentXPathNavigator.cs
- M3DUtil.cs
- ISCIIEncoding.cs
- RemotingHelper.cs
- keycontainerpermission.cs
- WaitHandleCannotBeOpenedException.cs
- IMembershipProvider.cs
- ListChangedEventArgs.cs