Compare commits
6 commits
a0492aaa0b
...
63aba3c9bb
Author | SHA1 | Date | |
---|---|---|---|
63aba3c9bb | |||
f9a1a5df62 | |||
977dc95b35 | |||
8682f50500 | |||
9acafd8ce6 | |||
1de8ba8d6e |
5 changed files with 1977 additions and 1906 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -396,3 +396,7 @@ FodyWeavers.xsd
|
||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
|
# NuGet Publish Target
|
||||||
|
NuGetPublish.targets
|
||||||
|
CapyKit/NuGetPublish.targets
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
<Version>1.0.2</Version>
|
<Version>1.0.3</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -16,4 +16,6 @@
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="NuGetPublish.targets" Condition="Exists('NuGetPublish.targets')" />
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
1907
CapyKit/Color.cs
1907
CapyKit/Color.cs
File diff suppressed because it is too large
Load diff
52
CapyKit/Extensions/ObjectExtensions.cs
Normal file
52
CapyKit/Extensions/ObjectExtensions.cs
Normal 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
1916
CapyKit/NamedColor.cs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue