Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有继承属性的nswag INotify UWP问题_C#_Inheritance_Uwp_Inotifypropertychanged_Nswag - Fatal编程技术网

C# 具有继承属性的nswag INotify UWP问题

C# 具有继承属性的nswag INotify UWP问题,c#,inheritance,uwp,inotifypropertychanged,nswag,C#,Inheritance,Uwp,Inotifypropertychanged,Nswag,我有一个DotNetCore Web Api,它的客户端是一个UWP应用程序,其中客户端通过生成的Nswag文件与Api连接。在我的api端有一个类DropDownBase,它被用作许多不同类型的下拉类的基类,它用来保存所有下拉类的公共属性。在这里,我将向您展示一个名为calible的儿童课程 DropDownBase(api侧) 口径(api侧) 现在需要注意的是,在客户端,我使用这个DropDownBase类来创建集合和更多自定义逻辑,这样我就不必为每个下拉类分别编写冗余逻辑。它的工作原理与

我有一个DotNetCore Web Api,它的客户端是一个UWP应用程序,其中客户端通过生成的Nswag文件与Api连接。在我的api端有一个类DropDownBase,它被用作许多不同类型的下拉类的基类,它用来保存所有下拉类的公共属性。在这里,我将向您展示一个名为calible的儿童课程

DropDownBase(api侧) 口径(api侧) 现在需要注意的是,在客户端,我使用这个DropDownBase类来创建集合和更多自定义逻辑,这样我就不必为每个下拉类分别编写冗余逻辑。它的工作原理与预期一致

问题

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.2.1.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class DropDownBase : DefaultBaseColumn, System.ComponentModel.INotifyPropertyChanged
{
    private System.Guid _id;
    private string _typeName;

    [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public System.Guid Id
    {
        get { return _id; }
        set 
        {
            if (_id != value)
            {
                _id = value; 
                RaisePropertyChanged();
            }
        }
    }

    [Newtonsoft.Json.JsonProperty("typeName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public string TypeName
    {
        get { return _typeName; }
        set 
        {
            if (_typeName != value)
            {
                _typeName = value; 
                RaisePropertyChanged();
            }
        }
    }


    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    
    protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
    {
        var handler = PropertyChanged;
        if (handler != null) 
            handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }

}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.2.1.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class Caliber : DropDownBase, System.ComponentModel.INotifyPropertyChanged
{


    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    
    protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
    {
        var handler = PropertyChanged;
        if (handler != null) 
            handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }

}
public partial class DropDownBase
{
    [JsonIgnore]
    public DropDownBase THIS => this;
}
属性TypeName存在于DropDownBase中,当它从子对象绑定到UI xaml时,例如:“{x:Bind calible.TypeName,Mode=OneWay}”,然后更改TypeName值,它不会更新UI上的值,因此INotify系统无法按预期工作。但是,如果属性直接存在于类calible中,而不是从父类继承,则它可以正常工作

DropDownBase(nswag客户端生成的文件)

calible(nswag客户端生成的文件)

请注意,对于我的情况,手动更改nswwag生成的文件不是一个理想的解决方案,因为我们经常生成这些文件,任何手动更改都将被覆盖。我只想让typename属性通知UI它已更改

在客户端,我还有第二个DropDownBase文件,在这个文件中,我为这个类添加了额外的东西,只用于客户端的任何自定义逻辑,因为nswag为我生成了一个分部类,这对我来说更容易做到,所以如果任何建议的修复包括在这个分部类中添加一些代码,这对我来说可能是可行的

DropDownBase(客户端部分类用于额外代码)


此问题是由父类重写引起的。nswwag生成的Calible类中的代码重写
PropertyChanged
事件和
RaisePropertyChanged
方法,从而导致从基类继承的hide RaisePropertyChanged方法

您可以在类中删除这些重写以解决错误。但你说这些代码是自动生成的,不能更改

正如您所说,您可以将Typename属性添加到子类中。或者您可以直接声明父类的对象并绑定dropDownBase.TypeName

[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.2.1.0 (Newtonsoft.Json v12.0.0.0)")]
public partial class Caliber : DropDownBase, System.ComponentModel.INotifyPropertyChanged
{


    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    
    protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
    {
        var handler = PropertyChanged;
        if (handler != null) 
            handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
    }

}
public partial class DropDownBase
{
    [JsonIgnore]
    public DropDownBase THIS => this;
}