Click here to Skip to main content
15,910,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// Object1 (it has multiple inner object)

i was getting exception when ever try to read the inner object at
C#
public static void WritePDF<T>(T Object1 ,int RrcordID)

       {
          Type type = typeof(T);
             foreach (System.Reflection.PropertyInfo property in type.GetProperties())
               {
                svalue = type.GetProperty(property.Name).GetValue(Object1, null).ToString();
               }
        }

before this i need to check it and get the inner object value ,How ?
Posted
Updated 11-Dec-13 20:20pm
v2

1 solution

Without knowing exactly what exception you're getting it's hard to say for sure what's going wrong.
But this line
svalue = type.GetProperty(property.Name).GetValue(Object1, null).ToString();

Will at least fail if:

  • 1. The value of the property is null as the call to ToString will then cause a NullReferenceException.
  • 2. The property is an indexer property (it's likely to throw an exception)

Hope this helps,
Fredrik
 
Share this answer
 
Comments
venuchary 12-Dec-13 3:27am    
svalue = type.GetProperty(property.Name).GetValue(Object1, null).ToString();

this works well when retrive the values .when loop reached to the object then getting exception "Object reference not set to an instance of an object"
1)here i need to identify loop reached to inner object.
2) i need get the values from that object

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900