Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed JsonPropertyName to JsonPropertyNameAttribute #1074

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Meadow.Foundation.Serialization;
/// Specifies the property name that is present in the JSON when serializing and deserializing.
/// </summary>
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
public class JsonPropertyName : Attribute
public class JsonPropertyNameAttribute : Attribute
{
/// <summary>
/// Gets the name of the property.
Expand All @@ -17,7 +17,7 @@ public class JsonPropertyName : Attribute
/// Initializes a new instance of JsonPropertyNameAttribute with the specified property name.
/// </summary>
/// <param name="propertyName">The name of the property</param>
public JsonPropertyName(string propertyName)
public JsonPropertyNameAttribute(string propertyName)
{
PropertyName = propertyName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private static void Deserialize(Hashtable? root, Type type, ref object instance)

(PropertyInfo Property, string MappedTo)[] nameMap =
props.Select((propertyInfo, index) => (
propertyInfo.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(JsonPropertyName)),
propertyInfo.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(JsonPropertyNameAttribute)),
props[index]))
.Where(p => p.Item1 != null)
.Select(t => (t.Item2, t.Item1.ConstructorArguments[0].Value.ToString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static string EscapeString(string value)
{
object returnObject = property.GetValue(o);

var mappedName = property.GetCustomAttribute<JsonPropertyName>(true);
var mappedName = property.GetCustomAttribute<JsonPropertyNameAttribute>(true);

var name = mappedName != null
? mappedName.PropertyName
Expand Down
Loading