Skip to content

Commit

Permalink
Chnaged generic types names
Browse files Browse the repository at this point in the history
  • Loading branch information
Pogromca-SCP committed Feb 19, 2024
1 parent 614d839 commit b2ad80d
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 53 deletions.
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Description
What goal does this PR attempts to achieve?

## Resolution
What changes were made to achieve this goal?

## Testing Evidence
How do you know that it works?

## Related PRs/Dependencies
Is this PR relying on anything else?

## Before merging
- [ ] If non-cosmetic changes were introduced -> Update project version and changelog.
16 changes: 8 additions & 8 deletions SLCommandScript.Core/Interfaces/IExprVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@ namespace SLCommandScript.Core.Interfaces;
/// <summary>
/// Interface to implement in order to create an expressions visitor.
/// </summary>
/// <typeparam name="T">Type used for visit results.</typeparam>
public interface IExprVisitor<T>
/// <typeparam name="TResult">Type used for visit results.</typeparam>
public interface IExprVisitor<out TResult>
{
/// <summary>
/// Visits a command expression.
/// </summary>
/// <param name="expr">Expression to visit.</param>
/// <returns>Result value of the visit.</returns>
T VisitCommandExpr(CommandExpr expr);
TResult VisitCommandExpr(CommandExpr expr);

/// <summary>
/// Visits a delay expression.
/// </summary>
/// <param name="expr">Expression to visit.</param>
/// <returns>Result value of the visit.</returns>
T VisitDelayExpr(DelayExpr expr);
TResult VisitDelayExpr(DelayExpr expr);

/// <summary>
/// Visits a foreach expression.
/// </summary>
/// <param name="expr">Expression to visit.</param>
/// <returns>Result value of the visit.</returns>
T VisitForeachExpr(ForeachExpr expr);
TResult VisitForeachExpr(ForeachExpr expr);

/// <summary>
/// Visits a for else expression.
/// </summary>
/// <param name="expr">Expression to visit.</param>
/// <returns>Result value of the visit.</returns>
T VisitForElseExpr(ForElseExpr expr);
TResult VisitForElseExpr(ForElseExpr expr);

/// <summary>
/// Visits an if expression.
/// </summary>
/// <param name="expr">Expression to visit.</param>
/// <returns>Result value of the visit.</returns>
T VisitIfExpr(IfExpr expr);
TResult VisitIfExpr(IfExpr expr);

/// <summary>
/// Visits a sequence expression.
/// </summary>
/// <param name="expr">Expression to visit.</param>
/// <returns>Result value of the visit.</returns>
T VisitSequenceExpr(SequenceExpr expr);
TResult VisitSequenceExpr(SequenceExpr expr);
}
12 changes: 6 additions & 6 deletions SLCommandScript.Core/Iterables/EnumIterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ namespace SLCommandScript.Core.Iterables;
/// <summary>
/// Iterable wrapper for enum values.
/// </summary>
/// <typeparam name="T">Type of contained enum values.</typeparam>
/// <typeparam name="TEnum">Type of contained enum values.</typeparam>
/// <param name="enableNone">Whether or not the None values should be included in iteration.</param>
public class EnumIterable<T>(bool enableNone) : IIterable where T : Enum
public class EnumIterable<TEnum>(bool enableNone) : IIterable where TEnum : Enum
{
/// <summary>
/// Retrieves iterable object for specific enum type.
/// </summary>
/// <returns>Iterable object for specific enum.</returns>
public static EnumIterable<T> Get() => new(false);
public static EnumIterable<TEnum> Get() => new(false);

/// <summary>
/// Retrieves iterable object for specific enum type with None values included.
/// </summary>
/// <returns>Iterable object for specific enum.</returns>
public static EnumIterable<T> GetWithNone() => new(true);
public static EnumIterable<TEnum> GetWithNone() => new(true);

/// <summary>
/// <see langword="true" /> if last object was reached, <see langword="false" /> otherwise.
Expand All @@ -33,7 +33,7 @@ public bool IsAtEnd
{
if (_values is null)
{
_values = (T[]) typeof(T).GetEnumValues();
_values = (TEnum[]) typeof(TEnum).GetEnumValues();

if (!_enableNone)
{
Expand All @@ -59,7 +59,7 @@ public bool IsAtEnd
/// <summary>
/// Contains wrapped array of enum values.
/// </summary>
private T[] _values = null;
private TEnum[] _values = null;

/// <summary>
/// Contains index of current object. Used for randomization limit before values initialization.
Expand Down
14 changes: 7 additions & 7 deletions SLCommandScript.Core/Iterables/IterableListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace SLCommandScript.Core.Iterables;
/// <summary>
/// Iterable wrapper for a list of objects.
/// </summary>
/// <typeparam name="T">Type of contained objects.</typeparam>
/// <typeparam name="TItem">Type of contained objects.</typeparam>
/// <param name="source">Source of objects to insert into wrapped list.</param>
public abstract class IterableListBase<T>(Func<IEnumerable<T>> source) : IIterable
public abstract class IterableListBase<TItem>(Func<IEnumerable<TItem>> source) : IIterable
{
/// <summary>
/// <see langword="true" /> if last object was reached, <see langword="false" /> otherwise.
Expand All @@ -26,7 +26,7 @@ public bool IsAtEnd

if (_objects is null)
{
_objects = _source()?.Where(o => o is not null) ?? Array.Empty<T>();
_objects = _source()?.Where(o => o is not null) ?? Array.Empty<TItem>();

if (_count != 0)
{
Expand All @@ -44,17 +44,17 @@ public bool IsAtEnd
/// <summary>
/// Source of iterated objects.
/// </summary>
private readonly Func<IEnumerable<T>> _source = source;
private readonly Func<IEnumerable<TItem>> _source = source;

/// <summary>
/// Contains wrapped list of objects.
/// </summary>
private IEnumerable<T> _objects = null;
private IEnumerable<TItem> _objects = null;

/// <summary>
/// Contains currently used iterator.
/// </summary>
private IEnumerator<T> _enumerator = null;
private IEnumerator<TItem> _enumerator = null;

/// <summary>
/// Amount of contained elements. Used for randomization limit before objects initialization.
Expand Down Expand Up @@ -120,5 +120,5 @@ public void Reset()
/// </summary>
/// <param name="targetVars">Dictionary to insert properties into.</param>
/// <param name="obj">Object to load properties from.</param>
protected abstract void LoadVariables(IDictionary<string, string> targetVars, T obj);
protected abstract void LoadVariables(IDictionary<string, string> targetVars, TItem obj);
}
22 changes: 11 additions & 11 deletions SLCommandScript.Core/Iterables/IterablesUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,36 +60,36 @@ public static class IterablesUtils
/// <summary>
/// Shuffles elements in provided enumerable collection.
/// </summary>
/// <typeparam name="T">Type of elements contained in collection.</typeparam>
/// <typeparam name="TResult">Type of elements contained in collection.</typeparam>
/// <param name="data">Collection to shuffle.</param>
/// <returns>Shuffled array if at least 2 elements were found.</returns>
public static T[] Shuffle<T>(IEnumerable<T> data) => Shuffle(data?.ToArray());
public static TResult[] Shuffle<TResult>(IEnumerable<TResult> data) => Shuffle(data?.ToArray());

/// <summary>
/// Shuffles and retrieves specific amount of elements from provided collection.
/// </summary>
/// <typeparam name="T">Type of elements contained in collection.</typeparam>
/// <typeparam name="TResult">Type of elements contained in collection.</typeparam>
/// <param name="data">Collection to shuffle.</param>
/// <param name="amount">Amount of elements to retrieve. Takes effect only when smaller than elements count.</param>
/// <returns>Shuffled array if at least 2 elements were found.</returns>
public static T[] Shuffle<T>(IEnumerable<T> data, int amount) => Shuffle(data?.ToArray(), amount);
public static TResult[] Shuffle<TResult>(IEnumerable<TResult> data, int amount) => Shuffle(data?.ToArray(), amount);

/// <summary>
/// Shuffles elements in provided array.
/// </summary>
/// <typeparam name="T">Type of elements contained in array.</typeparam>
/// <typeparam name="TResult">Type of elements contained in array.</typeparam>
/// <param name="array">Array to shuffle. This array is modified.</param>
/// <returns>Shuffled original array if at least 2 elements were found.</returns>
public static T[] Shuffle<T>(T[] array) => array is null || array.Length < 2 ? array : ShuffleArray(array);
public static TResult[] Shuffle<TResult>(TResult[] array) => array is null || array.Length < 2 ? array : ShuffleArray(array);

/// <summary>
/// Shuffles and retrieves specific amount of elements from provided array.
/// </summary>
/// <typeparam name="T">Type of elements contained in array.</typeparam>
/// <typeparam name="TResult">Type of elements contained in array.</typeparam>
/// <param name="array">Array to shuffle. This array is modified.</param>
/// <param name="amount">Amount of elements to retrieve. Takes effect only when smaller than array length.</param>
/// <returns>New shuffled array or original array if less than 2 elements were found.</returns>
public static T[] Shuffle<T>(T[] array, int amount)
public static TResult[] Shuffle<TResult>(TResult[] array, int amount)
{
if (array is null || array.Length < 2)
{
Expand All @@ -101,7 +101,7 @@ public static T[] Shuffle<T>(T[] array, int amount)
return ShuffleArray(array);
}

var result = new T[amount];
var result = new TResult[amount];
amount = 0;

for (var i = array.Length - 1; amount < result.Length; --i)
Expand All @@ -118,10 +118,10 @@ public static T[] Shuffle<T>(T[] array, int amount)
/// <summary>
/// Shuffles elements in provided array.
/// </summary>
/// <typeparam name="T">Type of elements contained in array.</typeparam>
/// <typeparam name="TResult">Type of elements contained in array.</typeparam>
/// <param name="array">Array to shuffle. This array is modified.</param>
/// <returns>Shuffled original array.</returns>
private static T[] ShuffleArray<T>(T[] array)
private static TResult[] ShuffleArray<TResult>(TResult[] array)
{
for (var i = array.Length - 1; i > 0; --i)
{
Expand Down
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/CommandExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class CommandExpr(ICommand cmd, string[] args, bool hasVariables) : Expr
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <exception cref="NullReferenceException">When provided visitor is <see langword="null" />.</exception>
/// <returns>Result of accepted visit.</returns>
public override T Accept<T>(IExprVisitor<T> visitor) => visitor.VisitCommandExpr(this);
public override TResult Accept<TResult>(IExprVisitor<TResult> visitor) => visitor.VisitCommandExpr(this);
}
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/DelayExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class DelayExpr(Expr body, int duration, string name) : Expr
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <exception cref="NullReferenceException">When provided visitor is <see langword="null" />.</exception>
/// <returns>Result of accepted visit.</returns>
public override T Accept<T>(IExprVisitor<T> visitor) => visitor.VisitDelayExpr(this);
public override TResult Accept<TResult>(IExprVisitor<TResult> visitor) => visitor.VisitDelayExpr(this);
}
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/Expr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public abstract class Expr
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <returns>Result of accepted visit.</returns>
public abstract T Accept<T>(IExprVisitor<T> visitor);
public abstract TResult Accept<TResult>(IExprVisitor<TResult> visitor);
}
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/ForElseExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public class ForElseExpr(Expr then, IIterable iterable, Expr els, int limit) : E
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <exception cref="NullReferenceException">When provided visitor is <see langword="null" />.</exception>
/// <returns>Result of accepted visit.</returns>
public override T Accept<T>(IExprVisitor<T> visitor) => visitor.VisitForElseExpr(this);
public override TResult Accept<TResult>(IExprVisitor<TResult> visitor) => visitor.VisitForElseExpr(this);
}
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/ForeachExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class ForeachExpr(Expr body, IIterable iterable) : Expr
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <exception cref="NullReferenceException">When provided visitor is <see langword="null" />.</exception>
/// <returns>Result of accepted visit.</returns>
public override T Accept<T>(IExprVisitor<T> visitor) => visitor.VisitForeachExpr(this);
public override TResult Accept<TResult>(IExprVisitor<TResult> visitor) => visitor.VisitForeachExpr(this);
}
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/IfExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class IfExpr(Expr then, Expr condition, Expr els) : Expr
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <exception cref="NullReferenceException">When provided visitor is <see langword="null" />.</exception>
/// <returns>Result of accepted visit.</returns>
public override T Accept<T>(IExprVisitor<T> visitor) => visitor.VisitIfExpr(this);
public override TResult Accept<TResult>(IExprVisitor<TResult> visitor) => visitor.VisitIfExpr(this);
}
4 changes: 2 additions & 2 deletions SLCommandScript.Core/Language/Expressions/SequenceExpr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class SequenceExpr(IEnumerable<Expr> body) : Expr
/// <summary>
/// Accepts a visit from an expression visitor.
/// </summary>
/// <typeparam name="T">Type used for visit result.</typeparam>
/// <typeparam name="TResult">Type used for visit result.</typeparam>
/// <param name="visitor">Visitor to accept.</param>
/// <exception cref="NullReferenceException">When provided visitor is <see langword="null" />.</exception>
/// <returns>Result of accepted visit.</returns>
public override T Accept<T>(IExprVisitor<T> visitor) => visitor.VisitSequenceExpr(this);
public override TResult Accept<TResult>(IExprVisitor<TResult> visitor) => visitor.VisitSequenceExpr(this);
}
14 changes: 7 additions & 7 deletions SLCommandScript.Core/Reflection/CustomTypesUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public static class CustomTypesUtils
/// <summary>
/// Loads custom type and creates its new instance.
/// </summary>
/// <typeparam name="T">Type to cast new instance into.</typeparam>
/// <typeparam name="TResult">Type to cast new instance into.</typeparam>
/// <param name="typeName">Name of custom type to find.</param>
/// <param name="message">Message to return on error.</param>
/// <returns>New custom type instance or <see langword="default" /> value of an error has occured.</returns>
public static T MakeCustomTypeInstance<T>(string typeName, out string message)
public static TResult MakeCustomTypeInstance<TResult>(string typeName, out string message)
{
var customType = GetCustomType(typeName, out message);

Expand All @@ -23,28 +23,28 @@ public static T MakeCustomTypeInstance<T>(string typeName, out string message)
return default;
}

if (!typeof(T).IsAssignableFrom(customType))
if (!typeof(TResult).IsAssignableFrom(customType))
{
message = $"Custom type '{customType.Name}' is not derived from desired type";
return default;
}

return ActivateCustomInstance<T>(customType, out message);
return ActivateCustomInstance<TResult>(customType, out message);
}

/// <summary>
/// Activates an instance of a custom type.
/// </summary>
/// <typeparam name="T">Type to cast new instance into.</typeparam>
/// <typeparam name="TResult">Type to cast new instance into.</typeparam>
/// <param name="customType">Custom type to instantiate.</param>
/// <param name="message">Message to return on error.</param>
/// <returns>New custom type instance or <see langword="default" /> value of an error has occured.</returns>
private static T ActivateCustomInstance<T>(Type customType, out string message)
private static TResult ActivateCustomInstance<TResult>(Type customType, out string message)
{
try
{
message = null;
return (T) Activator.CreateInstance(customType);
return (TResult) Activator.CreateInstance(customType);
}
catch (Exception ex)
{
Expand Down

0 comments on commit b2ad80d

Please sign in to comment.