예제 #1
0
 /// <summary>
 /// Adds the elements of a <see cref="AssemblyAttributeCollection"/> to the end of the collection.
 /// </summary>
 /// <param name="items">The <see cref="AssemblyAttributeCollection"/> to be added to the end of the collection.</param>
 public void AddRange(AssemblyAttributeCollection items)
 {
     for (int i = 0; (i < items.Count); i = (i + 1))
     {
         Add(items[i]);
     }
 }
예제 #2
0
            /// <summary>
            /// Generates code for the specified assembly attributes.
            /// </summary>
            /// <param name="assemblyAttributes">The assembly attributes for which code should be generated.</param>
            /// <param name="imports">Imports used to resolve the assembly attribute names to fully qualified type names.</param>
            /// <param name="assemblies">Assembly that will be used to resolve the attribute names to <see cref="Type" /> instances.</param>
            /// <param name="writer">The <see cref="TextWriter" /> to which the generated code will be written.</param>
            public void GenerateAssemblyAttributesCode(AssemblyAttributeCollection assemblyAttributes, StringCollection imports, StringCollection assemblies, TextWriter writer) {
                CodeCompileUnit codeCompileUnit = new CodeCompileUnit();

                // for C# the imports were already generated, as the # generator
                // will otherwise output the imports after the assembly attributes
                if (Language == CodeLanguage.VB) {
                    CodeNamespace codeNamespace = new CodeNamespace();

                    foreach (string import in imports) {
                        codeNamespace.Imports.Add(new CodeNamespaceImport(import));
                    }

                    codeCompileUnit.Namespaces.Add(codeNamespace);
                }

                foreach (AssemblyAttribute assemblyAttribute in assemblyAttributes) {
                    if (assemblyAttribute.IfDefined && !assemblyAttribute.UnlessDefined) {
                        // create new assembly-level attribute
                        CodeAttributeDeclaration codeAttributeDeclaration = new CodeAttributeDeclaration(assemblyAttribute.TypeName);

                        if (assemblyAttribute.AsIs) {
                            codeAttributeDeclaration.Arguments.Add(new CodeAttributeArgument(new CodeSnippetExpression(assemblyAttribute.Value)));
                        } else {
                            // convert string value to type expected by attribute constructor
                            object typedValue = GetTypedValue(assemblyAttribute, assemblies, imports);
                            if (typedValue != null) {
                                // add typed value to attribute arguments
                                codeAttributeDeclaration.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(typedValue)));
                            }
                        }

                        // add assembly-level argument to code compile unit
                        codeCompileUnit.AssemblyCustomAttributes.Add(codeAttributeDeclaration);
                    }
                }

                Generator.GenerateCodeFromCompileUnit(codeCompileUnit, writer, new CodeGeneratorOptions());
            }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssemblyAttributeCollection"/> class
 /// with the specified <see cref="AssemblyAttributeCollection"/> instance.
 /// </summary>
 public AssemblyAttributeCollection(AssemblyAttributeCollection value)
 {
     AddRange(value);
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AssemblyAttributeEnumerator"/> class
        /// with the specified <see cref="AssemblyAttributeCollection"/>.
        /// </summary>
        /// <param name="arguments">The collection that should be enumerated.</param>
        internal AssemblyAttributeEnumerator(AssemblyAttributeCollection arguments)
        {
            IEnumerable temp = (IEnumerable)(arguments);

            _baseEnumerator = temp.GetEnumerator();
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssemblyAttributeCollection"/> class
 /// with the specified <see cref="AssemblyAttributeCollection"/> instance.
 /// </summary>
 public AssemblyAttributeCollection(AssemblyAttributeCollection value)
 {
     AddRange(value);
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssemblyAttributeEnumerator"/> class
 /// with the specified <see cref="AssemblyAttributeCollection"/>.
 /// </summary>
 /// <param name="arguments">The collection that should be enumerated.</param>
 internal AssemblyAttributeEnumerator(AssemblyAttributeCollection arguments)
 {
     IEnumerable temp = (IEnumerable) (arguments);
     _baseEnumerator = temp.GetEnumerator();
 }
예제 #7
0
 /// <summary>
 /// Adds the elements of a <see cref="AssemblyAttributeCollection"/> to the end of the collection.
 /// </summary>
 /// <param name="items">The <see cref="AssemblyAttributeCollection"/> to be added to the end of the collection.</param> 
 public void AddRange(AssemblyAttributeCollection items)
 {
     for (int i = 0; (i < items.Count); i = (i + 1)) {
         Add(items[i]);
     }
 }