c#方法名称预期INotifypropertyChanged

Rui*_*Rui 1 c# inotifypropertychanged

我遇到了问题.我是一名VB.net程序员,我正在努力学习C#.在我做过的很多VB项目中,我总是使用一个viewModelBase类,我可以通过我的项目通知我的属性,当我尝试将代码从vb转换为C#时,我得到一个method name expected就行了:if (TypeDescriptor.GetProperties(this)(propertyName) == null)

[Conditional("DEBUG"), DebuggerStepThrough()]
    public void VerifyPropertyName(string propertyName)
    {
        if (TypeDescriptor.GetProperties(this)(propertyName) == null)
        {
            string msg = "Invalid property name: " + propertyName;

            if (this.ThrowOnInvalidPropertyName)
            {
                throw new Exception(msg);
            }
            else
            {
                Debug.Fail(msg);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我真的找不到任何解决方案!有帮助吗?

谢谢

Jon*_*eet 7

听起来你只是错过了C#中的索引器语法这一事实[key].我怀疑你想要:

if (TypeDescriptor.GetProperties(this)[propertyName] == null)
Run Code Online (Sandbox Code Playgroud)

这是第一次调用GetProperties方法,找到PropertyDescriptorCollection的所有属性的this...那么它使用索引PropertyDescriptorCollection名字来访问一个特定的属性.