0

我在运行时收到以下错误:AmbiguousMatchExcpetion“找到不明确的匹配”。

有人知道是什么原因吗?

班级

public class MyTrimmedClass : Control, INotifyPropertyChanged
{
    public HtUserGroupSetup CurrentUserGroupSetup
    {
        get { return _CurrentUserGroupSetup; }
        set
        {
            if (_CurrentUserGroupSetup != value)
            {
                _CurrentUserGroupSetup = value;
                OnPropertyChanged();
            }
        }
    }
    private HtUserGroupSetup _CurrentUserGroupSetup;


    public event PropertyChangedEventHandler PropertyChanged;

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}


public class HtUserGroupSetup : HtUserGroup
{
    public new List<HtPermissionSetup> Permissions
    {
        get { return _Permissions; }
        set
        {
            if (_Permissions != value)
            {
                _Permissions = value;
                OnPropertyChanged("Permissions");
            }
        }
    }
    private List<HtPermissionSetup> _Permissions = new List<HtPermissionSetup>();

    public HtUserGroupSetup(HtUserGroup userGroup)
    {
        Name = userGroup.Name;
        Description = userGroup.Description;
    }
}

public class HtUserGroup : HtBaseServiceData
{
    private string _Name = "";
    [DataMember]
    public string Name
    {
        get { return _Name; }
        set
        {
            if (_Name != value)
            {
                _Name = value;
                OnPropertyChanged("Name");
            }
        }
    }

    private string _Description = "";
    [DataMember]
    public string Description
    {
        get { return _Description; }
        set
        {
            if (_Description != value)
            {
                _Description = value;
                OnPropertyChanged("Description");
            }
        }
    }

    private List<HtPermission> _Permissions = new List<HtPermission>();
    [DataMember]
    public List<HtPermission> Permissions
    {
        get { return _Permissions; }
        set
        {
            if (_Permissions != value)
            {
                _Permissions = value;
                OnPropertyChanged("Permissions");
            }
        }
    }
}

public abstract class HtBaseServiceData : INotifyPropertyChanged
{
    protected void OnPropertyChanged(string property)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
    }
    public event PropertyChangedEventHandler PropertyChanged;
}

截屏

截屏

堆栈跟踪

System.Reflection.AmbiguousMatchException ist aufgetreten。

HResult=-2147475171 Message=Mehrdeutige Übereinstimmung gefunden。
Source=mscorlib StackTrace: bei System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) InnerException:

堆栈跟踪

4

1 回答 1

1

问题是,其中的Permissions属性隐藏了baseClass ( ) 的属性。HtUserGroupSetupPermissionsHtUserGroup

public new List<HtPermissionSetup> Permissions

重命名Permissions属性HtUserGroupSetup解决了这个问题。

于 2017-05-17T08:47:50.087 回答