Tired of not having a generic version of IClonable?
-
Try this extension method:
public static T Clone<T>(this T obj) where T : ICloneable
{
return (T)(((ICloneable)obj).Clone());
}In VB:
<Extension()>
Public Shared Function Clone(Of T As IClonable)(ByVal obj As T) As T
Return DirectCast(DirectCast(obj, IClonable).Clone(), T)
End Function(If the VB syntax is wrong, tell me. I don't use VB any more)
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
Try this extension method:
public static T Clone<T>(this T obj) where T : ICloneable
{
return (T)(((ICloneable)obj).Clone());
}In VB:
<Extension()>
Public Shared Function Clone(Of T As IClonable)(ByVal obj As T) As T
Return DirectCast(DirectCast(obj, IClonable).Clone(), T)
End Function(If the VB syntax is wrong, tell me. I don't use VB any more)
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
neat !
-
Try this extension method:
public static T Clone<T>(this T obj) where T : ICloneable
{
return (T)(((ICloneable)obj).Clone());
}In VB:
<Extension()>
Public Shared Function Clone(Of T As IClonable)(ByVal obj As T) As T
Return DirectCast(DirectCast(obj, IClonable).Clone(), T)
End Function(If the VB syntax is wrong, tell me. I don't use VB any more)
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
No, but I found this in my code today:
public static T
Clone<T>
(
this T Connection
)
where T : System.Data.IDbConnection , new()
{
return ( new T()
{
ConnectionString = Connection.ConnectionString
} ) ;
}I get the feeling that I never even tried to test it. I'm not sure I ever should. But it compiles! To make matters worse, I found that because I had just written this:
public static partial class LibExt
{
private static readonly System.Collections.Generic.Dictionary<System.Type,System.Reflection.ConstructorInfo> constructors ;static LibExt
(
)
{
constructors = new System.Collections.Generic.Dictionary<System.Type,System.Reflection.ConstructorInfo>() ;return ;
}
public static System.Data.IDbConnection
CloneConnection
(
this System.Data.IDbConnection Connection
)
{
System.Data.IDbConnection result ;System.Type typ = Connection.GetType() ; if ( !constructors.ContainsKey ( typ ) ) { constructors \[ typ \] = typ.GetConstructor ( System.Type.EmptyTypes ) ; } result = (System.Data.IDbConnection) constructors \[ typ \].Invoke ( new object \[ 0 \] ) ; result.ConnectionString = Connection.ConnectionString ; return ( result ) ;
}
}Which I haven't tested either. :sigh:
-
Try this extension method:
public static T Clone<T>(this T obj) where T : ICloneable
{
return (T)(((ICloneable)obj).Clone());
}In VB:
<Extension()>
Public Shared Function Clone(Of T As IClonable)(ByVal obj As T) As T
Return DirectCast(DirectCast(obj, IClonable).Clone(), T)
End Function(If the VB syntax is wrong, tell me. I don't use VB any more)
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???