Beispiel #1
0
        public static AttributeDescription BuildAttribute(CodeGeneratorContext context, TypeMember type, object[] constructorArgumentsAndBody)
        {
            var body = constructorArgumentsAndBody.OfType <Action>().FirstOrDefault();
            var constructorArguments = constructorArgumentsAndBody
                                       .Where(x => !(x is Action))
                                       .Select(context.GetConstantExpression);

            var attribute = new AttributeDescription {
                AttributeType        = type,
                ConstructorArguments = constructorArguments.ToList()
            };

            var attributeContext = new AttributeContext(attribute);

            if (body != null)
            {
                using (context.PushState(attributeContext))
                {
                    body();
                }
            }

            return(attribute);
        }