-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
282 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reflection; | ||
using Dexiom.EPPlusExporter.Helpers; | ||
|
||
namespace Dexiom.EPPlusExporter | ||
{ | ||
public class DisplayField<T> where T : class | ||
{ | ||
private readonly PropertyInfo _propertyInfo; | ||
private readonly DynamicProperty<T> _dynamicProperty; | ||
|
||
public DisplayField(PropertyInfo propertyInfo) | ||
{ | ||
_propertyInfo = propertyInfo; | ||
|
||
Name = _propertyInfo.Name; | ||
DisplayName = ReflectionHelper.GetPropertyDisplayName(_propertyInfo); | ||
Type = _propertyInfo.PropertyType; | ||
} | ||
|
||
public DisplayField(DynamicProperty<T> dynamicProperty) | ||
{ | ||
_dynamicProperty = dynamicProperty; | ||
|
||
Name = _dynamicProperty.Name; | ||
DisplayName = _dynamicProperty.DisplayName; | ||
Type = _dynamicProperty.ValueType; | ||
} | ||
|
||
#region Properties | ||
public string Name { get; set; } | ||
public string DisplayName { get; set; } | ||
public Type Type { get; set; } | ||
#endregion | ||
|
||
public object GetValue(T item) | ||
{ | ||
if (_propertyInfo != null) | ||
{ | ||
#if NET4 | ||
return _propertyInfo.GetValue(item, null); | ||
#endif | ||
#if NET45 || NET46 | ||
return _propertyInfo.GetValue(item); | ||
#endif | ||
} | ||
|
||
return _dynamicProperty.GetValue(item); | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
|
||
namespace Dexiom.EPPlusExporter | ||
{ | ||
public static class DynamicProperty | ||
{ | ||
public static DynamicProp<T> Create<T>(Func<T, object> getValue, Type valueType) where T : class => new DynamicProp<T>(getValue, valueType); | ||
} | ||
|
||
public class DynamicProp<T> | ||
{ | ||
public DynamicProp(Func<T, object> getValue, Type valueType) | ||
{ | ||
ValueType = valueType; | ||
GetValue = getValue; | ||
} | ||
|
||
|
||
public Type ValueType { get; set; } | ||
public Func<T, object> GetValue { get; set; } | ||
} | ||
} |
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,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Dexiom.EPPlusExporter | ||
{ | ||
#region Create Method (using type inference) | ||
public static class DynamicProperty | ||
{ | ||
public static DynamicProperty<T> Create<T>(IEnumerable<T> data, string name, string displayName, Type valueType, Func<T, object> getValue) where T : class | ||
{ | ||
return new DynamicProperty<T>() | ||
{ | ||
Name = name, | ||
DisplayName = displayName, | ||
ValueType = valueType, | ||
GetValue = getValue | ||
}; | ||
} | ||
} | ||
#endregion | ||
|
||
public class DynamicProperty<T> | ||
where T : class | ||
{ | ||
public string Name { get; set; } | ||
public string DisplayName { get; set; } | ||
public Type ValueType { get; set; } | ||
public Func<T, object> GetValue { get; set; } | ||
} | ||
} |
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.