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

Top 5 Contributors of the Month

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..?

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
GetObject(oItems.GetValue(aoObjectToFound, Nothing), asObjectName)
End If
End If
End If

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

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