Beispiel #1
0
 private void ValidateAttributes(CodeAttributeDeclarationCollection attributes)
 {
     if (attributes.Count != 0)
     {
         IEnumerator enumerator = attributes.GetEnumerator();
         while (enumerator.MoveNext())
         {
             CodeAttributeDeclaration current = (CodeAttributeDeclaration)enumerator.Current;
             ValidateTypeName(current, "Name", current.Name);
             ValidateTypeReference(current.AttributeType);
             foreach (CodeAttributeArgument argument in current.Arguments)
             {
                 this.ValidateAttributeArgument(argument);
             }
         }
     }
 }
Beispiel #2
0
        private void ValidateAttributes(CodeAttributeDeclarationCollection attributes)
        {
            if (attributes.Count == 0)
            {
                return;
            }
            IEnumerator en = attributes.GetEnumerator();

            while (en.MoveNext())
            {
                CodeAttributeDeclaration current = (CodeAttributeDeclaration)en.Current;
                ValidateTypeName(current, "Name", current.Name);
                foreach (CodeAttributeArgument arg in current.Arguments)
                {
                    ValidateAttributeArgument(arg);
                }
            }
        }
Beispiel #3
0
        protected virtual void OutputAttributeDeclarations(CodeAttributeDeclarationCollection attributes)
        {
            GenerateAttributeDeclarationsStart(attributes);

            IEnumerator enumerator = attributes.GetEnumerator();

            if (enumerator.MoveNext())
            {
                CodeAttributeDeclaration attribute = (CodeAttributeDeclaration)enumerator.Current;

                OutputAttributeDeclaration(attribute);

                while (enumerator.MoveNext())
                {
                    attribute = (CodeAttributeDeclaration)enumerator.Current;

                    output.WriteLine(',');
                    OutputAttributeDeclaration(attribute);
                }
            }

            GenerateAttributeDeclarationsEnd(attributes);
        }
        private void GenerateAttributes(CodeAttributeDeclarationCollection attributes, string prefix, bool inLine)
        {
            if (attributes.Count == 0) return;
            IEnumerator en = attributes.GetEnumerator();
            bool paramArray = false;

            while (en.MoveNext())
            {
                // we need to convert paramArrayAttribute to params keyword to
                // make csharp compiler happy. In addition, params keyword needs to be after
                // other attributes.

                CodeAttributeDeclaration current = (CodeAttributeDeclaration)en.Current;

                if (current.Name.Equals("system.paramarrayattribute", StringComparison.OrdinalIgnoreCase))
                {
                    paramArray = true;
                    continue;
                }

                GenerateAttributeDeclarationsStart(attributes);
                if (prefix != null)
                {
                    Output.Write(prefix);
                }

                if (current.AttributeType != null)
                {
                    Output.Write(GetTypeOutput(current.AttributeType));
                }
                Output.Write("(");

                bool firstArg = true;
                foreach (CodeAttributeArgument arg in current.Arguments)
                {
                    if (firstArg)
                    {
                        firstArg = false;
                    }
                    else
                    {
                        Output.Write(", ");
                    }

                    OutputAttributeArgument(arg);
                }

                Output.Write(")");
                GenerateAttributeDeclarationsEnd(attributes);
                if (inLine)
                {
                    Output.Write(" ");
                }
                else
                {
                    Output.WriteLine();
                }
            }

            if (paramArray)
            {
                if (prefix != null)
                {
                    Output.Write(prefix);
                }
                Output.Write("params");

                if (inLine)
                {
                    Output.Write(" ");
                }
                else
                {
                    Output.WriteLine();
                }
            }
        }
        private void GenerateAttributes(CodeAttributeDeclarationCollection attributes, bool inLine = false)
        {
            if (attributes.Count == 0)
            {
                return;
            }

            IEnumerator en         = attributes.GetEnumerator();
            bool        paramArray = false;

            while (en.MoveNext())
            {
                CodeAttributeDeclaration current = (CodeAttributeDeclaration)en.Current;

                // params (varargs) must be last parameter to actually compile
                if (current.Name.Equals("system.paramarrayattribute", StringComparison.OrdinalIgnoreCase))
                {
                    paramArray = true;
                    continue;
                }

                output.Write("@");

                if (current.AttributeType != null)
                {
                    output.Write(GetTypeOutput(current.AttributeType));
                }
                if (current.Arguments.Count > 0)
                {
                    output.Write("(");
                    bool firstArg = true;
                    foreach (CodeAttributeArgument arg in current.Arguments)
                    {
                        if (!firstArg)
                        {
                            output.Write(", ");
                        }
                        else
                        {
                            firstArg = false;
                        }
                        OutputAttributeArgument(arg);
                    }
                    output.Write(")");
                }

                if (!inLine)
                {
                    output.WriteLine();
                }
                else
                {
                    output.Write(" ");
                }
            }

            if (paramArray)
            {
                output.Write("params");
                if (!inLine)
                {
                    output.WriteLine();
                }
                else
                {
                    output.Write(" ");
                }
            }
        }