How to obtain only interface properties using reflection?

Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 236
Suppose we have a class as under

 public class Employee : IMyInterface
public int property1 { get; set; }
public string property2{get;set;}
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public virtual int EmployeeAge { private set; get; } //read-only property
public virtual string EmployeeSalary { set; private get; } //write-only property

interface IMyInterface
int property1 { get; set; }
string property2 { get; set; }


The intention is to obtain only the interface properties.The below code does the work
.Where(p => p.GetAccessors()[0].IsFinal)
.ForEach(i => Console.WriteLine(i.Name));

The IsFinal property of MethodBase class gets a value indicating whether this method is final.It returns true if this method is final; otherwise, false. It is defined as

public bool IsFinal { get; }

More Info :

Comments or Responses

Login to post response