/// <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]); } }
/// <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()); }
/// <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); }
/// <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(); }
/// <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(); }