Solved

Properties by reflexion

Posted on 2013-01-14
4
158 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

737 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