C# generics with MVVM, pulling the T out of

后端 未结 4 2153
情深已故
情深已故 2021-02-11 09:42

My Model is a generic class that contains a (for example) Value property which can be int, float, string, bool, etc. So naturally this class is represe

4条回答
  •  名媛妹妹
    2021-02-11 10:30

    As a side note, when you said:

    When I expose Model to the View

    You aren't following MVVM conventions, for whatever that's worth. In MVVM, the model itself should never be exposed to the view.

    That being said, you can expose the type of T in this way.

    public Type ModelType
    {
        get { return typeof(T); }
    }
    

    If that suits your purposes.

提交回复
热议问题