Ejemplo n.º 1
0
        protected void Add_Properties(Col1 c)
        {
            foreach (var i in c.Items)
            {
                if ((i.CheckingFlags & Flags1.DoNotCreateProperty) != 0)
                {
                    continue;
                }
                var p = Add_Property(i.PropertyName, i.PropertyType, i.Description);
                i.PropertyCreated?.Invoke(p);
                if ((i.CheckingFlags & Flags1.NotNull) == 0)
                {
                    continue;
                }

                if (Target.Kind == CsNamespaceMemberKind.Class)
                {
                    if ((i.CheckingFlags & Flags1.AddNotNullAttributeToPropertyIfPossible) != 0)
                    {
                        p.WithAttribute(CsAttribute.Make <NotNullAttribute>(Target));
                    }
                }

                if ((i.CheckingFlags & Flags1.PropertyCanBeNull) != 0)
                {
                    p.WithAttribute(CsAttribute.Make <CanBeNullAttribute>(Target));
                }
            }
        }
Ejemplo n.º 2
0
        public static void AddAggressiveInlining(this ICsClassMember csMethod, ITypeNameResolver cl)
        {
            var atr = CsAttribute.Make <MethodImplAttribute>(cl)
                      .WithArgumentCode(cl.GetTypeName <MethodImplOptions>() + "." + MethodImplOptions.AggressiveInlining);

            csMethod.Attributes.Add(atr);
        }
        private void Add_TryRecoverUnitFromName()
        {
            var resultTypeName = Cfg.Name.ToUnitTypeName().GetTypename();

            string c()
            {
                var cw = Ext.Create(GetType());

                const ArgChecking flags = ArgChecking.NormalizedString;

                cw.CheckArgument("unitName", flags, Target);
                cw.Open("foreach (var i in All)");
                cw.SingleLineIf("unitName == i.UnitName", "return i.Unit;");
                cw.Close();

                RelatedUnit cfg = Cfg;

                {
                    var type = typeof(Power).Assembly.GetTypes().FirstOrDefault(a => a.Name == resultTypeName);
                    if (type != null)
                    {
                        var t = GetFractionalUnit(type);
                        if (t.Item1 != null)
                        {
                            cw.WriteLine("// try to split");
                            cw.WriteLine("var parts = unitName.Split('/');");
                            cw.OpenIf("parts.Length == 2");
                            cw.WriteLine("var counterUnit = " + t.Item1.Name + "s.TryRecoverUnitFromName(parts[0]);");
                            cw.WriteLine("var denominatorUnit = " + t.Item2.Name + "s.TryRecoverUnitFromName(parts[1]);");
                            cw.WriteLine("return new " + resultTypeName + "(counterUnit, denominatorUnit);");
                            cw.Close();
                            cw.WriteLine("throw new ArgumentException(nameof(unitName));");
                            return(cw.Code);
                        }
                    }
                }
                cw.WriteReturn(new CsArguments("unitName").Create(resultTypeName));
                return(cw.Code);
            }

            var body = c();
            // koniec body
            var m = Target.AddMethod("TryRecoverUnitFromName", resultTypeName).WithStatic().WithBody(body);
            var p = m.AddParam("unitName", "string");

            p.WithAttribute(CsAttribute.Make <NotNullAttribute>(Target));
        }