Click here to Skip to main content
15,921,210 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have made different number of classes with different properties and i have made a function which simply checks either the property value in that particular class is coming null or not so i just wanted to know that is there any way that i just pass the references of that class and the property name of that class comes dynamically since every class have different properties with different name...???
Posted

Reflection is what you need to do this. It's almost certainly not worth it.
 
Share this answer
 
this code will help you how to implement what Christian Graus said.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PropertyInfo[] pinfo = typeof(MYClass).GetProperties();
    }
}
public class MYClass
{
    public MYClass()
    { }
    public int MyProperty1 { get; set; }
    public int MyProperty2 { get; set; }
    public int MyProperty3 { get; set; }
}
 
Share this answer
 
reflection is the most appropriate way to do this , try it ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900