-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for copyable attribute * Correct observations * Minor Change * move ObjectCopier to Mapper * Improvements in unit testing. * Refactoring ObjectMapper * Allow to use Dictionary<string, object> as source for mapping. * Add Functional methods and reduce double check ObjectMapper * Fixing suggestion from CR. * Reduce PropertyTypeCache instances * Fix build * Add TryParseBasicType method * Ignore RunInConsoleModeTest test for now * Before to publish
- Loading branch information
Showing
31 changed files
with
1,068 additions
and
955 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace Unosquare.Swan.Components | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
/// <summary> | ||
/// Provide Enumerations helpers with internal cache | ||
/// </summary> | ||
public static class EnumHelper | ||
{ | ||
private static readonly Dictionary<Type, Tuple<int, string>[]> Cache = | ||
new Dictionary<Type, Tuple<int, string>[]>(); | ||
|
||
private static readonly object LockObject = new object(); | ||
|
||
/// <summary> | ||
/// Gets the items with the enum item value. | ||
/// </summary> | ||
/// <typeparam name="T">The type of enumeration</typeparam> | ||
/// <param name="humanize">if set to <c>true</c> [humanize].</param> | ||
/// <returns> | ||
/// A collection of Type/Tuple pairs | ||
/// that represents items with the enum item value | ||
/// </returns> | ||
public static Tuple<int, string>[] GetItemsWithValue<T>(bool humanize = true) | ||
{ | ||
lock (LockObject) | ||
{ | ||
if (Cache.ContainsKey(typeof(T)) == false) | ||
{ | ||
Cache.Add(typeof(T), Enum.GetNames(typeof(T)) | ||
.Select(x => new Tuple<int, string>((int)Enum.Parse(typeof(T), x), humanize ? x.Humanize() : x)) | ||
.ToArray()); | ||
} | ||
|
||
return Cache[typeof(T)]; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the items with the enum item index. | ||
/// </summary> | ||
/// <typeparam name="T">The type of enumeration</typeparam> | ||
/// <param name="humanize">if set to <c>true</c> [humanize].</param> | ||
/// <returns> | ||
/// A collection of Type/Tuple pairs that represents items with the enum item value | ||
/// </returns> | ||
public static Tuple<int, string>[] GetItemsWithIndex<T>(bool humanize = true) | ||
{ | ||
lock (LockObject) | ||
{ | ||
if (Cache.ContainsKey(typeof(T)) == false) | ||
{ | ||
var i = 0; | ||
|
||
Cache.Add(typeof(T), Enum.GetNames(typeof(T)) | ||
.Select(x => new Tuple<int, string>(i++, humanize ? x.Humanize() : x)) | ||
.ToArray()); | ||
} | ||
|
||
return Cache[typeof(T)]; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Unosquare.Swan.Components | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
/// <summary> | ||
/// Interface object map | ||
/// </summary> | ||
public interface IObjectMap | ||
{ | ||
/// <summary> | ||
/// Gets or sets the map. | ||
/// </summary> | ||
Dictionary<PropertyInfo, List<PropertyInfo>> Map { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the type of the source. | ||
/// </summary> | ||
Type SourceType { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets the type of the destination. | ||
/// </summary> | ||
Type DestinationType { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.