Skip to content

Commit 708c82d

Browse files
Stop outputting when there are no events - WIP
Will also need to update the override in initializestatement
1 parent fe8a2f6 commit 708c82d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

CodeConverter/CSharp/MethodWithHandles.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ public static IEnumerable<MemberDeclarationSyntax> GetDeclarationsForFieldBacked
3939
{
4040
// It should be safe to use the underscore name since in VB the compiler generates a backing field with that name, and errors if you try to clash with it
4141
var variablesToMap = decl.Variables
42-
.Select(v => (Variable: v, HasEvents: true, NewId: SyntaxFactory.Identifier("_" + v.Identifier.Text))).ToArray();
42+
.Select(v => (Variable: v, HasEvents: HasEvents(methodsWithHandles, v.Identifier), NewId: SyntaxFactory.Identifier("_" + v.Identifier.Text))).ToArray();
4343
var fieldDecl = decl.WithVariables(SyntaxFactory.SeparatedList(
44-
variablesToMap.Select(m => m.Variable.WithIdentifier(m.NewId))
44+
variablesToMap.Select(m => m.HasEvents ? m.Variable.WithIdentifier(m.NewId) : m.Variable)
4545
));
4646
var fieldModifiers = SyntaxFactory.TokenList(new[] {SyntaxFactory.Token(SyntaxKind.PrivateKeyword)}.Concat(convertedModifiers.Where(m => !m.IsCsVisibility(false, false))));
4747
yield return SyntaxFactory.FieldDeclaration(attributes, fieldModifiers, fieldDecl);
48-
foreach (var mapping in variablesToMap) {
48+
foreach (var mapping in variablesToMap.Where(v => v.HasEvents)) {
4949
yield return GetDeclarationsForFieldBackedProperty(methodsWithHandles, attributes, convertedModifiers,
5050
decl.Type, mapping.Variable.Identifier,
5151
mapping.NewId);
5252
}
5353
}
5454

55+
private static bool HasEvents(IReadOnlyCollection<MethodWithHandles> methodsWithHandles, SyntaxToken propertyId) =>
56+
methodsWithHandles.Any(m => m.GetPropertyEvents(propertyId.Text).Any());
57+
5558
private static PropertyDeclarationSyntax GetDeclarationsForFieldBackedProperty(IReadOnlyCollection<MethodWithHandles> methods,
5659
SyntaxList<AttributeListSyntax> attributes, SyntaxTokenList convertedModifiers, TypeSyntax typeSyntax,
5760
SyntaxToken propertyIdentifier, SyntaxToken fieldIdentifier)

0 commit comments

Comments
 (0)