コード例 #1
0
        public RelatedUnit WithPrefixedUnit(string unitShortName, string fieldName,
                                            decimal multiplicator, string fromMethodNameSufix = null, TypeCodeAliases aliases = null,
                                            Action <AliasedPrefixedUnitInfo> extraSettings    = null)
        {
            if (aliases != null)
            {
                if (string.IsNullOrWhiteSpace(fieldName))
                {
                    if (!string.IsNullOrWhiteSpace(aliases.NameSingular))
                    {
                        fieldName = aliases.NameSingular.FirstUpper();
                    }
                }
                if (string.IsNullOrWhiteSpace(fromMethodNameSufix))
                {
                    if (!string.IsNullOrWhiteSpace(aliases.NamePlural))
                    {
                        fromMethodNameSufix = aliases.NamePlural.FirstUpper();
                    }
                }
            }

            AliasedPrefixedUnitInfo info = new AliasedPrefixedUnitInfo(fieldName,
                                                                       UnitShortCodeSource.MakeDirect(unitShortName), multiplicator.CsEncode(),
                                                                       fromMethodNameSufix, aliases);

            if (extraSettings != null)
            {
                extraSettings(info);
            }
            Units.Add(info);
            return(this);
        }
コード例 #2
0
 public static UnitShortCodeSource MakePower(UnitShortCodeSource baseSource, int baseSourcePower)
 {
     return(new UnitShortCodeSource
     {
         _baseSource = baseSource,
         _baseSourcePower = baseSourcePower
     });
 }
コード例 #3
0
 public RelatedUnitInfo(string fieldName, UnitShortCodeSource unitShortCode, string fromMethodNameSufix)
 {
     // unitShortCode       = unitShortCode?.Trim();
     fieldName           = fieldName.CoalesceNullOrWhiteSpace(unitShortCode.EffectiveValue);
     FieldName           = fieldName.Trim().FirstUpper();
     UnitShortCode       = unitShortCode;
     FromMethodNameSufix = fromMethodNameSufix;
 }
コード例 #4
0
 public AliasedPrefixedUnitInfo(
     string fieldName,
     UnitShortCodeSource unitShortCode,
     string scaleFactor,
     string fromMethodNameSufix,
     TypeCodeAliases aliases)
     : base(fieldName, unitShortCode, scaleFactor, fromMethodNameSufix)
 {
     Aliases = aliases;
 }
コード例 #5
0
        protected override void Add_FromMethods()
        {
            var collection  = CommonFractionalUnitDefs.All;
            var commonUnits = collection.GetBy(Cfg.UnitTypes.Unit);

            if (commonUnits.Length == 0)
            {
                return;
            }
            foreach (var i in commonUnits)
            {
                var u = new RelatedUnitInfo(i.TargetPropertyName,
                                            UnitShortCodeSource.MakeDirect(i.GetUnitName()),
                                            i.TargetPropertyName);
                BasicUnitValuesGenerator.Add_FromMethods(
                    GetType(),
                    i.Type.Value,
                    i.Type,
                    Target,
                    u);
            }
        }
コード例 #6
0
        private void Add_FromMethods()
        {
            var tmp = RelatedUnitGeneratorDefs.All;
            var d   = tmp.ByName(Cfg.UnitTypes.Value);

            if (d is null)
            {
                IRelatedUnitDefinition u = new RelatedUnitInfo(
                    Cfg.BaseUnit.Field,
                    UnitShortCodeSource.MakeDirect("----"),
                    Cfg.BaseUnit.Field);
                Add_FromMethods(GetType(), Cfg.UnitTypes.Value, Cfg.UnitTypes, Target, u);
                return;
            }

            if (d.Units is null || d.Units.Count == 0)
            {
                return;
            }
            foreach (var u in d.Units)
            {
                Add_FromMethods(GetType(), Cfg.UnitTypes.Value, Cfg.UnitTypes, Target, u);
            }
        }
コード例 #7
0
        private RelatedUnit WithPowerDerivedUnits(int power, PrefixedUnitInfo[] items, XValueTypeName[] values)
        {
            Power = power;
            if (power != 1)
            {
                PowerOne = new TypesGroup(values[0]);
            }

            var propertyPrefix = Prefix(power);

            foreach (var i in items)
            {
                var fromMethodNameSufix = i.FromMethodNameSufix.AddPrefix(propertyPrefix);
                var unitShortCodeSource = UnitShortCodeSource.MakePower(i.UnitShortCode, power);
                var q = new AliasedPrefixedUnitInfo(propertyPrefix + i.FieldName,
                                                    unitShortCodeSource,
                                                    Mul(power, i.ScaleFactor), fromMethodNameSufix, null);
                Units.Add(q);
            }

            if (power <= 1)
            {
                return(this);
            }
            for (var i = 1; i < power; i++)
            {
                var otherUnitContainer = values[i - 1] + "Unit";
                var myUnitContainer    = values[power - 1] + "Unit";
                var relation           = new UnitNamePrefixRelation(
                    Prefix(i), Prefix(power),
                    myUnitContainer, otherUnitContainer);
                PrefixRelations.Add(relation);
            }

            return(this);
        }