Type.GetProperty using interfaces and inheritance

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
 
G

Guest

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.
 
R

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top