i have this method in asp.net for clo开发者_开发技巧ne my control :
public static Control Clone( Control ctrlSource )
{
Type t = ctrlSource.GetType();
Control ctrlDest = ( Control )t.InvokeMember( "" , BindingFlags.CreateInstance , null , null , null );
foreach( PropertyInfo prop in t.GetProperties() )
{
if( prop.CanWrite )
{
if( prop.Name == "ID" )
{
ctrlDest.ID = ctrlSource.ID + "cloned" + Security.Cryptography.Cryptography.generateRandomPrivateKey( 5 );
}
else
{
prop.SetValue( ctrlDest , prop.GetValue( ctrlSource , null ) , null );
}
}
}
return ctrlDest;
}
how can i set the source control event(like Click event) in destination control?
There is no way you can get a list of methods (AKA Invocation List
) subscribed to an event using reflection. You can subscribe or unsubscribe, but cannot get a list of all methods. Every control (or type) can implement it differently.
Why not explain why you want to do that and someone can suggest another way to do that.
精彩评论