473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Type.GetProperty using interfaces and inheritance

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

Nov 16 '05 #1
2 5211
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.

--
Rakesh Rajan
"Robert Zurer" wrote:
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

Nov 16 '05 #2
In article <20**********************************@microsoft.co m>,
Ra*********@discussions.microsoft.com says...
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Franco Gustavo | last post by:
Hi, Please help me to understand this, because I don't see what I'm missing. I was reading a lot of examples on Internet that explain that C# doesn't implement multiple inheritance it...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
1
by: Joe Jax | last post by:
I have an object which has a base object hierarchy as well as a number of implemented interfaces. Given any one property on that object, how do I find out which base class or interface defines that...
18
by: Jordan | last post by:
In OOP literature we read frequently about "interface" - a term which is apparently used to mean different things depending on context and possibly language. ..NET however provides for the...
18
by: _dee | last post by:
Question about best use of interfaces: Say there's a 'Master' class that needs to implement a few interfaces: class Master : I1, I2, I3 { } The actual code already exists in smaller...
27
by: jm | last post by:
I am having trouble understanding the purposes of an interface, even though the concept of interfaces is around me all the time (user interface, for example). I'm just not understanding software...
70
by: garyusenet | last post by:
I'm using an example piece of code: - namespace Wintellect.Interop.Sound{ using System; using System.Runtime.InteropServices; using System.ComponentModel; sealed class Sound{ public static...
26
by: Chris Becke | last post by:
Given an interface (in the c++ sense, nothing more than a struct containing pure virtual methods) struct Iv1 { virtual method0()=0; }; And a class that implements the interface class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.