Click here to Skip to main content
15,914,447 members
Home / Discussions / C#
   

C#

 
QuestionRe: change the #region Text Color AND some particular part of code Pin
jojoba201130-Mar-10 0:05
jojoba201130-Mar-10 0:05 
AnswerRe: change the #region Text Color AND some particular part of code Pin
TheFoZ30-Mar-10 0:21
TheFoZ30-Mar-10 0:21 
QuestionRunning exe files Pin
kebedetesema29-Mar-10 22:53
kebedetesema29-Mar-10 22:53 
AnswerRe: Running exe files Pin
kevinnicol30-Mar-10 3:20
kevinnicol30-Mar-10 3:20 
Questionproblem with timer Pin
mjawadkhatri29-Mar-10 22:19
mjawadkhatri29-Mar-10 22:19 
AnswerRe: problem with timer Pin
OriginalGriff29-Mar-10 22:29
mveOriginalGriff29-Mar-10 22:29 
GeneralRe: problem with timer Pin
mjawadkhatri29-Mar-10 22:39
mjawadkhatri29-Mar-10 22:39 
AnswerRe: problem with timer Pin
Deep Unknown30-Mar-10 2:47
Deep Unknown30-Mar-10 2:47 
GeneralRe: problem with timer Pin
mjawadkhatri30-Mar-10 19:32
mjawadkhatri30-Mar-10 19:32 
Question[SOLVED] Calling MethodBase's Invoke on a constructor (reflection) Pin
blackblizzard29-Mar-10 20:59
blackblizzard29-Mar-10 20:59 
AnswerRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
PIEBALDconsult30-Mar-10 5:04
mvePIEBALDconsult30-Mar-10 5:04 
GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
blackblizzard30-Mar-10 5:14
blackblizzard30-Mar-10 5:14 
GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
PIEBALDconsult30-Mar-10 7:35
mvePIEBALDconsult30-Mar-10 7:35 
GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
blackblizzard30-Mar-10 8:00
blackblizzard30-Mar-10 8:00 
GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
PIEBALDconsult30-Mar-10 8:42
mvePIEBALDconsult30-Mar-10 8:42 
GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
blackblizzard30-Mar-10 8:48
blackblizzard30-Mar-10 8:48 
GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
PIEBALDconsult30-Mar-10 9:49
mvePIEBALDconsult30-Mar-10 9:49 
AnswerRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
PIEBALDconsult30-Mar-10 10:24
mvePIEBALDconsult30-Mar-10 10:24 
Aha! It is documented:

"
Return Value
Type: System..::.Object

An object containing the return value of the invoked method, or nullNothingnullptra null reference (Nothing in Visual Basic) in the case of a constructor.

"

So I think you have to cast.


Here's a little something I whipped up to show a generic method to do it:

private static readonly System.Collections.Generic.Dictionary<System.Type,System.Reflection.MethodBase> dic ;

static Test
(
)
{
    dic = new System.Collections.Generic.Dictionary<System.Type,System.Reflection.MethodBase>() ;

    return ;
}

public static T
Clone<T>
(
    this T Source
)
where T : class
{
    System.Type t = typeof(T) ;

    System.Reflection.MethodBase m ;

    if ( !dic.ContainsKey ( t ) )
    {
        System.Type[] part = new System.Type[] { t } ;

        m = t.GetMethod ( "Clone" , part ) ;

        if ( ( m == null ) || ( ((System.Reflection.MethodInfo) m).ReturnType != t ) )
        {
            m = t.GetConstructor ( part ) ;

            if ( m == null )
            {
                throw ( new System.Exception ( "blah blah blah" ) ) ;
            }
        }

        dic [ t ] = m ;
    }
    else
    {
        m = dic [ t ] ;
    }

    T result ;

    if ( m.IsConstructor )
    {
        result = (T) ((System.Reflection.ConstructorInfo) m).Invoke ( new object[] { Source } ) ;
    }
    else
    {
        result = (T) m.Invoke ( Source , new object[] { Source } ) ;
    }

    return ( result ) ;
}

GeneralRe: Calling MethodBase's Invoke on a constructor (reflection) Pin
blackblizzard30-Mar-10 22:07
blackblizzard30-Mar-10 22:07 
QuestionTotally custom windows forms Pin
r0seBa29-Mar-10 19:59
r0seBa29-Mar-10 19:59 
QuestionMail [modified] Pin
ravanth29-Mar-10 18:25
ravanth29-Mar-10 18:25 
AnswerRe: Mail Pin
PSK_29-Mar-10 18:37
PSK_29-Mar-10 18:37 
AnswerRe: Mail Pin
Abhinav S29-Mar-10 19:53
Abhinav S29-Mar-10 19:53 
Question32 bit dll on 64 bit Windows --- Windows Service? Pin
devvvy29-Mar-10 17:01
devvvy29-Mar-10 17:01 
AnswerRe: 32 bit dll on 64 bit Windows --- Windows Service? Pin
PSK_29-Mar-10 17:21
PSK_29-Mar-10 17:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.