public void InternalConstructorSetsAllNeededData_When_EventIsField() { EventFieldDeclarationSyntax decl = GetNode <EventFieldDeclarationSyntax>("class Test { event System.Action e1, e2 }"); const int index = 1; VariableDeclaratorSyntax var = decl.Declaration.Variables[index]; SemanticModel semanticModel = Compilation.CurrentCompilation.GetSemanticModel(decl.SyntaxTree); IEventSymbol symbol = (semanticModel.GetDeclaredSymbol(var) as IEventSymbol) !; Data.EventData data = new(symbol, Compilation); Location location = decl.GetLocation(); Assert.True( data.SemanticModel is not null && data.SemanticModel.SyntaxTree.IsEquivalentTo(semanticModel.SyntaxTree) && data.Symbol is not null && SymbolEqualityComparer.Default.Equals(data.Symbol, symbol) && data.Location is not null && data.Location == location && data.Declaration is not null && data.Declaration.IsEquivalentTo(decl) && data.ParentCompilation is not null && data.ParentCompilation == Compilation && data.AsProperty is null && data.AsField is not null && data.AsField.IsEquivalentTo(decl) && data.Variable is not null && data.Variable.IsEquivalentTo(var) && data.Index == index ); }
//TODO: Use symbol (instead of syntax node), remove code duplication from property handling // It looks like there's a bug since Roslyn is failing to resolve the symbol for the event private string MakeGenericTypeIfAppropriate(EventFieldDeclarationSyntax node, string existingFieldVar) { var typeDecl = ((TypeDeclarationSyntax)node.Parent); if (typeDecl.TypeParameterList == null || typeDecl.TypeParameterList.IsMissing) { return(existingFieldVar); } //TODO: Register the following variable? var genTypeVar = TempLocalVar($"gt_{node.Declaration.Variables[0].Identifier.Text}_{node.GetLocation().SourceSpan.Start}"); AddCecilExpressions(new[] { $"var {genTypeVar} = {eventDeclaringTypeVar}.MakeGenericInstanceType({eventDeclaringTypeVar}.GenericParameters.ToArray());", $"var {genTypeVar}_ = new FieldReference({existingFieldVar}.Name, {existingFieldVar}.FieldType, {genTypeVar});", }); return($"{genTypeVar}_"); }