?
Solved

Properties by reflexion

Posted on 2013-01-14
4
Medium Priority
?
160 Views
Last Modified: 2013-01-26
how can access sub class properties?, I can access Y properties, in this case Name, but not x, another case is the same but instead of single reference of x, with a list of x, in this second case how iterate every object.

	public class X
	{
		public int ID{get;set;}	
		public int Name{get;set;}
	}

	public class y
	{

		public string Name{get;set;}
		public x Reference{get:set;}
	}

	//Second case with a List
	public class y
	{

		public string Name{get;set;}
		public List<x> Reference{get:set;}
	}

	public static void Main()
	{
		y classY = new y();
		y.Name = "some text here";
		y.x.ID = "1";
		y.x.Name ="some text for x here";
	}

	// in another class, pass y
	// so, in this method I only can get 'y' values, but not x
	Hashtable table = new Hashtable();
	public void GetProperties(object p)
	{
	    Type mytype = p.GetType();
	    var properties = mytype.GetProperties(BindingFlags.Public | BindingFlags.Instance);

	    foreach (var property in properties)
	    {
	    	table.Add(property.Name, property.GetValue(p, null));
		}	
	}

Open in new window

0
Comment
Question by:Crashman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38775493
Which is the subclass? You have two classes with the same exact name (y), which will not compile.
0
 
LVL 8

Author Comment

by:Crashman
ID: 38775772
the other class named Y is a list, and this is second case...in the first, how iterate all objects including references and the other the same case but with a list instead a single object.
0
 
LVL 8

Accepted Solution

by:
Crashman earned 0 total points
ID: 38801872
Solved, every entity used IEditableObject, the hastable is saved before BeginEdit, later, every object iterates his own hashtable
0
 
LVL 8

Author Closing Comment

by:Crashman
ID: 38821810
Solved by my self
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question