Compare commits

..

No commits in common. "63aba3c9bbaf5e2c7701ed5a49b31416fc9abde8" and "a0492aaa0b3ec03e15d2ee83f6b6453866156620" have entirely different histories.

5 changed files with 1906 additions and 1977 deletions

4
.gitignore vendored
View file

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

View file

@ -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.3</Version> <Version>1.0.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -16,6 +16,4 @@
</None> </None>
</ItemGroup> </ItemGroup>
<Import Project="NuGetPublish.targets" Condition="Exists('NuGetPublish.targets')" />
</Project> </Project>

File diff suppressed because it is too large Load diff

View file

@ -1,52 +0,0 @@
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));
}
}
}
}
}

File diff suppressed because it is too large Load diff