Your code shows a different problem than your description.

About your code:
Your first post shows variable "result" is a List. But in your second post 
you access that variable as an array.

About dynamic fields:
Look into .net reflection 
<https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/reflection>.
 
It allows you to look up the value of class member, given its name.
Essentially you have an object -one of the GoogleAdsRow that is in your 
list- and a name -which comes from FieldMask-. With reflection you can get 
its value. Actually you need to do this twice. Using your last code: 
Assuming an instance of Google AdsRow, first you use reflection to get the 
property with name "CustomerClient". Store its value in a variable of type 
"object". Then use reflection on THAT object, and retrieve the property 
named "ClientCustomer".
If reflection is too slow for you (you expect 10,000s of rows), check out 
package FastMember, which allows the same - but much faster.

.net reflection goes way beyond the intention of this forum, you should 
check out Stackoverflow.

I have two remarks though:
1. When the query returns zero rows, FieldMask probably has no fields. Make 
sure to check it.
2. The GoogleAds package does some name wrangling, I am not sure FieldMask 
contains names from the raw result of the API, or contains similar wrangled 
names.


You may want to reconsider the idea of dynamic fields. If you only have a 
dozen, or dozens of report types, it's probably easier to hardcode every 
one of these reports.

On Wednesday, April 13, 2022 at 3:57:51 PM UTC+2 axtens wrote:

> So I've been able to retrieve the fields using FieldMask. Is it possible 
> to programmatically access the fields in the GoogleAdsRow? For example, 
> from the "Immediate Window" in VS2019 where result contains a list of 
> GoogleAdsRows:
> ```
> result[0].CustomerClient.ClientCustomer
> "customers/7212153394"
> result[0]["CustomerClient.ClientCustomer"]
> error CS0021: Cannot apply indexing with [] to an expression of type 
> 'GoogleAdsRow'
> ```
> How does one achieve a dynamic field selection?
>
>
>
>
> On Wednesday, 13 April 2022 at 9:22:42 pm UTC+8 Zweitze wrote:
>
>> When you request a report, you'll reserve a response object with a few 
>> members, among that "Results" which is a list of returned GoogleAdsRows.
>> Among the other members you will find "FieldMask" which contains a list 
>> of names of the requested fields.
>>
>> With the FieldMask list, you can determine which fields you should 
>> include in that report you want to make.
>> On Wednesday, April 13, 2022 at 9:23:17 AM UTC+2 axtens wrote:
>>
>>> Having built up a list of GoogleAdsRow into
>>> ```
>>>          var result = new List<GoogleAdsRow>();
>>> ```
>>> how can I now get a list of all the fields in each row so as to build up 
>>> TSV report, with headings at the top and the columnar data below.
>>>
>>> -- Bruce
>>>
>>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/204527a2-e3f7-49e9-a8df-bb802a9fa539n%40googlegroups.com.

Reply via email to