diff --git a/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj b/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj index 0e938e53..649eead3 100644 --- a/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj +++ b/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj @@ -12,9 +12,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/src/cs/util/Vim.Util/Reflection.cs b/src/cs/util/Vim.Util/Reflection.cs index 77caaf8f..72cb63da 100644 --- a/src/cs/util/Vim.Util/Reflection.cs +++ b/src/cs/util/Vim.Util/Reflection.cs @@ -18,18 +18,11 @@ public static IEnumerable GetAllSubclassesOf(this Assembly asm, Type t) public static IEnumerable GetAllFields(this Type self) => self.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - /// - /// Ignores the property or the field when they are being enumerated from a given object. - /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - public class IgnoreInReflectedListAttribute : Attribute { } - /// /// Converts fields to a dictionary of string/object pair. /// public static IDictionary FieldsToDictionary(this object self) => self.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance) - .Where(fi => !fi.GetCustomAttributes().Any()) .ToDictionary(fi => fi.Name, fi => fi.GetValue(self)); /// @@ -37,13 +30,16 @@ public static IDictionary FieldsToDictionary(this object self) /// public static IDictionary PropertiesToDictionary(this object self) => self.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(pi => !pi.GetCustomAttributes().Any()) .ToDictionary(pi => pi.Name, fi => fi.GetValue(self)); /// /// Converts properties to an enumerable of strings. /// - public static IEnumerable PropertiesToStrings(this object self) - => self.PropertiesToDictionary().Select(kv => $"{kv.Key}: {kv.Value}"); + public static IEnumerable PropertiesToStrings(this object self, Func keyFilter = null) + { + return self.PropertiesToDictionary() + .Where(kv => keyFilter?.Invoke(kv.Key) ?? true) + .Select(kv => $"{kv.Key}: {kv.Value}"); + } } } diff --git a/src/cs/vim-format.sln b/src/cs/vim-format.sln index 6a7a027f..fb20d3c7 100644 --- a/src/cs/vim-format.sln +++ b/src/cs/vim-format.sln @@ -59,6 +59,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Gltf.Converter", "sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Gltf.Converter.Tests", "samples\Vim.Gltf.Converter.Tests\Vim.Gltf.Converter.Tests.csproj", "{902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vim.Format.ILMerge", "vim\Vim.Format.ILMerge\Vim.Format.ILMerge.csproj", "{3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vim.Format.ILMerge.Tests", "vim\Vim.Format.ILMerge.Tests\Vim.Format.ILMerge.Tests.csproj", "{26C02A1E-168B-2945-8AD2-7E7C30114F91}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -149,6 +153,14 @@ Global {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}.Debug|Any CPU.Build.0 = Debug|Any CPU {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}.Release|Any CPU.ActiveCfg = Release|Any CPU {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}.Release|Any CPU.Build.0 = Release|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Release|Any CPU.Build.0 = Release|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -175,6 +187,8 @@ Global {A0FA4646-67AC-4310-9BA5-53D2D7CF218F} = {E2EBD5E0-81EC-4720-833C-05ECE1BA84A1} {8C81050A-951C-418F-BBA8-76EE0353863C} = {E2EBD5E0-81EC-4720-833C-05ECE1BA84A1} {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3} = {E2EBD5E0-81EC-4720-833C-05ECE1BA84A1} + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} + {26C02A1E-168B-2945-8AD2-7E7C30114F91} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7D1BF641-26E8-4809-B638-029241C51BE2} diff --git a/src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj b/src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj new file mode 100644 index 00000000..ed44c980 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + false + + + true + ..\Vim.Format.ILMerge\bin\$(Configuration)\Vim.Format.Standalone.dll + + + + diff --git a/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs b/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs new file mode 100644 index 00000000..d4693ad0 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs @@ -0,0 +1,41 @@ +using NUnit.Framework; +using System.IO; +using Vim.Util; +using Vim.Util.Logging; +using Serilog; + +namespace Vim.Format.ILMerge.Tests; + +[TestFixture] +public static class VimFormatILMergeTests +{ + [Test] + public static void TestVimFormatStandalone() + { + // This test makes use of the merged version of serilog. + // We had to create a merged standalone version of Vim.Format to minimize collisions with other assemblies in Revit. + var fileName = "standalone.log"; + var msg = "This is a log message which uses the ILMerged version of serilog"; + + { + // setup + IO.Delete(fileName); + Assert.IsTrue(!File.Exists(fileName)); + } + + { + // action + var logger = Util.Logging.Serilog.Log.Init("toot", fileName, true); + logger.LogInformation(msg); + Log.CloseAndFlush(); + } + + { + // verify + var fileInfo = new FileInfo(fileName); + Assert.IsTrue(fileInfo.Exists, $"File not found: {fileInfo.FullName}"); + var logged = File.ReadAllText(fileInfo.FullName); + Assert.IsTrue(logged.Contains(msg)); + } + } +} diff --git a/src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props b/src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props new file mode 100644 index 00000000..780712a3 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props @@ -0,0 +1,8 @@ + + + + + False + $(ProjectDir)ILRepack.targets + + \ No newline at end of file diff --git a/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets b/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets new file mode 100644 index 00000000..f0482766 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj new file mode 100644 index 00000000..c3413f18 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj @@ -0,0 +1,31 @@ + + + + netstandard2.0 + false + Always + Vim.Format.ILMerge + + true + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + +