Saturday, November 24, 2012

We are at the mercy of language designers

using System;

namespace Craft
{

    public delegate string Greeter(string s);
    public class HeyAttribute : Attribute
    {
        public Greeter GreetAction { get; set; }
    }


  
    // Strongly-typed mechanism on attribute is no joy in C#, it's not
    // possible.  C# language designers reduces the attributes "complexity" :
    // http://stackoverflow.com/questions/294216/why-does-c-sharp-forbid-generic-attribute-types

    [Hey(GreetAction = Mate.Yo)] // This will not compile, despite the simplicity
    public class Test
    {
    }



    public class Mate
    {
        public static string Yo(string s)
        {
            return "Hello " + s;
        }
    }


    class Program
   {
        static void Main(string[] args)
        {           
        }
    }

   
}



   

No comments:

Post a Comment