Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataGridViewComboBoxColumn.cs
- Int16Storage.cs
- BitmapPalettes.cs
- EpmTargetPathSegment.cs
- TrackPoint.cs
- SiteMapDataSourceDesigner.cs
- FormViewInsertedEventArgs.cs
- TdsParameterSetter.cs
- messageonlyhwndwrapper.cs
- FirewallWrapper.cs
- SqlWorkflowInstanceStore.cs
- ContentFilePart.cs
- MergablePropertyAttribute.cs
- EditCommandColumn.cs
- StsCommunicationException.cs
- HandlerFactoryWrapper.cs
- SafeUserTokenHandle.cs
- WorkflowApplicationAbortedException.cs
- InheritablePropertyChangeInfo.cs
- StateRuntime.cs
- ImpersonateTokenRef.cs
- PageEventArgs.cs
- SortQuery.cs
- ConstNode.cs
- TableLayoutRowStyleCollection.cs
- GetPageNumberCompletedEventArgs.cs
- FileLevelControlBuilderAttribute.cs
- XmlWellformedWriter.cs
- ComponentDispatcherThread.cs
- ServiceDescriptionSerializer.cs
- PerformanceCounterLib.cs
- DynamicRendererThreadManager.cs
- DirectionalLight.cs
- GroupBoxRenderer.cs
- PageContent.cs
- TriggerAction.cs
- OpenTypeLayoutCache.cs
- SecurityUtils.cs
- METAHEADER.cs
- SHA1Managed.cs
- RoleManagerSection.cs
- SessionEndingCancelEventArgs.cs
- GridViewColumnHeaderAutomationPeer.cs
- SizeAnimationBase.cs
- WebPartHelpVerb.cs
- StringToken.cs
- CheckPair.cs
- DescendentsWalker.cs
- OutputCacheSettings.cs
- PolicyChain.cs
- PageRequestManager.cs
- ObjectResult.cs
- WebPartDeleteVerb.cs
- Sql8ExpressionRewriter.cs
- SkinBuilder.cs
- Group.cs
- FlowLayoutSettings.cs
- ComponentChangingEvent.cs
- prompt.cs
- SqlTriggerContext.cs
- BaseCollection.cs
- CompoundFileReference.cs
- ConfigurationStrings.cs
- BCryptHashAlgorithm.cs
- DataGridViewTextBoxColumn.cs
- PreservationFileWriter.cs
- HashStream.cs
- SchemaObjectWriter.cs
- SrgsOneOf.cs
- HtmlTextArea.cs
- PingOptions.cs
- PointLight.cs
- OciHandle.cs
- FileAuthorizationModule.cs
- ReadOnlyHierarchicalDataSourceView.cs
- WebServiceData.cs
- DataViewSettingCollection.cs
- ColumnTypeConverter.cs
- ACL.cs
- WorkflowInstanceQuery.cs
- UIElementIsland.cs
- LinqDataSourceValidationException.cs
- BaseTemplateBuildProvider.cs
- CriticalFinalizerObject.cs
- RegexCompilationInfo.cs
- ReadWriteSpinLock.cs
- TableLayoutPanel.cs
- NullableDoubleAverageAggregationOperator.cs
- PostBackOptions.cs
- ByteStreamMessageEncodingElement.cs
- ProfileInfo.cs
- ColorMap.cs
- OleDbParameterCollection.cs
- BaseParagraph.cs
- EntityContainer.cs
- ToolStripSplitButton.cs
- MissingSatelliteAssemblyException.cs
- SqlNodeTypeOperators.cs
- IndependentlyAnimatedPropertyMetadata.cs
- XPathArrayIterator.cs