notanaverageman / Bindables

Bindables converts your auto properties into Wpf dependency or attached properties.
MIT License
52 stars 9 forks source link

Application freeze when declaring DP in class with generic #10

Open RodgerLeblanc opened 5 years ago

RodgerLeblanc commented 5 years ago

When declaring a DP using Bindables in a generic class, the application freezes.

namespace BindablesGeneric
{
    public class MyLabel : MyLabel<string>
    {
    }

    public class MyLabel<T> : Label
    {
        //This one hang the execution, need to force close Visual Studio

        [DependencyProperty]
        public object MyProperty { get; set; }

        //This one works

        //public static readonly DependencyProperty MyPropertyProperty =
        //    DependencyProperty.Register(nameof(MyProperty), typeof(object), typeof(MyLabel<T>), new PropertyMetadata(null));

        //public object MyProperty
        //{
        //    get { return (object)GetValue(MyPropertyProperty); }
        //    set { SetValue(MyPropertyProperty, value); }
        //}
    }
}
RodgerLeblanc commented 5 years ago

BindablesGeneric.zip

notanaverageman commented 5 years ago

Thanks for reporting the issue. I have found the root cause. The generic type in Mono.Cecil does not contain the T argument while it is being written in IL. That causes an infinite loop in .NET reflection codes.

I am trying to find a way to include the T in IL. I haven't found the way how Mono.Cecil handles it. When I find it, I will fix the code and release a new package.