This is some sample of things you can do with my compiler:

Operator generic constraints

public static T3 Average<T, T2, T3>(IEnumerable<T> items)
    where T2 + T = T2
    where T2 / Int32 = T3
{
    T2 value = default(T2);
    int count = 0;
    foreach (T item in items)
    {
        count ++;
        value = value + item;
    }
    return value / count; 
}

Parameterized constructor generic constraints

public class C<T>
    where T : new(string, bool)
{
    public T CreateT(string s, bool b)
    {
        return new T(s, b);
    }
}

Mix return and yield return, add yield return many

public IEnumerable<int> GetInts(bool b)
{
    if (b)
        return Enumerable.Range(1, 2);
    yield return many Enumerable.Range(1, 2);
    yield return 4;
}

Weak delegates

Singleton.Instance.A += weak InstanceA; // where A is of type Action

NotifyPropertyChanged implementation

[NotifyPropertyChanged]
public class TestNotifyPropertyChanged
{
    public int P1 { get; set; }

    private string _p2;
    public string P2
    {
        get { return _p2; }
        set 
        {
            if (_p2 != null)
                _p2 = value; 
        }
    }
}

Last edited Apr 12, 2012 at 9:23 AM by MatthieuMEZIL, version 3

Comments

melody4mind Apr 25, 2012 at 7:23 PM 
I've been dying to get into Roslyn. I love the parameterized generic ctor constraints! I even added an idea to visualstudio.uservoice.com about it:

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2122427-expand-generic-constraints-for-constructors