public override object VisitCastExpression(CastExpression castExpression, object data)
{
base.VisitCastExpression(castExpression, data);
if (resolver.CompilationUnit == null)
return null;
if (castExpression.CastType != CastType.TryCast) {
IReturnType targetType = ResolveType(castExpression.CastTo);
if (targetType != null) {
IClass targetClass = targetType.GetUnderlyingClass();
if (targetClass != null && (targetClass.ClassType == ClassType.Struct || targetClass.ClassType == ClassType.Enum)) {
// cast to value type is a conversion
castExpression.CastType = CastType.Conversion;
}
if (targetClass != null && targetClass.FullyQualifiedName == "System.Char") {
// C# cast to char is done using ChrW function
ResolveResult sourceRR = resolver.ResolveInternal(castExpression.Expression, ExpressionContext.Default);
IReturnType sourceType = sourceRR != null ? sourceRR.ResolvedType : null;
if (IsInteger(sourceType)) {
ReplaceCurrentNode(new IdentifierExpression("ChrW").Call(castExpression.Expression));
}
}
}
}
return null;
}