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="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