-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Unicode annotation and the capability of generating UnicodeAttribute when scaffolding.
- Loading branch information
HuyLuong
committed
Sep 12, 2020
1 parent
b647bd1
commit 5cdae72
Showing
7 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.EntityFrameworkCore | ||
{ | ||
/// <summary> | ||
/// Configures the property as capable of persisting unicode characters. Can only be set on System.String properties. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] | ||
public sealed class UnicodeAttribute : Attribute | ||
{ | ||
/// <summary> | ||
/// A value indicating whether the property can contain unicode characters or not. | ||
/// </summary> | ||
public bool IsUnicode { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="UnicodeAttribute" /> class. | ||
/// </summary> | ||
/// <param name="isUnicode">A value indicating whether the property can contain unicode characters or not.</param> | ||
public UnicodeAttribute(bool isUnicode = true) | ||
{ | ||
IsUnicode = isUnicode; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/EFCore/Metadata/Conventions/UnicodeAttributeConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Reflection; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; | ||
|
||
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions | ||
{ | ||
/// <summary> | ||
/// A convention that configures the Unicode based on the <see cref="UnicodeAttribute" /> applied on the property. | ||
/// </summary> | ||
public class UnicodeAttributeConvention : PropertyAttributeConventionBase<UnicodeAttribute> | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="UnicodeAttributeConvention" />. | ||
/// </summary> | ||
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param> | ||
public UnicodeAttributeConvention([NotNull] ProviderConventionSetBuilderDependencies dependencies) | ||
: base(dependencies) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Called after a property is added to the entity type with an attribute on the associated CLR property or field. | ||
/// </summary> | ||
/// <param name="propertyBuilder"> The builder for the property. </param> | ||
/// <param name="attribute"> The attribute. </param> | ||
/// <param name="clrMember"> The member that has the attribute. </param> | ||
/// <param name="context"> Additional information associated with convention execution. </param> | ||
protected override void ProcessPropertyAdded( | ||
IConventionPropertyBuilder propertyBuilder, | ||
UnicodeAttribute attribute, | ||
MemberInfo clrMember, | ||
IConventionContext context) | ||
{ | ||
propertyBuilder.IsUnicode(unicode: attribute.IsUnicode, fromDataAnnotation: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters