public BasicUnit GetDeltaByUnit(XUnitTypeName unit) { if (!_dict.TryGetValue(unit, out var item)) { return(null); } return(item.GetDeltaByUnit()); }
/// <summary> /// Creates instance /// </summary> /// <param name="value">Name of type that contains value and unit i.e. Length</param> /// <param name="unit">Name of type that represents unit i.e. LengthUnit</param> /// <param name="container">Name of static type that contains fields with known unit names i.e. LengthUnits</param> public TypesGroup(XValueTypeName value, XUnitTypeName unit = null, XUnitContainerTypeName container = null) { Value = value ?? throw new ArgumentException(nameof(value)); ValueKind = Value.Kind; Unit = unit ?? value.ToUnitTypeName(); Container = container ?? Unit.ToUnitContainerTypeName(); }
public static ICodeSource MakeFromConstructor(XUnitTypeName unit, IReadOnlyList <ValueOfSomeTypeExpression> arguments, bool dependsOnLeftArgument) { var call = "new " + unit.GetTypename(); var ar = arguments.Select(a => (ICodeSource1)a.Expression).ToArray(); return(new MethodCallCodeSource(call, ar, dependsOnLeftArgument)); }
public RelatedUnitsFamily GetPowers(XUnitTypeName unitName) { var myInfo = FindByUnitName(unitName); if (myInfo is null) { return(null); } var other = new Dictionary <int, RelatedUnit>(); var powerOneUnit = myInfo.Power == 1 ? new TypesGroup(myInfo.Name) : myInfo.PowerOne; if (powerOneUnit is null) { throw new NotImplementedException(); } var powerOneUnitUnitName = powerOneUnit.Unit; foreach (var i in Items) { if (i.Name == myInfo.Name) { continue; } if (i.Power == 1) { var coo = new TypesGroup(i.Name).Unit; if (coo != powerOneUnitUnitName) { continue; } } else { if (powerOneUnitUnitName != i.PowerOne?.Unit) { continue; } } other[i.Power] = i; } return(new RelatedUnitsFamily(myInfo, other)); }
private void Scan(ValueOfSomeTypeExpressionRoot root, XUnitTypeName x, Kind2 kind, ExpressionPath path = null) { if (!_resolver.TryGetValue(x.GetTypename(), out var type)) { throw new NotImplementedException(); } var info1 = new ValueOfSomeTypeExpression(root, type, new TreeExpression(path, null, kind), kind); _sink.Add(info1); if (kind != Kind2.Property) { return; } foreach (var propInfo in type.GetProperties()) { var attribute = propInfo.GetCustomAttribute <RelatedUnitSourceAttribute>(); if (attribute != null && attribute.Usage == RelatedUnitSourceUsage.DoNotUse) { continue; } var pt = propInfo.PropertyType; if (!pt.Implements <IUnit>()) { continue; } Scan(root, new XUnitTypeName(propInfo.PropertyType.Name), kind, path + propInfo.Name); } foreach (var methodInfo in type.GetMethods(BindingFlags.Instance | BindingFlags.Public)) { var at = methodInfo.GetCustomAttribute <RelatedUnitSourceAttribute>(); if (at is null || (at.Usage & RelatedUnitSourceUsage.ProvidesRelatedUnit) == 0) { continue; } var returnType = methodInfo.ReturnType; if (!returnType.Implements <IUnit>()) { throw new Exception("Should return IUnit"); } if (methodInfo.GetParameters().Length != 0) { throw new Exception("Should be parameterles"); } Scan(root, new XUnitTypeName(returnType.Name), Kind2.Method, path + $"{methodInfo.Name}"); } }
private RelatedUnit FindByUnitName(XUnitTypeName unitName) { RelatedUnit myInfo = null; foreach (var i in Items) { var t = new TypesGroup(i.Name); if (t.Unit != unitName) { continue; } myInfo = i; break; } if (myInfo is null) { return(null); } //throw new NotImplementedException(); return(myInfo); }
private ICodeSource Construct(XUnitTypeName unit) { if (!_resolver.TryGetValue(unit.GetTypename(), out var type1)) { throw new NotImplementedException(); } ValueOfSomeTypeExpression[] sources; var constr = type1.GetConstructors() .Where(a => { var pa = a.GetParameters(); foreach (var info in pa) { if (!info.ParameterType.Implements <IUnit>()) { return(false); } } return(true); }) .OrderByDescending(a => a.GetParameters().Length) .ToArray(); var typesDict = TypeFinder.Make(_sink); if (constr.Length == 0) { sources = typesDict.GetTypeSources(type1); if (sources.Any()) { var src = sources[0]; return(new ExpressionCodeSource(src.Expression, src.Root == ValueOfSomeTypeExpressionRoot.Left)); } return(null); } var ccc = constr[0]; var list = typesDict.FindParameters(ccc, t => Construct(new XUnitTypeName(t.Name)), out var hasLeft); // var hasLeft = list.Any(q => q.Root == ValueOfSomeTypeExpressionRoot.Left); if (!hasLeft) { sources = typesDict.GetTypeSources(type1); if (sources.Any()) { var src = sources[0]; return(new ExpressionCodeSource(src.Expression, src.Root == ValueOfSomeTypeExpressionRoot.Left)); } throw new NotImplementedException(); } return(MethodCallCodeSource.MakeFromConstructor(unit, list, true)); }
public CommonFractionalUnit[] GetBy(XUnitTypeName namesUnit) { return(Items.Where(a => a.Type.Unit == namesUnit).ToArray()); }
public bool Equals(XUnitTypeName other) { return(TypeName.Equals(other.TypeName)); }