Browse Source

Add allowImplicitConversion parameter to TranslatedExpression.ConvertTo

pull/844/head
Siegfried Pammer 8 years ago
parent
commit
e7bc501d3f
  1. 6
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

6
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -168,7 +168,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -168,7 +168,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// From the caller's perspective, IntPtr/UIntPtr behave like normal C# integers except that they have native int size.
/// All the special cases necessary to make IntPtr/UIntPtr behave sanely are handled internally in ConvertTo().
/// </remarks>
public TranslatedExpression ConvertTo(IType targetType, ExpressionBuilder expressionBuilder, bool checkForOverflow = false)
public TranslatedExpression ConvertTo(IType targetType, ExpressionBuilder expressionBuilder, bool checkForOverflow = false, bool allowImplicitConversion = false)
{
var type = this.Type;
if (type.Equals(targetType))
@ -294,6 +294,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -294,6 +294,10 @@ namespace ICSharpCode.Decompiler.CSharp
.WithILInstruction(this.ILInstructions)
.WithRR(new ConstantResolveResult(targetType, null));
}
var conversions = Resolver.CSharpConversions.Get(compilation);
if (allowImplicitConversion && conversions.ImplicitConversion(type, targetType).IsValid) {
return this;
}
var castExpr = new CastExpression(expressionBuilder.ConvertType(targetType), Expression);
castExpr.AddAnnotation(checkForOverflow ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation);
return castExpr.WithoutILInstruction().WithRR(rr);

Loading…
Cancel
Save