none
Obtaining correct method signature RRS feed

  • Question

  •  
    How to get syntactically correct signature which compiles for code template generation ?
    I tried code below but it creates syntactically incorrect signature.
     
    Andrus.
     
    using System;
    using System.Collections.Generic;
     
    public class MainClass
    {
        static string GetSignature(Type xTheType, string method)
        {
            var xModule = xTheType.Module;
            var xTheMethod = xTheType.GetMethod(method);
            return xTheMethod.ToString();
        }
     
        public static void Main()
        {
            // Observed: Void Test(System.Object, System.Collections.Generic.List`1[System.String])
            // Expected: public void Test(object p1, List<string> p2)
            // or some other syntactically correct signature
            Console.WriteLine(GetSignature(typeof(MainClass), "Test"));
        }
     
        public void Test(object p1, List<string> p2)
        {
        }
    }
    Friday, October 31, 2008 10:27 AM

Answers

All replies

  • That's how .NET generics work.  Generic types don't become concrete until they are specialized at runtime.  Just filter out the back-quote and the number.
    Hans Passant.
    Friday, October 31, 2008 10:32 AM
    Moderator
  • Thank you.

    My question was about obtaining syntactically correct signature.

    How to change sample code so that correct signature is created?
    Friday, October 31, 2008 6:18 PM