Smart rounding was ajusted
This commit is contained in:
50
StructureHelperCommon/Services/Units/GetUnitLogic.cs
Normal file
50
StructureHelperCommon/Services/Units/GetUnitLogic.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Services.Units
|
||||
{
|
||||
public class GetUnitLogic : IGetUnitLogic
|
||||
{
|
||||
private static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
||||
private Dictionary<UnitTypes, string> defaultUnitNames;
|
||||
|
||||
|
||||
public GetUnitLogic()
|
||||
{
|
||||
defaultUnitNames = new()
|
||||
{
|
||||
{ UnitTypes.Length, "m"},
|
||||
{ UnitTypes.Area, "m2"},
|
||||
{ UnitTypes.Force, "kN" },
|
||||
{ UnitTypes.Moment, "kNm"},
|
||||
{ UnitTypes.Stress, "MPa"},
|
||||
{ UnitTypes.Curvature, "1/m"},
|
||||
};
|
||||
}
|
||||
|
||||
public IUnit GetUnit(UnitTypes unitType, string unitName = null)
|
||||
{
|
||||
if (unitName is null)
|
||||
{
|
||||
var boolResult = defaultUnitNames.TryGetValue(unitType, out unitName);
|
||||
if (boolResult == false)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": unit type{unitType} is unknown");
|
||||
}
|
||||
}
|
||||
return units
|
||||
.Where(u =>
|
||||
u.UnitType == unitType
|
||||
&
|
||||
u.Name == unitName)
|
||||
.Single();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user