Bug Report - Document.Variables requires get_Item()

D

David Thielen

Hi;

I am trying somehow to get these bugs reported to the Word group
(having no luck so far):

To delete a Word.Document.Variable in Word.Document.Variables you have
to call

object obj = var.Name;
document.Variables.get_Item(ref obj).Delete();.

I am assuming this is because of the ref object passed to it. But it
is strange that you can’t call

document.Variables[var.Name].Delete();.

And the intellisense in VisualStudio allows the [string] but does not
know of the get_Item. (I’m not sure this is a bug because of how PIAs
are built but it does strike me that it could be.)

- dave
 
M

Mark Bower [MSFT]

Hi David,
The reason you have to write your code this way is due to the way the C#
language works rather than anything to do with Word/Office.
C# and the CLR do not support parameterized properties. The Office
interfaces were written for COM which does support this. So to enable C#
apps to be able to call these COM interfaces through interop, the PIAs mask
the underlying property with a get_Item() method.

If you were to use VB.NET instead, you would be able to write code almost
exactly as you suggest as VB.NET supports both parameterized properties and
automatic type coercion to provide backward compatibility with VB6.

There's a really good article describing some of the quirks of programming
the Office APIs with C# in the MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/OffCSharp.asp

Cheers,
Mark.


--
Mark Bower
Microsoft
http://blogs.msdn.com/bowerm

This post is provided 'as-is' without warranty and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top