Welcome to MSDN Blogs Sign in | Join | Help

Getting Better Time Formats

Orcas introduced a new DateTimeOffset class that is easier to use for representing absolute times than the original DateTime class. However, if you run svcutil on a contract that contains a DateTimeOffset, you'll get an ugly generated structure because DateTimeOffset isn’t recognized as a natively supported type by the system. A new class is generated by svcutil to match the schema for DateTimeOffset in the metadata.

namespace System
{
using System.Runtime.Serialization;

[DebuggerStepThroughAttribute()]
[GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[DataContractAttribute(Name="DateTimeOffset", Namespace="http://schemas.datacontract.org/2004/07/System")]
public partial struct DateTimeOffset : IExtensibleDataObject
{

private ExtensionDataObject extensionDataField;

private DateTime DateTimeField;

private short OffsetMinutesField;

public ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}

[DataMemberAttribute(IsRequired=true)]
public DateTime DateTime
{
get
{
return this.DateTimeField;
}
set
{
this.DateTimeField = value;
}
}

[DataMemberAttribute(IsRequired=true)]
public short OffsetMinutes
{
get
{
return this.OffsetMinutesField;
}
set
{
this.OffsetMinutesField = value;
}
}
}
}

There's a new option on svcutil, /targetClientVersion:Version35, that can be used to indicate that code generation should use new features in Orcas.

As far as I know, there are three places where this option makes a difference.

  1. DateTimeOffset is automatically added as a known type when referenced
  2. Asynchronous methods are generated using the Orcas event-based asynchronous model
  3. Additional LINQ types are supported during schema import for XmlSerializer

Next time: Read Only Data Members

Published Thursday, September 04, 2008 5:00 AM by Nicholas Allen

Comments

Thursday, September 04, 2008 1:49 PM by Nicholas Allen's Indigo Blog

# Composing Compression and Encryption

Encryption is counterproductive for compression if the two features aren't used together correctly. Generally,

Friday, January 23, 2009 7:55 PM by Nicholas Allen's Indigo Blog

# FxCop Target Rules

To go along with yesterday's post on targeting a particular version of the framework for proxy generation

New Comments to this post are disabled
 
Page view tracker