Type.GetProperty using interfaces and inheritance

  • Thread starter Thread starter Robert Zurer
  • Start date Start date
R

Robert Zurer

I have two interfaces one inherits from the other

public interface IEmployee
{
string FirstName{get; set;}
string LastName{get; set;}
}

public interface IHRMSEmployee : IEmployee
{
string SSNum{get; set;}
}

PropertyInfo propInfo = typeof(IHRMSEmployee)GetProperty("LastName");
returns null.

PropertyInfo propInfo = typeof(IEmployee)GetProperty("LastName");
returns a value.

Why is this? Using classes, I can get the inherited property this way>


Thanks

Robert Zurer
 
Well, IMHO, I think that unless you implement an interface in a class, you won't have access to the inherited members. In this case, the derived interface does not exist as such, so as to have the inherited members, hence returning null.
 
Well, IMHO, I think that unless you implement an interface in a class,
you won't have access to the inherited members. In this case,
the derived interface does not exist as such, so as to have the inherited members, hence returning null.

I'm sorry. I didn't mean to give that impression.
The classes which implement the interfaces have been defined

public class Employee : IEmployee
{
private string firstName;
private string lastName;
public string FirstName
{
get{return firstName;}
set{firstName = value;}
}
public string LastName
{
get{return lastName;}
set{lastName = value;}
}
}

public class HRMSEmployee : Employee, IHRMSEmployee
{
private string SSNum;
public string LastName
{
get{return ssNum;}
set{ssNum= value;}
}
}

and, as I said, when using classes

PropertyInfo propInfo = typeof(HRMSEmployee)GetProperty("LastName");
does return a value.

The question is why does

PropertyInfo propInfo = typeof(IHRMSEmployee)GetProperty("LastName");
not return a value.


Robert Zurer
 
Back
Top