Compare commits

...

6 commits

Author SHA1 Message Date
63aba3c9bb Delete NuGetPublish.targets 2025-01-30 00:04:47 -06:00
f9a1a5df62 Color work 2025-01-30 00:02:32 -06:00
977dc95b35 Update .gitignore 2025-01-29 23:58:51 -06:00
8682f50500 Added property transfer 2025-01-29 23:57:59 -06:00
9acafd8ce6 Update .gitignore 2025-01-29 22:32:29 -06:00
1de8ba8d6e Adding NuGet Publish target 2025-01-29 22:32:08 -06:00
5 changed files with 1977 additions and 1906 deletions

4
.gitignore vendored
View file

@ -396,3 +396,7 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
# NuGet Publish Target
NuGetPublish.targets
CapyKit/NuGetPublish.targets

View file

@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
</PropertyGroup>
<ItemGroup>
@ -16,4 +16,6 @@
</None>
</ItemGroup>
<Import Project="NuGetPublish.targets" Condition="Exists('NuGetPublish.targets')" />
</Project>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapyKit.Extensions
{
/// <summary> An class containing extenstions that apply to any object type. </summary>
public static class ObjectExtensions
{
/// <summary>
/// An object extension method that updates the properties of a given <paramref name="target"/>
/// object with the values from a given <paramref name="source"/> object.
/// </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="target"> The target object to act on. </param>
/// <param name="source"> Source for the new property values. </param>
public static void UpdateProperties<T>(this T target, T source)
{
var properties = typeof(T).GetProperties();
foreach (var prop in properties)
{
if (prop.CanWrite)
{
prop.SetValue(target, prop.GetValue(source));
}
}
}
/// <summary>
/// An object extension method that updates the properties of a given <paramref name="target"/>
/// object with the values from a given <paramref name="source"/> object.
/// </summary>
/// <param name="target"> The target object to act on. </param>
/// <param name="source"> Source for the new property values. </param>
public static void UpdateProperties(this object target, object source)
{
var targetProperties = target.GetType().GetProperties();
var sourceProperties = source.GetType().GetProperties();
var matchingProperties = targetProperties.Join(sourceProperties, outer => new { outer.Name, outer.PropertyType }, inner => new { inner.Name, inner.PropertyType }, (outer, inner) => new { Target = outer, Source = inner });
foreach (var propertyMatch in matchingProperties)
{
if(propertyMatch.Target.CanWrite)
{
propertyMatch.Target.SetValue(target, propertyMatch.Source.GetValue(source));
}
}
}
}
}

1916
CapyKit/NamedColor.cs Normal file

File diff suppressed because it is too large Load diff