Проверка на частичный класс - PullRequest
0 голосов
/ 05 марта 2012

У меня есть этот код для проверки класса Customer, созданного из службы WCF:

public partial class Customer : IDataErrorInfo
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }

#region IDataErrorInfo Members

public string Error
{
    get { throw new NotImplementedException(); }
}

public string this[string columnName]
{
    get
    {
        string result = null;
        if (columnName == "FirstName")
        {
            if (string.IsNullOrEmpty(FirstName))
                result = "Please enter a First Name";
        }
        if (columnName == "LastName")
        {
            if (string.IsNullOrEmpty(LastName))
                result = "Please enter a Last Name";
        }
       if (columnName == "Age")
        {
            if (Age < = 0 || Age >= 99)
                result = "Please enter a valid age";
        }
        return result;
    }
}

#endregion

}

Я получаю ошибку при определении this [string columnName], вероятно, потому что это частичный класс:

Member names cannot be the same as their enclosing type

Вы знаете, как я могу обойти эту проблему?

1 Ответ

0 голосов
/ 05 марта 2012

Все это говорит вам о том, что ваше имя участника не может совпадать с именем класса.Например, у вас не может быть метода или свойства Customer в объекте Customer.

Например, остерегайтесь

public class Customer 
{
   public void Customer()  //<- You cannot do this, remove the void Customer should only be the constructor
   { } 
}

Так что я предполагаю, что проблема в другом месте, а не во фрагменте кода, который вы опубликовали.

...