all groups > visual studio .net ide > january 2005 >
You're in the

visual studio .net ide

group:

Optional parameters to VS extensibility functions in C#



Optional parameters to VS extensibility functions in C# Emil Astrom
1/31/2005 9:07:17 PM
visual studio .net ide: Hi!

On several occasions I've had the need to call functions in Visual Studio
that take optional parameters, such as TextSelection.Delete(int). In VB
macro code I can do the following:

Dim td As TextDocument = ActiveDocument.Object
td.Selection.Delete()

But if I include that into C# add-in code, I get a compiler error: No
overload for method 'Delete' takes '0' arguments

If I instead try (which I thought was the recommended method)

td.Selection.Delete(Type.Missing);

then I get this instead:

The best overloaded method match for 'EnvDTE.TextSelection.Delete(int)' has
some invalid arguments
Argument '1': cannot convert from 'object' to 'int'

So my question is: What is the correct way to call functions with optional
arguments from C# add-ins?

Failing that, maybe someone has a tip of how to delete text between two
points?

Thanks,

Emil

Re: Optional parameters to VS extensibility functions in C# Carlos J. Quintero [.NET MVP]
2/1/2005 2:43:48 PM
In this case the optional argument is integer, so you pass the value 1 which
is the default.

If you want to delete the text between 2 edit points without selecting the
text, you use EditPoint1.Delete(EditPoint2).

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com


"Emil Astrom" <emil_astrom(at)hotmail.com> escribió en el mensaje
news:%23eeq5B9BFHA.2380@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Re: Optional parameters to VS extensibility functions in C# Emil Astrom
2/1/2005 11:38:30 PM
I had missed that usage of the Editpoint.Delete function. Thanks!

Out of curiosity, how did you know the default value to be 1 for
TextSelection.Delete? Is there a trick? Might be good to know for other
functions with default values.

Thanks again,

Emil


"Carlos J. Quintero [.NET MVP]" <carlosq@NOSPAMsogecable.com> wrote in
message news:edSWQQGCFHA.4004@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Re: Optional parameters to VS extensibility functions in C# Carlos J. Quintero [.NET MVP]
2/2/2005 11:12:28 AM
"Emil Astrom" <emil_astrom(at)hotmail.com> escribió en el mensaje
news:%23ARQE7KCFHA.3368@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

The Object Browser shows the following information for the Delete method of
the TextSelection class:

public void Delete(int Count = 1)
Member of EnvDTE.TextSelection

Summary:
Deletes the selection.

Attributes:
[System.Runtime.InteropServices.DispIdAttribute(23)]

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com


Re: Optional parameters to VS extensibility functions in C# Emil Astrom
2/2/2005 12:19:09 PM
That's interesting, beacause all I see in the object browser is this:

public abstract new void Delete ( System.Int32 Count )
Member of EnvDTE.TextSelection

No default value and no summary ;-(

How can this be? Is it a setting in Visual Studio or am I missing some help
files etc?

/Emil

"Carlos J. Quintero [.NET MVP]" <carlosq@NOSPAMsogecable.com> wrote in
message news:uAO60%23QCFHA.3376@TK2MSFTNGP12.phx.gbl...
[quoted text, click to view]

Re: Optional parameters to VS extensibility functions in C# Carlos J. Quintero [.NET MVP]
2/2/2005 8:04:55 PM
I don't know, but it could depend on:

- VS.NET 2002 vs VSNET 2003
- The language used by the Object Browser. The previous example was for C#
2003. For VB.NET 2002 I get:

<System.Runtime.InteropServices.DispIdAttribute(23)>
Public Sub Delete(Optional ByVal Count As Integer = 1)
Member of EnvDTE.TextSelection

Which also shows the default value 1. So, check in your case which IDE and
language you are using.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com


"Emil Astrom" <emil_astrom(at)hotmail.com> escribió en el mensaje
news:u6jcHkRCFHA.3368@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button