I have this code for validation of the Customer class which is created from a WCF service:
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
}
I get the error at the definition of the this[string columnName] method, probably because its a partial class:
Member names cannot be the same as their enclosing type
Do you know how I can get around this problem?
All this is telling you, is that your Member name cannot be the same name as the class name. For example you cannot have a Customer method or property on a Customer object.
For example beware of
So I’m guessing that the issue is somewhere else and not int the code snippet that you have posted.