Home All Groups Group Topic Archive Search About

CLS-Compliance and Array Parameter Rank

Author
28 May 2006 11:50 PM
TC
I just upgraded some code to VB 2005. When I did so, Visual Studio
generated several warnings telling me about things which weren't quite
perfect in my code. I resolved all the warnings except one. I need help
with this one.

'Public Function Multiply(A(,) As Double, B() As Double) As Double()'
is not CLS-compliant because it overloads 'Public Function
Multiply(A(,) As Double, B(,) As Double) As Double(,)' which differs
from it only by array of array parameter types or by the rank of the
array parameter types.

Apparently, my code is not CLS-compliant because B() has the same
parameter signature as B(,) under the CLS rules. I understand this
problem, but I don't know how to fix it.

The only solution I see is to stop overloading (i.e. change the name of
one of the two functions), but that will change the public signature of
my code. Can anyone suggest a better solution?


-TC

Author
29 May 2006 5:30 AM
Mattias Sjögren
>The only solution I see is to stop overloading (i.e. change the name of
>one of the two functions), but that will change the public signature of
>my code. Can anyone suggest a better solution?

If you don't care about CLS compliance you can apply the
CLSCompliant(False) attribute to the method to get rid of the warning.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
29 May 2006 3:40 PM
TC
Mattias,

Thanks for the advice. Unfortunately, I'm forced to care about CLS
compliance. The module in question is referenced by many projects, some
of which must be CLS compliant.

-TC
Author
29 May 2006 3:59 PM
Jay B. Harlow [MVP - Outlook]
TC,
What Mattias was suggesting was:

<Assembly: CLSCompliant(True)>

Public Class Something

    <CLSCompliant(False)> _
    Public Function Multiply(ByVal A(,) As Double, ByVal B() As Double) As
Double()
        Return Nothing
    End Function

    Public Function Multiply(ByVal A(,) As Double, ByVal B(,) As Double) As
Double(,)
        Return Nothing
    End Function

End Class

You can have the entire assembly CSL compliant, except selected types &
methods, as above.

NOTE: I don't know why but it makes a difference which one you use
<CLSCompliant(False)> on...

This is similar to System.Convert.ToUInt32() method. The System.Convert
class is CLS Compliant, however the ToUInt32 is not, as UInt32 is not.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"TC" <golemdan***@yahoo.com> wrote in message
news:1148917257.909475.154140@j33g2000cwa.googlegroups.com...
| Mattias,
|
| Thanks for the advice. Unfortunately, I'm forced to care about CLS
| compliance. The module in question is referenced by many projects, some
| of which must be CLS compliant.
|
| -TC
|