C#与VB.Net的优雅与严格
Oxite中,有如下代码
Method
在VB.Net下,
Expression.Lamba.Body是不能直接转换为MethodCallExpression的
这里的method.Body是一个UnaryExpression.
在VB.Net中可以这样
Public Sub AddMethod(Of T)(ByVal pMethod As Expression(Of Func(Of T, Object)))
Dim tUnary As UnaryExpression = TryCast(pMethod.Body, UnaryExpression)
If tUnary Is Nothing Then
Throw New InvalidOperationException
End If
Dim tMethodCall As MethodCallExpression = TryCast(tUnary.Operand, MethodCallExpression)
If tMethodCall Is Nothing Then
Throw New InvalidOperationException
End If
Me.Methods.Add(New ReflectedActionDescriptor(tMethodCall.Method, tMethodCall.Method.Name, New ReflectedControllerDescriptor(tMethodCall.Object.Type)))
End Sub
Dim tUnary As UnaryExpression = TryCast(pMethod.Body, UnaryExpression)
If tUnary Is Nothing Then
Throw New InvalidOperationException
End If
Dim tMethodCall As MethodCallExpression = TryCast(tUnary.Operand, MethodCallExpression)
If tMethodCall Is Nothing Then
Throw New InvalidOperationException
End If
Me.Methods.Add(New ReflectedActionDescriptor(tMethodCall.Method, tMethodCall.Method.Name, New ReflectedControllerDescriptor(tMethodCall.Object.Type)))
End Sub
不清楚C#默认的转换是怎么转换的,有点反感某些缺省配置了.