File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
ICSharpCode.Decompiler.Tests/TestCases/Correctness
ICSharpCode.Decompiler/CSharp/Transforms Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ static void Main()
4242#endif
4343 Issue2444 . M2 ( ) ;
4444 Issue2741 . B . Test ( new Issue2741 . C ( ) ) ;
45+ ExtensionMethodDemo . Issue2165 . Test ( ) ;
4546 }
4647
4748 #region ConstructorTest
@@ -550,3 +551,46 @@ public object this[int key] {
550551 }
551552 }
552553}
554+
555+ namespace ExtensionMethodDemo
556+ {
557+ // First extension class with an out int parameter
558+ public static class StringExtensions
559+ {
560+ public static bool TryParseCustom ( this string input , out int result )
561+ {
562+ return int . TryParse ( input , out result ) ;
563+ }
564+ }
565+
566+ // Second extension class with an out double parameter
567+ public static class StringDoubleExtensions
568+ {
569+ public static bool TryParseCustom ( this string input , out double result )
570+ {
571+ return double . TryParse ( input , out result ) ;
572+ }
573+ }
574+
575+ class Issue2165
576+ {
577+ public static void Test ( )
578+ {
579+ string value1 = "123" ;
580+ string value2 = "123.45" ;
581+ #if CS70
582+ // Use the int version with extension method syntax
583+ if ( value1 . TryParseCustom ( out int intResult ) )
584+ {
585+ Console . WriteLine ( "Parsed int: " + intResult ) ;
586+ }
587+
588+ // Use the double version with extension method syntax
589+ if ( value2 . TryParseCustom ( out double doubleResult ) )
590+ {
591+ Console . WriteLine ( "Parsed double: " + doubleResult ) ;
592+ }
593+ #endif
594+ }
595+ }
596+ }
Original file line number Diff line number Diff line change @@ -622,13 +622,16 @@ void InsertVariableDeclarations(TransformContext context)
622622 {
623623 // 'T v; SomeCall(out v);' can be combined to 'SomeCall(out T v);'
624624 AstType type ;
625+ bool isOutVar = false ;
625626 if ( context . Settings . AnonymousTypes && v . Type . ContainsAnonymousType ( ) )
626627 {
627628 type = new SimpleType ( "var" ) ;
629+ isOutVar = true ;
628630 }
629631 else if ( dirExpr . Annotation < UseImplicitlyTypedOutAnnotation > ( ) != null )
630632 {
631633 type = new SimpleType ( "var" ) ;
634+ isOutVar = true ;
632635 }
633636 else
634637 {
@@ -652,6 +655,11 @@ void InsertVariableDeclarations(TransformContext context)
652655 var ovd = new OutVarDeclarationExpression ( type , name ) ;
653656 ovd . Variable . AddAnnotation ( new ILVariableResolveResult ( ilVariable ) ) ;
654657 ovd . CopyAnnotationsFrom ( dirExpr ) ;
658+ if ( isOutVar )
659+ {
660+ ovd . RemoveAnnotations < ResolveResult > ( ) ;
661+ ovd . AddAnnotation ( new OutVarResolveResult ( v . Type ) ) ;
662+ }
655663 replacements . Add ( ( dirExpr , ovd ) ) ;
656664 }
657665 else
You can’t perform that action at this time.
0 commit comments