hi,
I need to get the ColumnsNames in 'ResultColumns' as shown in the image of the quickwatch above.I am not able to get anything inside the 'query' bt can access it through the quickwatch as shown.How can i access it.Please Help.
Regards, Jaison
hi,
I need to get the ColumnsNames in 'ResultColumns' as shown in the image of the quickwatch above.I am not able to get anything inside the 'query' bt can access it through the quickwatch as shown.How can i access it.Please Help.
Regards, Jaison
Your field query
is private. That is why you can't access it in a "normal" way.
You can still access it through Reflection tough. You can use the following code to access a private field:
/// <summary>
/// Uses reflection to get the field value from an object.
/// </summary> ///
/// <param name="type">The instance type.</param>
/// <param name="instance">The instance object.</param>
/// <param name="fieldName">The field's name which is to be fetched.</param>
/// <returns>The field value from the object.</returns>
internal static object GetInstanceField(Type type, object instance, string fieldName)
{
BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
| BindingFlags.Static;
FieldInfo field = type.GetField(fieldName, bindFlags);
return field.GetValue(instance);
}
In your case you would then call it like:
Korzh.EasyQuery.Db.DbQuery query = GetInstanceField(typeof(Korzh.EasyQuery.Db.SqlQueryBuilder), builder, "query") as Korzh.EasyQuery.Db.DbQuery;
However you should do this only when absolutely necessary. Fields are normally private for a reason. And bypassing this my cause some unexpected behaviour.
The code for the function was taken from the following answer: How to get the value of private field in C#?