From 7bb51a21e1e92bd1a595b14bcac223cb2eb40e72 Mon Sep 17 00:00:00 2001 From: Guilherme Werner Date: Tue, 19 Nov 2024 17:57:48 -0300 Subject: [PATCH] Add Tribufu.ComponentModel --- Directory.Build.props | 13 ++++++++ Directory.Packages.props | 2 ++ Tribufu.sln | 6 ++++ .../EnumMemberConverter.cs | 30 +++++++++++++++++++ src/Tribufu.ComponentModel/README.md | 1 + .../Tribufu.ComponentModel.csproj | 16 ++++++++++ src/Tribufu.Native/Tribufu.Native.csproj | 13 ++------ .../Tribufu.Serialization.Newtonsoft.csproj | 13 ++------ .../Tribufu.Serialization.csproj | 7 ----- src/Tribufu.Utils/Tribufu.Utils.csproj | 11 ++----- src/Tribufu/Tribufu.csproj | 18 +++++------ 11 files changed, 84 insertions(+), 46 deletions(-) create mode 100644 Directory.Build.props create mode 100644 src/Tribufu.ComponentModel/EnumMemberConverter.cs create mode 100644 src/Tribufu.ComponentModel/README.md create mode 100644 src/Tribufu.ComponentModel/Tribufu.ComponentModel.csproj diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..62f2166 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,13 @@ + + + 1.0.0.0 + Tribufu + Tribufu + Copyright (c) Tribufu. All Rights Reserved. + 1.0.0.0 + MIT + git + https://github.com/Tribufu/TribufuNet + 1.0.0 + + diff --git a/Directory.Packages.props b/Directory.Packages.props index a10ed18..cd87747 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,5 +4,7 @@ + + diff --git a/Tribufu.sln b/Tribufu.sln index 3cbe010..997c7df 100644 --- a/Tribufu.sln +++ b/Tribufu.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu", "src\Tribufu\Trib EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Utils", "src\Tribufu.Utils\Tribufu.Utils.csproj", "{8F16FBBB-199E-4EE3-BFF3-31DD6F84DCD0}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.ComponentModel", "src\Tribufu.ComponentModel\Tribufu.ComponentModel.csproj", "{3DFBC35E-62A7-4CB0-81D9-5E7AA1882557}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +39,10 @@ Global {8F16FBBB-199E-4EE3-BFF3-31DD6F84DCD0}.Debug|Any CPU.Build.0 = Debug|Any CPU {8F16FBBB-199E-4EE3-BFF3-31DD6F84DCD0}.Release|Any CPU.ActiveCfg = Release|Any CPU {8F16FBBB-199E-4EE3-BFF3-31DD6F84DCD0}.Release|Any CPU.Build.0 = Release|Any CPU + {3DFBC35E-62A7-4CB0-81D9-5E7AA1882557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3DFBC35E-62A7-4CB0-81D9-5E7AA1882557}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3DFBC35E-62A7-4CB0-81D9-5E7AA1882557}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3DFBC35E-62A7-4CB0-81D9-5E7AA1882557}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Tribufu.ComponentModel/EnumMemberConverter.cs b/src/Tribufu.ComponentModel/EnumMemberConverter.cs new file mode 100644 index 0000000..38d62e3 --- /dev/null +++ b/src/Tribufu.ComponentModel/EnumMemberConverter.cs @@ -0,0 +1,30 @@ +// Copyright (c) Tribufu. All Rights Reserved. +// SPDX-License-Identifier: MIT + +using System; +using System.ComponentModel; +using System.Globalization; +using System.Runtime.Serialization; + +namespace Tribufu.ComponentModel +{ + public class EnumMemberConverter : EnumConverter + { + public EnumMemberConverter(Type type) : base(type) { } + + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + var type = typeof(T); + + foreach (var field in type.GetFields()) + { + if (Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)) is EnumMemberAttribute attribute && value is string enumValue && attribute.Value == enumValue) + { + return field.GetValue(null); + } + } + + return base.ConvertFrom(context, culture, value); + } + } +} diff --git a/src/Tribufu.ComponentModel/README.md b/src/Tribufu.ComponentModel/README.md new file mode 100644 index 0000000..54c1ab5 --- /dev/null +++ b/src/Tribufu.ComponentModel/README.md @@ -0,0 +1 @@ +# Tribufu diff --git a/src/Tribufu.ComponentModel/Tribufu.ComponentModel.csproj b/src/Tribufu.ComponentModel/Tribufu.ComponentModel.csproj new file mode 100644 index 0000000..2452ac6 --- /dev/null +++ b/src/Tribufu.ComponentModel/Tribufu.ComponentModel.csproj @@ -0,0 +1,16 @@ + + + Tribufu.ComponentModel + Tribufu Component Model Helpers + README.md + + + Library + Properties + net5.0 + true + + + + + diff --git a/src/Tribufu.Native/Tribufu.Native.csproj b/src/Tribufu.Native/Tribufu.Native.csproj index feb26aa..948bb44 100644 --- a/src/Tribufu.Native/Tribufu.Native.csproj +++ b/src/Tribufu.Native/Tribufu.Native.csproj @@ -1,15 +1,8 @@  Tribufu.Native - 0.1.0 Tribufu Native Interop - Tribufu - Tribufu README.md - MIT - Copyright (c) Tribufu. All Rights Reserved. - git - https://github.com/Tribufu/TribufuNet Library @@ -17,12 +10,12 @@ netstandard2.0;net45;net5.0 true + + + - - - diff --git a/src/Tribufu.Serialization.Newtonsoft/Tribufu.Serialization.Newtonsoft.csproj b/src/Tribufu.Serialization.Newtonsoft/Tribufu.Serialization.Newtonsoft.csproj index 2aade60..0d33420 100644 --- a/src/Tribufu.Serialization.Newtonsoft/Tribufu.Serialization.Newtonsoft.csproj +++ b/src/Tribufu.Serialization.Newtonsoft/Tribufu.Serialization.Newtonsoft.csproj @@ -1,15 +1,8 @@  Tribufu.Serialization.Newtonsoft - 0.1.0 Tribufu Serialization Helpers for Newtonsoft.Json - Tribufu - Tribufu README.md - MIT - Copyright (c) Tribufu. All Rights Reserved. - git - https://github.com/Tribufu/TribufuNet Library @@ -17,10 +10,10 @@ netstandard2.0;net45;net5.0 true - - - + + + diff --git a/src/Tribufu.Serialization/Tribufu.Serialization.csproj b/src/Tribufu.Serialization/Tribufu.Serialization.csproj index b93b947..8efd520 100644 --- a/src/Tribufu.Serialization/Tribufu.Serialization.csproj +++ b/src/Tribufu.Serialization/Tribufu.Serialization.csproj @@ -1,15 +1,8 @@  Tribufu.Serialization - 0.1.0 Tribufu Serialization Helpers - Tribufu - Tribufu README.md - MIT - Copyright (c) Tribufu. All Rights Reserved. - git - https://github.com/Tribufu/TribufuNet Library diff --git a/src/Tribufu.Utils/Tribufu.Utils.csproj b/src/Tribufu.Utils/Tribufu.Utils.csproj index 21cab74..026c17d 100644 --- a/src/Tribufu.Utils/Tribufu.Utils.csproj +++ b/src/Tribufu.Utils/Tribufu.Utils.csproj @@ -1,15 +1,8 @@  Tribufu.Utils - 0.1.0 Tribufu Utils - Tribufu - Tribufu README.md - MIT - Copyright (c) Tribufu. All Rights Reserved. - git - https://github.com/Tribufu/TribufuNet Library @@ -17,9 +10,9 @@ net5.0 true - - + + diff --git a/src/Tribufu/Tribufu.csproj b/src/Tribufu/Tribufu.csproj index 78943fd..386d19f 100644 --- a/src/Tribufu/Tribufu.csproj +++ b/src/Tribufu/Tribufu.csproj @@ -1,15 +1,8 @@  Tribufu - 0.1.0 Tribufu .NET SDK - Tribufu - Tribufu README.md - MIT - Copyright (c) Tribufu. All Rights Reserved. - git - https://github.com/Tribufu/TribufuNet Library @@ -17,10 +10,15 @@ netstandard2.0;net45;net5.0 true - - - + + + + + + + +