But I ran into a situation recently in one of my company's VB.net projects where I had to pass a worksheet (Excel.Interop) into a new form (constructor). Apparently when you have a non CLS compliant object type passed into a constructor, you get the warning, "type of parameter is not CLS-complaint".
If you find VS warnings as annoying as I do, you want to get rid of that. You can do so by (caution, its overly simplistic): converting the worksheet to the generic Object class before passing it in. Then just re-convert it back to worksheet in the constructor.
I.E.
Dim arSheetHiding As Object = CType(arSheet, Object)
yourForm = New YourForm(arSheetHiding)
...
Public Sub New(ByVal sheet As Object)
InitializeComponent()
Dim wkst As Excel.Worksheet = CType(sheet, Excel.Worksheet)
_WorkSheet = wkst
...
End Sub
This does create more code but you get that "0 warnings feeling" that you're taking good care of your project.
No comments:
Post a Comment