Skip to content

Commit

Permalink
Add support for MetadataType Attribute (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsigi authored Jan 8, 2025
1 parent e5ccd01 commit 0f5d1bd
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ public class WithRegex
<sup><a href='/src/Destructurama.Attributed.Tests/Snippets.cs#L6-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-WithRegex' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## 8. Working with MetadataTypeAttribute

You can apply [`MetadataTypeAttribute`](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.metadatatypeattribute) to your class providing another type with annotated properties. It may help you in the case when source type with its properties is defined in a code generated file so you don't want to put the attributes in there as they would get overwritten by the generator. Note that you have to set `AttributedDestructuringPolicyOptions.RespectMetadataTypeAttribute` to `true`.

```csharp
var log = new LoggerConfiguration()
.Destructure.UsingAttributes(x => x.RespectMetadataTypeAttribute = true)
...
```

# Benchmarks

The results are available [here](https://destructurama.github.io/attributed/dev/bench/).
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Destructurama.Attributed
public AttributedDestructuringPolicyOptions() { }
public bool IgnoreNullProperties { get; set; }
public bool RespectLogPropertyIgnoreAttribute { get; set; }
public bool RespectMetadataTypeAttribute { get; set; }
}
public interface IPropertyDestructuringAttribute
{
Expand Down
337 changes: 337 additions & 0 deletions src/Destructurama.Attributed.Tests/MetadataTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
using System.ComponentModel.DataAnnotations;
using Destructurama.Attributed.Tests.Support;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Serilog.Events;
using Shouldly;

namespace Destructurama.Attributed.Tests;

[TestFixture]
public class MetadataTypeTests
{
[SetUp]
public void SetUp()
{
AttributedDestructuringPolicy.Clear();
}

[TearDown]
public void TearDown()
{
AttributedDestructuringPolicy.Clear();
}

[Test]
public void MetadataType_Should_Not_Be_Respected()
{
var customized = new Dto
{
Private = "secret",
Public = "not_Secret"
};

var evt = DelegatingSink.Execute(customized);

var sv = (StructureValue)evt.Properties["Customized"];
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);

props.Count.ShouldBe(2);
props["Public"].LiteralValue().ShouldBe("not_Secret");
props["Private"].LiteralValue().ShouldBe("secret");
}

[Test]
public void MetadataType_Should_Be_Respected()
{
var customized = new Dto
{
Private = "secret",
Public = "not_Secret"
};

var evt = DelegatingSink.Execute(customized, configure: opt => opt.RespectMetadataTypeAttribute = true);

var sv = (StructureValue)evt.Properties["Customized"];
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);

props.Count.ShouldBe(1);
props["Public"].LiteralValue().ShouldBe("not_Secret");
}

[Test]
public void MetadataTypeWithDerived_Should_Be_Respected()
{
var customized = new DtoWithDerived
{
Private = "secret",
Public = "not_Secret"
};

var evt = DelegatingSink.Execute(customized, configure: opt => opt.RespectMetadataTypeAttribute = true);

var sv = (StructureValue)evt.Properties["Customized"];
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);

props.Count.ShouldBe(1);
props["Public"].LiteralValue().ShouldBe("not_Secret");
}

[Test]
public void WithMask_NotLoggedIfNull_Initialized()
{
var customized = new AttributedWithMask
{
String = "Foo[Masked]",
Object = "Bar[Masked]",
};

var evt = DelegatingSink.Execute(customized, configure: x =>
{
x.IgnoreNullProperties = true;
x.RespectMetadataTypeAttribute = true;
});

var sv = (StructureValue)evt!.Properties["Customized"];
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);

props.ContainsKey("String").ShouldBeTrue();
props.ContainsKey("Object").ShouldBeTrue();

props["String"].LiteralValue().ShouldBe("Foo***");
props["Object"].LiteralValue().ShouldBe("Bar***");
}


[Test]
public void AttributesAreConsultedWhenDestructuringWithMeta()
{
var customized = new CustomizedWithMeta
{
ImmutableScalar = new(),
MutableScalar = new(),
NotAScalar = new(),
Ignored = "Hello, there",
Ignored2 = "Hello, there again",
ScalarAnyway = new(),
AuthData = new()
{
Username = "This is a username",
Password = "This is a password"
}
};

var evt = DelegatingSink.Execute(customized, configure: opt =>
{
opt.RespectLogPropertyIgnoreAttribute = true;
opt.RespectMetadataTypeAttribute = true;
});

var sv = (StructureValue)evt.Properties["Customized"];
var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);

props.ShouldNotContainKey("Ignored");
props.ShouldNotContainKey("Ignored2");

props["ImmutableScalar"].LiteralValue().ShouldBeOfType<ImmutableScalar>();
props["MutableScalar"].LiteralValue().ShouldBe(new MutableScalar().ToString());
props["NotAScalar"].ShouldBeOfType<StructureValue>();
props.ContainsKey("Ignored").ShouldBeFalse();
props["ScalarAnyway"].LiteralValue().ShouldBeOfType<NotAScalar>();
props["Struct1"].LiteralValue().ShouldBeOfType<Struct1>();
props["Struct2"].LiteralValue().ShouldBeOfType<Struct2>();
props["StructReturningNull"].LiteralValue().ShouldBeNull();
props["StructNull"].LiteralValue().ShouldBeNull();

var str = sv.ToString();
str.Contains("This is a username").ShouldBeTrue();
str.Contains("This is a password").ShouldBeFalse();
}

