diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..c29d7aba --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,46 @@ +# Contributing to Ardalis.GuardClauses + +We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: + +- Reporting a bug +- Discussing the current state of the code +- Submitting a fix +- Proposing new features + +## We Develop with GitHub + +Obviously... + +## We Use Pull Requests + +Mostly. But pretty much exclusively for non-maintainers. You'll need to fork the repo in order to submit a pull request. Here are the basic steps: + +1. Fork the repo and create your branch from `main`. +2. If you've added code that should be tested, add tests. +3. If you've changed APIs, update the documentation. +4. Ensure the test suite passes. +5. Make sure your code lints. +6. Issue that pull request! + +- [Pull Request Check List](https://ardalis.com/github-pull-request-checklist/) +- [Resync your fork with this upstream repo](https://ardalis.com/syncing-a-fork-of-a-github-repository-with-upstream/) + +## Ask before adding a pull request + +You can just add a pull request out of the blue if you want, but it's much better etitquette (and more likely to be accepted) if you open a new issue or comment in an existing issue stating you'd like to make a pull request. + +## Getting Started + +Look for [issues marked with 'help wanted'](https://github.com/ardalis/guardclauses/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) to find good places to start contributing. + +## Any contributions you make will be under the MIT Software License + +In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers this project. + +## Report bugs using Github's [issues](https://github.com/ardalis/guardclauses/issues) + +We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/ardalis/GuardClauses/issues/new/choose); it's that easy! + +## Sponsor us + +If you don't have the time or expertise to contribute code, you can still support us by [sponsoring](https://github.com/sponsors/ardalis). diff --git a/Directory.Build.props b/Directory.Build.props index 8e9b748c..9254923c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -15,6 +15,7 @@ strict + $(MSBuildThisFileDirectory) $([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectDirectory))) diff --git a/Directory.Packages.props b/Directory.Packages.props index 032f2799..522d9381 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,20 +4,20 @@ - + - + - - - - + + + + diff --git a/README.md b/README.md index acbfd1d0..84176688 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Install-Package Ardalis.SmartEnum -Version 2.1.0 ## Usage -Define your smart enum by inheriting from `SmartEnum` where `TEnum` is the type you're declaring. For [example](/src/SmartEnum.UnitTests/TestEnum.cs): +Define your smart enum by inheriting from `SmartEnum` where `TEnum` is the type you're declaring. For [example](/test/SmartEnum.UnitTests/TestEnum.cs): ```csharp using Ardalis.SmartEnum; diff --git a/src/SmartEnum.EFCore/SmartEnumConverterExtensions.cs b/src/SmartEnum.EFCore/SmartEnumConverterExtensions.cs index cb014836..4b267b81 100644 --- a/src/SmartEnum.EFCore/SmartEnumConverterExtensions.cs +++ b/src/SmartEnum.EFCore/SmartEnumConverterExtensions.cs @@ -6,7 +6,9 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Reflection; using System.Text; namespace SmartEnum.EFCore @@ -23,6 +25,7 @@ public static void ConfigureSmartEnum(this ModelConfigurationBuilder configurati var propertyTypes = modelBuilder.Model.GetEntityTypes() .SelectMany(e => e.ClrType.GetProperties()) .Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(SmartEnum<,>))) + .Where(p => p.GetCustomAttribute() == null) .Select(p => p.PropertyType) .Distinct(); @@ -52,7 +55,8 @@ public static void ConfigureSmartEnum(this ModelBuilder modelBuilder) foreach (var entityType in modelBuilder.Model.GetEntityTypes()) { var properties = entityType.ClrType.GetProperties() - .Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(SmartEnum<,>))); + .Where(p => TypeUtil.IsDerived(p.PropertyType, typeof(SmartEnum<,>))) + .Where(p => p.GetCustomAttribute() == null); foreach (var property in properties) { diff --git a/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeEntity.cs b/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeEntity.cs index 406faa54..2295cea0 100644 --- a/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeEntity.cs +++ b/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeEntity.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; namespace SmartEnum.EFCore.IntegrationTests.Entities { @@ -24,6 +25,9 @@ public class SomeEntity public List OwnedEntities { get; set; } + [NotMapped] + public TestEnum NotMappedTest { get; set; } + public class Configuration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) diff --git a/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOuterOwnedEntity.cs b/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOuterOwnedEntity.cs index a37ea2c7..237af032 100644 --- a/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOuterOwnedEntity.cs +++ b/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOuterOwnedEntity.cs @@ -1,5 +1,7 @@ using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; + namespace SmartEnum.EFCore.IntegrationTests.Entities { [Owned] @@ -18,5 +20,8 @@ public class SomeOuterOwnedEntity public TestBaseEnumWithDerivedValues Test4 { get; set; } public SomeOwnedEntity InnerOwnedEntity { get; set; } + + [NotMapped] + public TestEnum NotMappedTest { get; set; } } } diff --git a/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOwnedEntity.cs b/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOwnedEntity.cs index 1608f87a..64a2278c 100644 --- a/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOwnedEntity.cs +++ b/test/SmartEnum.EFCore.IntegrationTests/Entities/SomeOwnedEntity.cs @@ -1,5 +1,7 @@ using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; + namespace SmartEnum.EFCore.IntegrationTests.Entities { [Owned] @@ -16,5 +18,8 @@ public class SomeOwnedEntity public TestStringEnum Test3 { get; set; } public TestBaseEnumWithDerivedValues Test4 { get; set; } + + [NotMapped] + public TestEnum NotMappedTest { get; set; } } } diff --git a/test/SmartEnum.EFCore.IntegrationTests/SmartEnumEFCoreDbTests.cs b/test/SmartEnum.EFCore.IntegrationTests/SmartEnumEFCoreDbTests.cs index 2097ae8a..a7540612 100644 --- a/test/SmartEnum.EFCore.IntegrationTests/SmartEnumEFCoreDbTests.cs +++ b/test/SmartEnum.EFCore.IntegrationTests/SmartEnumEFCoreDbTests.cs @@ -85,6 +85,7 @@ private static SomeEntity CreateEntity() Test2 = TestDerivedEnum.One, Test3 = TestStringEnum.One, Test4 = DerivedTestEnumWithValues1.A, + NotMappedTest = TestEnum.One, OwnedEntity = new SomeOwnedEntity { Value = 2, @@ -143,6 +144,7 @@ private static void VerifyEntity(SomeEntity entity) entity.Test2.Should().Be(TestDerivedEnum.One); entity.Test3.Should().Be(TestStringEnum.One); entity.Test4.Should().Be(DerivedTestEnumWithValues1.A); + entity.NotMappedTest.Should().BeNull(); entity.OwnedEntity.Value.Should().Be(2); entity.OwnedEntity.Weekday.Should().Be(Weekday.Friday); @@ -150,6 +152,7 @@ private static void VerifyEntity(SomeEntity entity) entity.OwnedEntity.Test2.Should().Be(TestDerivedEnum.One); entity.OwnedEntity.Test3.Should().Be(TestStringEnum.Two); entity.OwnedEntity.Test4.Should().Be(DerivedTestEnumWithValues1.B); + entity.OwnedEntity.NotMappedTest.Should().BeNull(); entity.OuterOwnedEntity.Value.Should().Be(3); entity.OuterOwnedEntity.Weekday.Should().Be(Weekday.Friday); @@ -157,6 +160,7 @@ private static void VerifyEntity(SomeEntity entity) entity.OuterOwnedEntity.Test2.Should().Be(TestDerivedEnum.One); entity.OuterOwnedEntity.Test3.Should().Be(TestStringEnum.Two); entity.OuterOwnedEntity.Test4.Should().Be(DerivedTestEnumWithValues1.B); + entity.OuterOwnedEntity.NotMappedTest.Should().BeNull(); entity.OuterOwnedEntity.InnerOwnedEntity.Value.Should().Be(4); entity.OuterOwnedEntity.InnerOwnedEntity.Weekday.Should().Be(Weekday.Friday); @@ -164,6 +168,7 @@ private static void VerifyEntity(SomeEntity entity) entity.OuterOwnedEntity.InnerOwnedEntity.Test2.Should().Be(TestDerivedEnum.One); entity.OuterOwnedEntity.InnerOwnedEntity.Test3.Should().Be(TestStringEnum.Two); entity.OuterOwnedEntity.InnerOwnedEntity.Test4.Should().Be(DerivedTestEnumWithValues1.B); + entity.OuterOwnedEntity.InnerOwnedEntity.NotMappedTest.Should().BeNull(); entity.OwnedEntities.Should().SatisfyRespectively( o => @@ -174,6 +179,7 @@ private static void VerifyEntity(SomeEntity entity) o.Test2.Should().Be(TestDerivedEnum.One); o.Test3.Should().Be(TestStringEnum.Three); o.Test4.Should().Be(DerivedTestEnumWithValues1.A); + o.NotMappedTest.Should().BeNull(); }, o => { @@ -183,6 +189,7 @@ private static void VerifyEntity(SomeEntity entity) o.Test2.Should().Be(TestDerivedEnum.One); o.Test3.Should().Be(TestStringEnum.One); o.Test4.Should().Be(DerivedTestEnumWithValues1.B); + o.NotMappedTest.Should().BeNull(); }); } }