Skip to content
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
3 changes: 0 additions & 3 deletions src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vim.Util.Logging.Serilog\Vim.Util.Logging.Serilog.csproj" />
<ProjectReference Include="..\Vim.Util\Vim.Util.csproj" />
</ItemGroup>
Expand Down
16 changes: 6 additions & 10 deletions src/cs/util/Vim.Util/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,28 @@ public static IEnumerable<Type> GetAllSubclassesOf(this Assembly asm, Type t)
public static IEnumerable<FieldInfo> GetAllFields(this Type self)
=> self.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

/// <summary>
/// Ignores the property or the field when they are being enumerated from a given object.
/// </summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class IgnoreInReflectedListAttribute : Attribute { }

/// <summary>
/// Converts fields to a dictionary of string/object pair.
/// </summary>
public static IDictionary<string, object> FieldsToDictionary(this object self)
=> self.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
.Where(fi => !fi.GetCustomAttributes<IgnoreInReflectedListAttribute>().Any())
.ToDictionary(fi => fi.Name, fi => fi.GetValue(self));

/// <summary>
/// Converts properties to a dictionary of string/object pair.
/// </summary>
public static IDictionary<string, object> PropertiesToDictionary(this object self)
=> self.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(pi => !pi.GetCustomAttributes<IgnoreInReflectedListAttribute>().Any())
.ToDictionary(pi => pi.Name, fi => fi.GetValue(self));

/// <summary>
/// Converts properties to an enumerable of strings.
/// </summary>
public static IEnumerable<string> PropertiesToStrings(this object self)
=> self.PropertiesToDictionary().Select(kv => $"{kv.Key}: {kv.Value}");
public static IEnumerable<string> PropertiesToStrings(this object self, Func<string, bool> keyFilter = null)
{
return self.PropertiesToDictionary()
.Where(kv => keyFilter?.Invoke(kv.Key) ?? true)
.Select(kv => $"{kv.Key}: {kv.Value}");
}
}
}
14 changes: 14 additions & 0 deletions src/cs/vim-format.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.4" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Vim.Format.ILMerge\Vim.Format.ILMerge.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<Reference Include="Vim.Format.Standalone">
<Private>true</Private>
<HintPath>..\Vim.Format.ILMerge\bin\$(Configuration)\Vim.Format.Standalone.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
8 changes: 8 additions & 0 deletions src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- see: https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task?tab=readme-ov-file#configuration-->
<PropertyGroup>
<ClearOutputDirectory>False</ClearOutputDirectory>
<ILRepackTargetsFile>$(ProjectDir)ILRepack.targets</ILRepackTargetsFile>
</PropertyGroup>
</Project>
44 changes: 44 additions & 0 deletions src/cs/vim/Vim.Format.ILMerge/ILRepack.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project ToolsVersion="12.0" DefaultTargets="PostBuildEvent" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<Target Name="ILMerge" AfterTargets="PostBuildEvent">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)Vim.Format.dll" />
<InputAssemblies Include="$(OutputPath)Vim.Format.Core.dll" />
<InputAssemblies Include="$(OutputPath)Vim.BFast.dll" />
<InputAssemblies Include="$(OutputPath)Vim.G3d.dll" />
<InputAssemblies Include="$(OutputPath)Vim.LinqArray.dll" />
<InputAssemblies Include="$(OutputPath)Vim.Math3D.dll" />
<InputAssemblies Include="$(OutputPath)Vim.Util.dll" />
<InputAssemblies Include="$(OutputPath)Vim.Util.Logging.Serilog.dll" />
<InputAssemblies Include="$(OutputPath)Serilog.dll" />
<InputAssemblies Include="$(OutputPath)Serilog.Sinks.Console.dll" />
<InputAssemblies Include="$(OutputPath)Serilog.Sinks.EventLog.dll" />
<InputAssemblies Include="$(OutputPath)Serilog.Sinks.File.dll" />
<InputAssemblies Include="$(OutputPath)Serilog.Sinks.RollingFile.dll" />
</ItemGroup>
<ILRepack
Parallel="true"
TargetKind="Dll"
InputAssemblies="@(InputAssemblies)"
OutputFile="$(OutputPath)/Vim.Format.Standalone.dll"
/>
<!--<Exec Command='$(ILRepack) ^
/parallel ^
/targetplatform:v4 ^
/out: ^
$(OutputPath)Vim.Format.dll ^
$(OutputPath)Vim.Format.Core.dll ^
$(OutputPath)Vim.BFast.dll ^
$(OutputPath)Vim.G3d.dll ^
$(OutputPath)Vim.LinqArray.dll ^
$(OutputPath)Vim.Math3D.dll ^
$(OutputPath)Vim.Util.dll ^
$(OutputPath)Vim.Util.Logging.Serilog.dll ^
$(OutputPath)Serilog.dll ^
$(OutputPath)Serilog.Sinks.Console.dll ^
$(OutputPath)Serilog.Sinks.EventLog.dll ^
$(OutputPath)Serilog.Sinks.File.dll ^
$(OutputPath)Serilog.Sinks.RollingFile.dll' />-->
</Target>

</Project>
31 changes: 31 additions & 0 deletions src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<AssemblyName>Vim.Format.ILMerge</AssemblyName>
<!--
https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#copylocallockfileassemblies
"If you set this property to true, any transitive NuGet package dependencies are copied to the output directory."
-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Vim.Format\Vim.Format.csproj" />
<ProjectReference Include="..\..\util\Vim.Util.Logging.Serilog\Vim.Util.Logging.Serilog.csproj" />
<PackageReference Include="ILRepack" Version="2.0.42">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.40" />
</ItemGroup>

<Target Name="ILMergeClean" AfterTargets="Clean">
<Message Text="### Cleaning ILMerge artifacts" Importance="high" />
<Delete Files="$(OutputPath)/Vim.Format.Standalone.dll" />
<Delete Files="$(OutputPath)/Vim.Format.Standalone.pdb" />
</Target>

</Project>
Loading