如何使原始类(int)子类INotifyPropertyChanged

发布于 2024-12-11 22:00:54 字数 86 浏览 0 评论 0原文

我如何将原始类型设置为 INotifyPropertyChanged 的​​子类 int ?我可以在不创建额外课程的情况下这样做吗?

How can i make a primitive type as int a subclass of INotifyPropertyChanged? Can i do so without creating an additional class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在巴黎塔顶看东京樱花 2024-12-18 22:00:54

int 是一个不可变的结构,因此这一点没有实际意义。

但不行,您不能将接口添加到不属于您的类或结构中。你必须以某种方式包裹它。

int is an immutable struct so the point is moot.

But no, you cannot add interfaces to a class or struct you don't own. You'd have to wrap it somehow.

夜声 2024-12-18 22:00:54

最好的选择是创建自己的类来实现 INotifyPropertyChanged 并包装类型。

一个简单的例子是:

public class ChangingPrimitive<T> : INotifyPropertyChanged
{
    // ... implement INotifyPropertyChanged Here

    public T Inner {get;set;}

    // ... optional work to expose the inner type directly
}

Your best bet is to make your own class that implements INotifyPropertyChanged and wraps the type.

A quick example would be:

public class ChangingPrimitive<T> : INotifyPropertyChanged
{
    // ... implement INotifyPropertyChanged Here

    public T Inner {get;set;}

    // ... optional work to expose the inner type directly
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文