question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API proposal: Introduce a strongly-typed diagnostic properties

See original GitHub issue

Background and Motivation

Communication between analyzers and their corresponding codefixes is a very common scenario. Currently there is Diagnostic.Properties property that we can set via the properties parameter on Diagnostic.Create method. However, the existing Properties is a dictionary of string, string. This is often not sufficient.

Proposed API

Option 1

 namespace Microsoft.CodeAnalysis
 {
+    public abstract class Diagnostic<TKey, TValue> : Diagnostic, IEquatable<Diagnostic<TKey, TValue>>, IFormattable
+    {
+        public ImmutableDictionary<TKey, TValue> GenericProperties { get; } // Or, TypedProperties, or some other suitable name
+    }
 }

Option 2

 namespace Microsoft.CodeAnalysis
 {
     public abstract class Diagnostic : IEquatable<Diagnostic>, IFormattable
     {
+        public ImmutableDictionary<object, object> ObjectProperties { get; } // Possibly need to find a better name
     }
 }

Usage Examples

// Analyzer code
context.ReportDiagnostic(Diagnostic<string, ISymbol>.Create(...));

// Codefix
if (context.Diagnostics[0] is Diagnostic<string, ISymbol> diagnostic)
{
    // Do work using diagnostic.GenericProperties
}

Alternative Designs

Risks

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
CyrusNajmabadicommented, Dec 3, 2021

It’s not exposed publicly, but I thought serialization would includes private members as well?

It itself is not serialized (and being an internal member and not part of the public api), cannot be observed.

Anyway, is there some way to overcome those concerns (even by a different proposal)? or it’s simply “impossible”?

I’m def not sure. The benefit of string/string is that it forces the type (and the users) to be able to put in data that is sure to serialize and sure to act as a pure value. It would need a very strong API and design to no longer have that. 😃

0reactions
Youssef1313commented, Dec 3, 2021

It’s not exposed publicly, but I thought serialization would includes private members as well?

Anyway, is there some way to overcome those concerns (even by a different proposal)? or it’s simply “impossible”?

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Diagnostics.Activity: Enumeration API [Iteration 2] · ...
First proposal: #67072 Background and motivation One of the main things ... the contract strongly typed by introducing some new properties.
Read more >
ECMAScript proposal: Type Annotations
This proposal aims to enable developers to add type annotations to their JavaScript code, allowing those annotations to be checked by a type...
Read more >
A Proposal For Type Syntax in JavaScript - TypeScript
Today we're excited to announce our support and collaboration on a new Stage 0 proposal to bring optional and erasable type syntax to ......
Read more >
Announcing 'Machine Learning .NET' 0.5
Specifically, the new ML.NET API offers attractive features which aren't possible with the current LearningPipeline API: Strongly-typed API: ...
Read more >
Zalando RESTful API and Event Guidelines
The purpose of our "RESTful API guidelines" is to define standards to successfully establish "consistent API look and feel" quality.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found