[Test]
public void Private_Property_Should_Be_Handled()
{
var customized = new ClassWithPrivateProperty();

var evt = DelegatingSink.Execute(customized);

var sv = (StructureValue)evt.Properties["Customized"];
sv.Properties.Count.ShouldBe(0);
}

#region Simple Metadata
/// <summary>
/// Simple Metadata Sample
/// </summary>
[MetadataType(typeof(DtoMetadata))]
private partial class Dto
{
public string Private { get; set; }

Check warning on line 169 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 169 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 169 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 169 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Public { get; set; }

Check warning on line 171 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 171 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 171 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 171 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

private class DtoMetadata
{
[NotLogged]
public object Private { get; set; }

Check warning on line 177 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 177 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 177 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
#endregion

#region Metadata with derived subclass
/// <summary>
/// Metadata Sample with derived subclass
/// </summary>
[MetadataType(typeof(DtoMetadataDerived))]
private partial class DtoWithDerived
{
public string Private { get; set; }

Check warning on line 188 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 188 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 188 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string Public { get; set; }

Check warning on line 190 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 190 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 190 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

private class DtoMetadataBase
{
public object Public { get; set; }

Check warning on line 195 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 195 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 195 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Public' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

private class DtoMetadataDerived : DtoMetadataBase
{
[NotLogged]
public object Private { get; set; }

Check warning on line 201 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 201 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 201 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Private' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
#endregion

#region Attributed With Mask in MetadataType
[MetadataType(typeof(AttributedWithMaskMetaData))]
private class AttributedWithMask
{
public string? String { get; set; }

public object? Object { get; set; }
}

private class AttributedWithMaskMetaData
{
[LogMasked(ShowFirst = 3)]
public object String { get; set; }

Check warning on line 217 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'String' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 217 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'String' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 217 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'String' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[LogMasked(ShowFirst = 3)]
public object Object { get; set; }

Check warning on line 220 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Object' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 220 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Object' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 220 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Object' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
#endregion

#region All Attributes visited
/// <summary>
/// Attribute on class in Metadatatype
/// </summary>
[LogAsScalar]
public class ImmutableScalar
{
public ImmutableScalar()
{
}
}

[LogAsScalar(isMutable: true)]
public class MutableScalar
{
}

public class NotAScalar
{
}

[MetadataType(typeof(CustomizedMeta))]
public class CustomizedWithMeta
{
public ImmutableScalar? ImmutableScalar { get; set; }
public MutableScalar? MutableScalar { get; set; }
public NotAScalar? NotAScalar { get; set; }
public string? Ignored { get; set; }
public string? Ignored2 { get; set; }
public NotAScalar? ScalarAnyway { get; set; }
public UserAuthData? AuthData { get; set; }
public Struct1 Struct1 { get; set; }
public Struct2 Struct2 { get; set; }
public StructReturningNull StructReturningNull { get; set; }
public StructReturningNull? StructNull { get; set; }
}

public class CustomizedMeta
{
public ImmutableScalar? ImmutableScalar { get; set; }
public MutableScalar? MutableScalar { get; set; }
public NotAScalar? NotAScalar { get; set; }

[NotLogged]
public object Ignored { get; set; }

Check warning on line 268 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Ignored' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 268 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Ignored' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 268 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Ignored' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[LogPropertyIgnore]
public object Ignored2 { get; set; }

Check warning on line 271 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Ignored2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 271 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Ignored2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 271 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Ignored2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[LogAsScalar]
public object ScalarAnyway { get; set; }

Check warning on line 274 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'ScalarAnyway' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 274 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'ScalarAnyway' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 274 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'ScalarAnyway' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public UserAuthData? AuthData { get; set; }

[LogAsScalar]
public object Struct1 { get; set; }

Check warning on line 278 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Struct1' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 278 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Struct1' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 278 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Struct1' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public object Struct2 { get; set; }

Check warning on line 280 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Struct2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 280 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Struct2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 280 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Struct2' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[LogAsScalar(isMutable: true)]
public object StructReturningNull { get; set; }

Check warning on line 283 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'StructReturningNull' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 283 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'StructReturningNull' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[LogAsScalar(isMutable: true)]
public object StructNull { get; set; }

Check warning on line 286 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'StructNull' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 286 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'StructNull' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

public class UserAuthDataMeta
{
public object Username { get; set; }

Check warning on line 291 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Username' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 291 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Username' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 291 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Username' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[NotLogged]
public object Password { get; set; }

Check warning on line 294 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 294 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 294 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

[MetadataType(typeof(UserAuthDataMeta))]
public class UserAuthData
{
public string? Username { get; set; }
public string? Password { get; set; }
}

public struct Struct1
{
public int SomeProperty { get; set; }
public override string ToString() => "AAA";
}

[LogAsScalar]
public struct Struct2
{
public int SomeProperty { get; set; }
public override string ToString() => "BBB";
}

public struct StructReturningNull
{
public int SomeProperty { get; set; }
public override string ToString() => null!;
}
#endregion

#region Private
public class ClassWithPrivatePropertyMeta
{
[LogMasked]
private object Name { get; set; }

Check warning on line 328 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / pack

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 328 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 328 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 328 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 328 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 328 in src/Destructurama.Attributed.Tests/MetadataTypeTests.cs

View workflow job for this annotation

GitHub Actions / analyze

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}

[MetadataType(typeof(ClassWithPrivatePropertyMeta))]
public class ClassWithPrivateProperty
{
private string? Name { get; set; } = "Tom";
}
#endregion
}
Loading

0 comments on commit 0f5d1bd

Please sign in to comment.