COM Interop에서 dynamic의 적절한 사용
From C# 4.0, variant types are instead mapped to dynamic (if Embed Interop Types
is enabled; more on this soon), allowing you to replace the last two lines with this:
excel.Cells [1, 1].Font.FontStyle = "Bold";
The disadvantage of working in this way is that you lose auto-completion, so you
must know that a property called Font happens to exist. For this reason, it’s usually
easier to dynamically assign the result to its known interop type:
Excel.Range range = excel.Cells [1, 1];
range.Font.FontStyle = "Bold";
As you can see, this saves only five characters over the old-fashioned approach!
댓글
댓글 쓰기