CommunityToolkit / CommunityToolkit/dotnet

Consider CLS-compliancy

Open
#571 11 comments 0 reactions 0 assignees View on GitHub
feature request :mailbox_with_mail: mvvm-toolkit :toolbox:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Overview

Currently we have (among others) following properties set in our `Directory.Build.props`:
```xml
AllEnabledByDefault
true

```
Due to [`CA1014`](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1014), we've marked our assemblies with
```csharp
[assembly: CLSCompliant(true)]
```
This we do not want to change.

Previously we've made use of code generation and marked our viewmodels with the `ObservableObjectAttribute`. However, with the newest version, this triggers the analyzer `MVVMTK0033` ("The type XXX is using the [ObservableObject] attribute while having no base type, and it should instead inherit from ObservableObject").

If we follow this advice and inherit from `ObservableObject`, the analyzer [`CS3009`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs3009) triggers because even tho the class is technically compliant with the common language specification, it is not marked as such.

### API breakdown

I would like to propose marking either the whole assembly as `CLSCompliant` or (at least) marking `ObservableObject` as such.

### Usage example

```csharp
public sealed partial class MyViewModel : ObservableObject {
...
}
```

### Breaking change?

No

### Alternatives

```csharp
[ObservableObject]
#pragma warning disable MVVMTK0033
public sealed partial class MyViewModel {
#pragma warning restore MVVMTK0033
...
}
```

### Additional context

Thank you in advance for considering the inclusion of this.

### Help us help you

Yes, but only if others can assist

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.