Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public void AnalyzeSymbol(SymbolAnalysisContext context)
break;

case IMethodSymbol methodSymbol when methodSymbol.MethodKind is not MethodKind.PropertyGet and not MethodKind.PropertySet:
if (context.Symbol is IMethodSymbol { MethodKind: MethodKind.Conversion })
return;

if (!IsValidType(methodSymbol.ReturnType))
{
context.ReportDiagnostic(Rule, methodSymbol, DiagnosticMethodReportOptions.ReportOnReturnType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Meziantou.Analyzer.Test.Helpers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
Expand All @@ -17,7 +9,6 @@
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Text;
using Xunit;

namespace TestHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,44 @@ public class Test : ITest
""")
.ValidateAsync();
}

[Fact]
public async Task ConversionOperator()
{
await CreateProjectBuilder()
.WithSourceCode("""
public class Sample
{
public static implicit operator Sample(System.Collections.Generic.List<string> _) => throw null;
public static implicit operator System.Collections.Generic.List<string>(Sample _) => throw null;
}
""")
.ValidateAsync();
}

[Fact]
public async Task AddOperator()
{
await CreateProjectBuilder()
.WithSourceCode("""
public class Sample
{
public static Sample operator+(Sample instance, [|System.Collections.Generic.List<int>|] value) => throw null;
}
""")
.ValidateAsync();
}

[Fact]
public async Task AddOperator_Instance()
{
await CreateProjectBuilder()
.WithSourceCode("""
public class Sample : System.Collections.Generic.List<int>
{
public static Sample operator+(Sample instance, int value) => throw null;
}
""")
.ValidateAsync();
}
}