File tree Expand file tree Collapse file tree 2 files changed +58
-1
lines changed
ICSharpCode.CodeConverter/CSharp Expand file tree Collapse file tree 2 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -363,7 +363,9 @@ public override CSharpSyntaxNode VisitFieldDeclaration(VBSyntax.FieldDeclaration
363363 foreach ( var declarator in node . Declarators ) {
364364 foreach ( var decl in CommonConversions . SplitVariableDeclarations ( declarator ) . Values ) {
365365 if ( isWithEvents ) {
366- var initializers = decl . Variables . ToDictionary ( v => v . Identifier . Text , v => v . Initializer ) ;
366+ var initializers = decl . Variables
367+ . Where ( a => a . Initializer != null )
368+ . ToDictionary ( v => v . Identifier . Text , v => v . Initializer ) ;
367369 var fieldDecl = decl . RemoveNodes ( initializers . Values , SyntaxRemoveOptions . KeepNoTrivia ) ;
368370 var initializerCollection = convertedModifiers . Any ( m => m . IsKind ( SyntaxKind . StaticKeyword ) )
369371 ? _additionalInitializers . AdditionalStaticInitializers
Original file line number Diff line number Diff line change @@ -435,6 +435,61 @@ public static void PrintTestMessage3()
435435}" ) ;
436436 }
437437
438+ [ Fact ]
439+ public void TestWitheventsWithoutInitializer ( )
440+ {
441+ TestConversionVisualBasicToCSharpWithoutComments (
442+ @"Class MyEventClass
443+ Public Event TestEvent()
444+ End Class
445+ Class Class1
446+ WithEvents MyEventClassInstance As MyEventClass
447+ Sub EventClassInstance_TestEvent() Handles MyEventClassInstance.TestEvent
448+ End Sub
449+ End Class" , @"using System.Runtime.CompilerServices;
450+
451+ class MyEventClass
452+ {
453+ public event TestEventEventHandler TestEvent;
454+
455+ public delegate void TestEventEventHandler();
456+ }
457+
458+ class Class1
459+ {
460+ private MyEventClass _MyEventClassInstance;
461+
462+ private MyEventClass MyEventClassInstance
463+ {
464+ [MethodImpl(MethodImplOptions.Synchronized)]
465+ get
466+ {
467+ return _MyEventClassInstance;
468+ }
469+
470+ [MethodImpl(MethodImplOptions.Synchronized)]
471+ set
472+ {
473+ if (_MyEventClassInstance != null)
474+ {
475+ _MyEventClassInstance.TestEvent -= EventClassInstance_TestEvent;
476+ }
477+
478+ _MyEventClassInstance = value;
479+ if (_MyEventClassInstance != null)
480+ {
481+ _MyEventClassInstance.TestEvent += EventClassInstance_TestEvent;
482+ }
483+ }
484+ }
485+
486+ public void EventClassInstance_TestEvent()
487+ {
488+ }
489+ }
490+ " ) ;
491+ }
492+
438493 [ Fact ]
439494 public void TestClassHandlesWithEvents ( )
440495 {
You can’t perform that action at this time.
0 commit comments