The sticking point is the DataReference property will return an AFDataReference object, which gives you the generic properties and methods of AFDataReference. To get the Table property of the Table Lookup Data Reference, you need to either know the exact type of TLDR, or at least use a dynamic variable.
The snippet of AFAttr.DataReference.returns an AFDataReference. It would be the same as:
AFDataReference dr1 = AFAttr.DataReference;
So dr1 does not appear to have a Table property because the AFDataReference does not have a Table property. The way to fix it would be using dynamic:
dynamic dr2 = AFAttr.DataReference;
And now it should have the Table property. But Intellisense does not kick in with dynamic, so you do lose that feature.
Thanks for the reply. The dynamic approach work:
- dynamic dr2 = AFAttr.DataReference;
You also mention "To get the Table property of the Table Lookup Data Reference, you need to either know the exact type of TLDR,..."
I know for sure this attribute I'm reading is a tableLookup.
So, what will be this other approach you mention.
How I set up the DataReference as a TLDR
2 of 2 people found this helpful
The attribute you are reading is an AFAttribute. We know that. It's data reference is the Table Lookup Data Reference. We know that too. While the TLDR implements AFDataReference, it nonetheless is its own type. The actual data type of the Table Lookup Data Reference is OSIsoft.AF.Asset.DataReference.TableLookupDR. But that type is not baked into AF SDK. That type is not added until runtime, since after all the DR is a plug in. Since you do not know of that type during design or compile time, you cannot use the exact type. Instead you must use dynamic.
If you set a breakpoint and examine the Locals window, you can see the types. Variable dr1 was defined using var (same as AFDataReference) but variable dr2 was defined as dynamic.
Thanks for your reply