I am doing some scripting of Adobe InDesign. Their COM implementation is really designed for VB, so it's not rigorous about reporting data types, occasionally necessitating the use of dynamics.
I'm trying to debug a chunk of code that looks like this:
foreach (dynamic pi in current.PageItems)
{
if (pi is TextFrame)
{
var frame = pi as TextFrame;
var str = frame.Contents.ToString();
Debug.WriteLine(str);
}
}
This gives me a RuntimeBinderException like this:
Additional information: Cannot dynamically invoke method 'WriteLine'
because it has a Conditional attribute
I get that the problem is that with Conditional attributes, the version of the code that needs to handle the type the dynamic resolves to at runtime might have gotten compiled out, but I'm explicitly converting what I want to debug to a string, so I don't see why this is still happening. How can I work around this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…