AssemblyTool/RecodeItLib/Utils/ExtentionMethods.cs

62 lines
1.4 KiB
C#
Raw Normal View History

2024-06-14 19:06:21 -04:00
using ReCodeIt.Models;
2024-06-13 01:46:51 -04:00
2024-06-14 19:06:21 -04:00
namespace ReCodeIt.Utils;
2024-06-13 01:46:51 -04:00
internal static class ExtentionMethods
{
public static void AddScoreToResult(this ScoringModel model)
{
try
{
if (DataProvider.ScoringModels.TryGetValue(model.ProposedNewName, out HashSet<ScoringModel> modelHashset))
{
foreach (var outVal in modelHashset)
{
if (outVal.Definition.Name == model.Definition.Name)
{
return;
}
}
modelHashset.Add(model);
return;
}
var newHash = new HashSet<ScoringModel>
{
model
};
DataProvider.ScoringModels.Add(model.ProposedNewName, newHash);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static int CalculateMaxScore(this SearchParams parms)
{
var propInfos = typeof(SearchParams).GetProperties();
int maxScore = 0;
foreach (var propInfo in propInfos)
{
object value = propInfo.GetValue(parms);
if (value == null) continue;
if (value is List<string> list)
{
maxScore += list.Count;
}
else
{
maxScore++;
}
}
return maxScore;
}
}