.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Get Properties from object

Posted By: Mahesh     Posted Date: March 15, 2011    Points:5   Category :ASP.Net
i am having an object which contains properties/child objects etc. child objects also contains properties, i need to iterate through each properties. which is best method to use..?

Responses
Author: Mahesh             
Posted Date: March 17, 2011     Points: 20   

hi friends i got the answer here is the simple code which iterates through each property useing reflection, for this if your objects contains child objects/ or child classes then you should know the root namspace for the child objects

Private Function GetObject(ByRef aoObjectToFound As Object, ByVal asObjectName As String, Byval asBaseClassNamspace as String) As Object
For Each oItems As Reflection.PropertyInfo In aoObjectToFound.GetType().GetProperties()
If oItems.GetValue(aoObjectToFound, Nothing) IsNot Nothing Then
If oItems.PropertyType.FullName.StartsWithasBaseClassNamspace) Then
If oItems.Name = asObjectName Then
Return oItems.GetValue(aoObjectToFound, Nothing, asBaseClassNamspace)
Exit Function
Else
GetObject(oItems.GetValue(aoObjectToFound, Nothing), asObjectName)
End If
End If
End If
Next

Return Nothing
End Function





Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend