Skip to content

Commit

Permalink
Updated extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
grofit committed Sep 4, 2018
1 parent 73ba3bb commit e918f79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void Bind<TFrom, TTo>(BindingConfiguration configuration = null) where TT

foreach (var constructorArg in configuration.WithNamedConstructorArgs)
{ binding.WithConstructorArgument(constructorArg.Key, constructorArg.Value); }

foreach (var constructorArg in configuration.WithTypedConstructorArgs)
{ binding.WithConstructorArgument(constructorArg.Key, constructorArg.Value); }
}

public void Bind<T>(BindingConfiguration configuration = null)
Expand Down
15 changes: 14 additions & 1 deletion src/EcsRx/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static IEnumerable<ISystem> GetApplicableSystems(this IEnumerable<ISystem
return systems.Where(x => x.Group.RequiredComponents.All(y => componentTypes.Contains(y)));
}

public static IEnumerable<T> OrderByPriority<T>(this IEnumerable<T> listToPrioritize)
public static IOrderedEnumerable<T> OrderByPriority<T>(this IEnumerable<T> listToPrioritize)
{
var priorityAttributeType = typeof(PriorityAttribute);
return listToPrioritize.OrderBy(x =>
Expand All @@ -46,5 +46,18 @@ public static IEnumerable<T> OrderByPriority<T>(this IEnumerable<T> listToPriori
return -priorityAttribute.Priority;
});
}

public static IOrderedEnumerable<T> ThenByPriority<T>(this IOrderedEnumerable<T> listToPrioritize)
{
var priorityAttributeType = typeof(PriorityAttribute);
return listToPrioritize.ThenBy(x =>
{
var priorityAttributes = x.GetType().GetCustomAttributes(priorityAttributeType, true);
if (priorityAttributes.Length <= 0) { return 0; }

var priorityAttribute = priorityAttributes.FirstOrDefault() as PriorityAttribute;
return -priorityAttribute.Priority;
});
}
}
}

0 comments on commit e918f79

Please sign in to comment.