Skip to content

Commit

Permalink
added xml docs
Browse files Browse the repository at this point in the history
  • Loading branch information
omuleanu committed May 27, 2024
1 parent c39e8a7 commit 35f9366
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ValueInjecter/Injections/FlatLoopInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace Omu.ValueInjecter.Injections
/// </summary>
public class FlatLoopInjection : ValueInjection
{
/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void Inject(object source, object target)
{
var targetProps = target.GetType().GetProps();
Expand All @@ -22,16 +25,26 @@ protected override void Inject(object source, object target)
}
}

/// <summary>
/// match properties
/// </summary>
protected virtual bool Match(string propName, PropertyInfo unflatProp, PropertyInfo targetFlatProp)
{
return unflatProp.PropertyType == targetFlatProp.PropertyType && propName == unflatProp.Name && unflatProp.GetGetMethod() != null;
}


/// <summary>
/// set value in the target property
/// </summary>
protected virtual void SetValue(object source, object target, PropertyInfo sp, PropertyInfo tp)
{
tp.SetValue(target, sp.GetValue(source, null), null);
}

/// <summary>
/// execute injection on all properties
/// </summary>
protected void Execute(PropertyInfo tp, object source, object target)
{
if (tp.CanWrite && tp.GetSetMethod() != null)
Expand Down
8 changes: 8 additions & 0 deletions ValueInjecter/Injections/INoSourceInjection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
namespace Omu.ValueInjecter.Injections
{
/// <summary>
/// injection without source
/// </summary>
public interface INoSourceInjection
{
/// <summary>
/// inject value into target object
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
object Map(object target);
}
}
15 changes: 15 additions & 0 deletions ValueInjecter/Injections/KnownTargetInjection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
namespace Omu.ValueInjecter.Injections
{
/// <summary>
/// known target type injection
/// </summary>
/// <typeparam name="TTarget"></typeparam>
public abstract class KnownTargetInjection<TTarget> : IValueInjection
{
/// <summary>
/// set values into target object based on source object
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
/// <returns></returns>
public object Map(object source, object target)
{
var theTarget = (TTarget) target;
Expand All @@ -10,6 +20,11 @@ public object Map(object source, object target)
return target;
}

/// <summary>
/// set values into target object based on source object
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
protected abstract void Inject(object source, ref TTarget target);
}
}
24 changes: 24 additions & 0 deletions ValueInjecter/Injections/LoopInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,55 @@ namespace Omu.ValueInjecter.Injections
/// </summary>
public class LoopInjection : PropertyInjection
{
/// <summary>
///
/// </summary>
public LoopInjection()
{
}

/// <summary>
/// ctor with ignored props setter
/// </summary>
/// <param name="ignoredProps"></param>
public LoopInjection(string[] ignoredProps)
: base(ignoredProps)
{
}

/// <summary>
/// get target property name based on source property name
/// </summary>
/// <param name="sourceName"></param>
/// <returns></returns>
protected virtual string GetTargetProp(string sourceName)
{
return sourceName;
}

/// <summary>
/// determine if types are matching
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
/// <returns></returns>
protected virtual bool MatchTypes(Type source, Type target)
{
return source == target;
}

/// <summary>
/// set target property value
/// </summary>
protected virtual void SetValue(object source, object target, PropertyInfo sp, PropertyInfo tp)
{
var val = sp.GetValue(source, null);
tp.SetValue(target, val, null);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void Execute(PropertyInfo sp, object source, object target)
{
if (sp.CanRead && sp.GetGetMethod() != null && (ignoredProps == null || !ignoredProps.Contains(sp.Name)))
Expand Down
9 changes: 9 additions & 0 deletions ValueInjecter/Injections/NoSourceInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
///</summary>
public abstract class NoSourceInjection : INoSourceInjection
{
/// <summary>
/// map target
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public object Map(object target)
{
Inject(target);
return target;
}

/// <summary>
/// inject value into target object
/// </summary>
/// <param name="target"></param>
protected abstract void Inject(object target);
}
}
19 changes: 19 additions & 0 deletions ValueInjecter/Injections/PropertyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,35 @@

namespace Omu.ValueInjecter.Injections
{
/// <summary>
/// Property injection
/// </summary>
public class PropertyInjection : ValueInjection
{
/// <summary>
/// properties to ignore
/// </summary>
protected string[] ignoredProps;

/// <summary>
///
/// </summary>
public PropertyInjection()
{
}

/// <summary>
/// ctor with properties to ignore setter
/// </summary>
/// <param name="ignoredProps"></param>
public PropertyInjection(string[] ignoredProps)
{
this.ignoredProps = ignoredProps;
}

/// <summary>
/// <inheritdoc/>
/// </summary>
protected override void Inject(object source, object target)
{
var sourceProps = source.GetType().GetProps();
Expand All @@ -27,6 +43,9 @@ protected override void Inject(object source, object target)
}
}

/// <summary>
/// <inheritdoc/>
/// </summary>
protected virtual void Execute(PropertyInfo sp, object source, object target)
{
if (sp.CanRead && sp.GetGetMethod() != null && (ignoredProps == null || !ignoredProps.Contains(sp.Name)))
Expand Down
31 changes: 31 additions & 0 deletions ValueInjecter/Injections/UnflatLoopInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ namespace Omu.ValueInjecter.Injections
/// </summary>
public class UnflatLoopInjection : ValueInjection
{
/// <summary>
///
/// </summary>
protected Func<PropertyInfo, object, object> activator;

/// <summary>
///
/// </summary>
public UnflatLoopInjection()
{
}
Expand All @@ -29,6 +35,11 @@ public UnflatLoopInjection(Func<PropertyInfo, object, object> activator)
this.activator = activator;
}

/// <summary>
/// inject values from source to target
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
protected override void Inject(object source, object target)
{
var sourceProps = source.GetType().GetProps();
Expand All @@ -38,16 +49,36 @@ protected override void Inject(object source, object target)
}
}

/// <summary>
/// check if properties match
/// </summary>
/// <param name="propName"></param>
/// <param name="unflatProp"></param>
/// <param name="sourceFlatProp"></param>
/// <returns></returns>
protected virtual bool Match(string propName, PropertyInfo unflatProp, PropertyInfo sourceFlatProp)
{
return unflatProp.PropertyType == sourceFlatProp.PropertyType && propName == unflatProp.Name && unflatProp.GetSetMethod() != null;
}

/// <summary>
/// set property value from source to target
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
/// <param name="sp"></param>
/// <param name="tp"></param>
protected virtual void SetValue(object source, object target, PropertyInfo sp, PropertyInfo tp)
{
tp.SetValue(target, sp.GetValue(source, null), null);
}

/// <summary>
/// execute property injection from source to target object
/// </summary>
/// <param name="sp"></param>
/// <param name="source"></param>
/// <param name="target"></param>
protected virtual void Execute(PropertyInfo sp, object source, object target)
{
if (sp.CanRead && sp.GetGetMethod() != null)
Expand Down
3 changes: 3 additions & 0 deletions ValueInjecter/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Omu.ValueInjecter
{
/// <summary>
/// mapper instance class
/// </summary>
public class Mapper
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions ValueInjecter/MapperInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Omu.ValueInjecter
{
/// <summary>
/// mapper instance class
/// </summary>
public class MapperInstance
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions ValueInjecter/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Omu.ValueInjecter.Utils
{
/// <summary>
/// ValueInjecter extensions
/// </summary>
public static class Extensions
{
/// <summary>
Expand Down
22 changes: 22 additions & 0 deletions ValueInjecter/Utils/StrUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,41 @@

namespace Omu.ValueInjecter.Utils
{
/// <summary>
/// String utilities
/// </summary>
public static class StrUtil
{
/// <summary>
/// remove string prefix
/// </summary>
/// <param name="o"></param>
/// <param name="prefix"></param>
/// <param name="comparison"></param>
/// <returns></returns>
public static string RemovePrefix(string o, string prefix, StringComparison comparison)
{
if (prefix == null) return o;
return !o.StartsWith(prefix, comparison) ? o : o.Remove(0, prefix.Length);
}

/// <summary>
/// remove string prefix
/// </summary>
/// <param name="o"></param>
/// <param name="prefix"></param>
/// <returns></returns>
public static string RemovePrefix(string o, string prefix)
{
return RemovePrefix(o, prefix, StringComparison.Ordinal);
}

/// <summary>
/// remove string suffix
/// </summary>
/// <param name="o"></param>
/// <param name="suffix"></param>
/// <returns></returns>
public static string RemoveSuffix(string o, string suffix)
{
if (suffix == null) return o;
Expand Down

0 comments on commit 35f9366

Please sign in to comment.