Skip to main content
Filter by
Sorted by
Tagged with
0 votes
2 answers
94 views

I am working on a Roslyn Diagnostic Analyzer and Code Fix Provider. Part of this entails an attribute, which takes a parameter of a method name, to override some validation logic. One of the ...
Dominick's user avatar
  • 496
0 votes
0 answers
75 views

Use Case Given a class with a specific attribute, during compilation, look for classes with that attribute, evaluate all the properties for the class, add [Display(Name = "some value")] to ...
Ron O's user avatar
  • 107
1 vote
1 answer
125 views

I was surprised that no analyzer found the wrong usage of async APIs like that: public void NoAnalyzerFindsThatIssue() { // does not trigger https://learn.microsoft.com/en-us/dotnet/csharp/...
stefan.seeland's user avatar
1 vote
1 answer
64 views

A simple class with a copy constructor, which calls another constructor: public class Foo<TEnum> where TEnum : Enum { public Foo(TEnum myEnum) { MyEnum = myEnum; } public Foo(Foo<...
lonix's user avatar
  • 22.4k
0 votes
1 answer
26 views

CodeGeneration. Problems calling ReplaceTrivia method on some comments. The issue arises when attempting to replace all comments in a method using the ReplaceTrivia method from the Roslyn API. ...
PhiseySt's user avatar
  • 158
2 votes
0 answers
111 views

I have a project specific roslyn source generator. It is a project reference in a library (which is also a project reference) in my application. <ProjectReference Include="$(RepoRoot)\...
Evan's user avatar
  • 2,586
0 votes
1 answer
77 views

I have created a diagnostic analyzer which reports various issues with custom attributes for properties. However, I am having trouble get the location of only the attribute and/or attribute arguments ...
Dominick's user avatar
  • 496
0 votes
0 answers
35 views

I am trying to learn how to create a Roslyn diagnostic analyzer and decided to try to develop it against a library I recently created; specifically, for one of the attributes. The attribute is called ...
Dominick's user avatar
  • 496
0 votes
0 answers
48 views

I have an analyzer (targeting netstandard2.0) relying on Microsoft.CodeAnalysis v 4.12.0, which in turn has reference to System.Memory v 4.6.0. And I have no direct reference to any other version of ...
ZorgoZ's user avatar
  • 3,758
1 vote
0 answers
90 views

I have a bit of a peculiar problem at work: In this project all of the ErrorCodes are defined in the code base. They look somewhat like this: public readonly ErrorMessageCode 00001 = new ...
RedSonja's user avatar
  • 340
2 votes
0 answers
111 views

I have the following code Try it here using System; using System.Diagnostics.CodeAnalysis; public class Base{ protected Base(){ Initialize(); } protected virtual void ...
infinitezero's user avatar
  • 2,147
0 votes
0 answers
81 views

I am on a roslyn analyzer that can handle async Task<T> boxing to an object variable like: int GetValue() => ... void Print(object value) => Console.WriteLine(value); void Main() { ...
kevin wolf's user avatar
15 votes
1 answer
2k views

In C# 12 there's the "Collection initialization can be simplified" analyser IDE0028. I've been wondering how the fixer decides when to fix or not fix initialisers such as new(), new List<...
lonix's user avatar
  • 22.4k
1 vote
2 answers
144 views

Is there a way to highlight certain class usage as a warning? For example I want to restrict usage of System.Math in my project. Can I somehow configure Rider or Roslyn to make it underline all ...
Nikolai's user avatar
  • 1,201
1 vote
1 answer
131 views

I am writing some Roslyn Analyzers at the moment and some of them have to use information from several classes (usualy located in different files) in order to fullfill their job. For example, I need ...
Baumeister28's user avatar
0 votes
2 answers
178 views

I'm trying to format code automatically to improve readability using Roslyn. This is what my method looks like: public SyntaxNode GetFormatedNode(SyntaxNode node) { var workspace = new ...
Shems Asfouri's user avatar
0 votes
1 answer
157 views

I have an ITemplate interface in my project. All interfaces derived from it have names that do not start with I. This causes the InconsistentNaming warning to appear. I want to suppress this warning ...
C6OI's user avatar
  • 3
0 votes
1 answer
78 views

Is there a way to tell the compiler that a following check will ensure that Item is not null and it is safe in the rest of the code and the CS8601 warning is not needed? The warning, which technically ...
Tony Basallo's user avatar
  • 3,134
0 votes
1 answer
754 views

I have a solution which contains 4 projects. One of them is a Roslyn source generator, one is a class library which uses the source generator, one is a testing project which also uses the source ...
kinderhead's user avatar
0 votes
0 answers
30 views

My project is a complex data modelling tool. To save me having to write bespoke reports for it, I added the facility for users to write macros to extract the data they need (in reality it is just me ...
steveo40's user avatar
  • 931
1 vote
0 answers
52 views

I've noticed an oddity in the way Visual Studio's popup (when you hover over a variable) displays non-nullable reference types, for example: clipData.GetFormats() returns a string[] - a non-nullable ...
Jez's user avatar
  • 30.5k
3 votes
2 answers
257 views

We have some code which names infrastructure constructs based on a few criteria, including the environment name. Here's a simplified example: enum AppEnvironment { Dev, Staging, Production ...
Jacob Stamm's user avatar
  • 1,908
0 votes
0 answers
205 views

I have created a Roslyn analyzer using the Analyzer with Code Fix template in Visual Studio 2022. Everything works in unit tests, but no diagnostics are shown up in Visual Studio. A minimal example ...
Dark Daskin's user avatar
  • 1,564
4 votes
1 answer
465 views

I'm writing a source generator (IIncrementalGenerator to be specific) and I want to make sure that the caching is correctly responding to changes in the source code. Run the source generator Assert ...
user3797758's user avatar
  • 1,113
2 votes
2 answers
3k views

I'm currently trying to create a new code analysis rule for Visual Studio 2022 so i followed this tutorial. When you follow the tutorial, you have to create a new Analyzer with Code Fix (.NET Standard)...
Alessandro's user avatar

1
2 3 4 5
17