[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Properties by reflexion

Posted on 2013-01-14
4
Medium Priority
?
162 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
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

830 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