コード例 #1
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);
        }
コード例 #2
0
        private static List <AttributeItem> getAttributeValue(CsAttribute pAttribute, string pAttrName, FactoryExpressionCreator pCreator)
        {
            string        s;
            AttributeItem item = new AttributeItem();

            if (pAttribute.attribute_name != null)
            {
                CsNamespaceOrTypeName n = (CsNamespaceOrTypeName)pAttribute.attribute_name;
                s = n.identifier.original_text;
            }
            else
            {
                throw new Exception();
                //s = attribute.type.parent.name;
            }

            if (s.Equals(pAttrName, StringComparison.Ordinal) || (s + "Attribute").Equals(pAttrName, StringComparison.Ordinal))
            {
                item.IsEmpty = false;
                foreach (var argument in pAttribute.positional_argument_list.list)
                {
                    item.Parameters.Add(((CsLiteral)argument).literal);
                }

                foreach (var argument in pAttribute.named_argument_list)
                {
                    item.NamedArguments.Add(argument.identifier.identifier, pCreator.Parse(argument.expression));
                }
            }

            return(new List <AttributeItem> {
                item
            });
        }
コード例 #3
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));
                }
            }
        }
コード例 #4
0
        private void Add_ClassAttributes()
        {
            var attribute = new CsAttribute("Serializable");

            Target.Attributes.Add(attribute);
            attribute = new CsAttribute("JsonConverter")
                        .WithArgumentCode($"typeof({Target.Name}JsonConverter)");
            Target.Attributes.Add(attribute);
        }
        /// <summary>
        /// Extension method that returns a full attribute declaration in the C# language format.
        /// </summary>
        /// <param name="source">The attribute toe generate the c# signature for.</param>
        /// <param name="manager">Optional parameter that contains all the using statements from the source code, when used will replace namespaces on type definition in code.</param>
        /// <returns>The formatted attribute signature or null if data was missing to create the attribute.</returns>
        public static string CSharpFormatAttributeSignature(this CsAttribute source, NamespaceManager manager = null)
        {
            if (source == null)
            {
                return(null);
            }
            if (!source.IsLoaded)
            {
                return(null);
            }

            return(!source.HasParameters ? $"[{source.Type.CSharpFormatTypeName(manager)}{Symbols.ParametersDefinitionStart}{Symbols.ParametersDefinitionEnd}]" : $"[{source.Type.CSharpFormatTypeName(manager)}{source.Parameters.CSharpFormatAttributeParametersSignature()}]");
        }
コード例 #6
0
        public static void AddRelatedUnitSourceAttribute(this IAttributable attributable, ITypeNameResolver resolver,
                                                         RelatedUnitSourceUsage flag, int sortOrder)
        {
            var argument    = resolver.GetEnumValueCode(flag);
            var csAttribute = new CsAttribute(nameof(RelatedUnitSourceAttribute))
                              .WithArgumentCode(argument);

            if (flag != RelatedUnitSourceUsage.DoNotUse)
            {
                csAttribute.WithArgument(sortOrder);
            }
            attributable.WithAttribute(csAttribute);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        /// <summary>
        /// Checks the attribute to determine if a HTTP verb supported by web api.
        /// </summary>
        /// <param name="sourceAttribute">Target attribute to search.</param>
        /// <returns>True if found or false if not.</returns>
        public static bool IsWebApiAttribute(CsAttribute sourceAttribute)
        {
            if (sourceAttribute == null)
            {
                return(false);
            }
            if (!sourceAttribute.IsLoaded)
            {
                return(false);
            }
            var attributeType = sourceAttribute.Type;

            if (attributeType?.Namespace != AspNetConstants.MvcNamespace)
            {
                return(false);
            }

            bool result = false;

            switch (attributeType.Name)
            {
            case AspNetConstants.HttpGetAttributeName:
                result = true;
                break;

            case AspNetConstants.HttpPostAttributeName:
                result = true;
                break;

            case AspNetConstants.HttpDeleteAttributeName:
                result = true;
                break;

            case AspNetConstants.HttpPutAttributeName:
                result = true;
                break;

            default:
                result = false;
                break;
            }

            return(result);
        }
コード例 #9
0
ファイル: Helpers.cs プロジェクト: gamificationvn/cstoas3
		private static List<AttributeItem> getAttributeValue(CsAttribute pAttribute, string pAttrName, FactoryExpressionCreator pCreator) {
			string s;
			AttributeItem item = new AttributeItem();

			if (pAttribute.attribute_name != null) {
				CsNamespaceOrTypeName n = (CsNamespaceOrTypeName)pAttribute.attribute_name;
				s = n.identifier.original_text;
			} else {
				throw new Exception();
				//s = attribute.type.parent.name;
			}

			if (s.Equals(pAttrName, StringComparison.Ordinal) || (s + "Attribute").Equals(pAttrName, StringComparison.Ordinal)) {
				item.IsEmpty = false;
				foreach (var argument in pAttribute.positional_argument_list.list) {
					item.Parameters.Add(((CsLiteral)argument).literal);
				}

				foreach (var argument in pAttribute.named_argument_list) {
					item.NamedArguments.Add(argument.identifier.identifier, pCreator.Parse(argument.expression));
				}
			}

			return new List<AttributeItem> {item};
		}