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