Il check-in C# un oggetto VB.NET per nulla dà inaspettato errore di compilazione:Il check-in C# un oggetto VB.NET per nulla dà inaspettato errore di compilazione
// Cannot compile:
var basePackage = BasePackage.GetFromID(id); // GetFromID is from VB.NET
if (basePackage != null) // Errormesage: "Cannot implicitly convert 'object' to 'bool'
{
}
correzione suggerito dal ReSharper:
// Can compile
if ((bool) (basePackage != null))
{
linkedGroups = basePackage.GetLinkedGroups();
}
Ho un collega che lo ha fatto in un anno senza problemi. Il mio collega utilizza Visual Studio 2012 e sto utilizzando Visual Studio 2013. Potrebbe essere una specie di impostazione?
Perché basePackage != null
un object
?
So che VB.NET ha Nothing
dove C# ha null
.
UPDATE: BasePackage di ereditato questo da un'altra classe: Non so se questo è aiuta in alcun modo.
Public Shared Operator =([object] As CMSObject, type As System.Type)
Return [object].GetType Is type
End Operator
Public Shared Operator <>([object] As CMSObject, type As System.Type)
Return [object].GetType IsNot type
End Operator
Public Shared Operator =([object] As CMSObject, o As Object)
Return [object].GetType Is o
End Operator
Public Shared Operator <>([object] As CMSObject, o As Object)
Return [object].GetType IsNot o
End Operator
SOLUZIONE: Quando ho outcomment questi due operatori C# è lavorare di nuovo bene.
Public Shared Operator =([object] As CMSObject, type As System.Type)
Return [object].GetType Is type
End Operator
'Public Shared Operator <>([object] As CMSObject, type As System.Type)
' Return [object].GetType IsNot type
'End Operator
Public Shared Operator =([object] As CMSObject, o As Object)
Return [object].GetType Is o
End Operator
'Public Shared Operator <>([object] As CMSObject, o As Object)
' Return [object].GetType IsNot o
'End Operator
Soluzione Finale tipo Aggiunto in VB.NET. Non c'è quindi bisogno del cast di C#.
Public Shared Operator =([object] As CMSObject, type As System.Type) **As Boolean**
Return [object].GetType Is type
End Operator
Public Shared Operator <>([object] As CMSObject, type As System.Type) **As Boolean**
Return [object].GetType IsNot type
End Operator
Public Shared Operator =([object] As CMSObject, o As Object) **As Boolean**
Return [object].GetType Is o
End Operator
Public Shared Operator <>([object] As CMSObject, o As Object) **As Boolean**
Return [object].GetType IsNot o
End Operator
Che aspetto ha la firma di 'GetFromID' in VB? –
Funzione condivisa pubblica GetFromID (ByVal ID job As Integer) Come BasePackage – radbyx
Che aspetto ha il 'BasePackage'? Contiene operatori? – CodeCaster