Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Created May 21, 2012 02:49
Show Gist options
  • Save sdurandeu/2760373 to your computer and use it in GitHub Desktop.
Save sdurandeu/2760373 to your computer and use it in GitHub Desktop.
T ToT template method sample
public static T To<T>(Endpoint endpoint) where T : Endpoint
{
if (endpoint.GetType() == typeof(T))
return endpoint as T;
var destination = Activator.CreateInstance<T>();
destination.ApplicationId = endpoint.ApplicationId;
destination.TileId = endpoint.TileId;
destination.ClientId = endpoint.ClientId;
destination.ChannelUri = endpoint.ChannelUri;
destination.UserId = endpoint.UserId;
destination.ExpirationTime = endpoint.ExpirationTime;
destination.DeviceType = endpoint.DeviceType;
return destination;
}
public static T To<T>(Endpoint endpoint) where T : Endpoint
{
if (endpoint.GetType() == typeof(T))
return endpoint as T;
var destination = Activator.CreateInstance<T>();
destination.ApplicationId = endpoint.ApplicationId;
destination.TileId = endpoint.TileId;
destination.ClientId = endpoint.ClientId;
destination.ChannelUri = endpoint.ChannelUri;
destination.UserId = endpoint.UserId;
destination.ExpirationTime = endpoint.ExpirationTime;
destination.DeviceType = endpoint.DeviceType;
return destination;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment