SharpCrafters Forum – Remove [assembly : ...] from AssemblyInfo.cs

SharpCrafters Support Forum

        


Remove [assembly : ...] from AssemblyInfo.cs Expand / Collapse
Author
Message
Posted 11/25/2009 5:24:21 AM


Community Member
Hello,

is it possible to remove entry from AssemblyInfo.cs using PostSharp.Core?

Problem:
I have entry like this:
[assembly: MyApplication(MyAttributeType = typeof(MyAttribute))]

I need to remove it at runtime.

If it is possible, then how?
Post #641
Posted 11/25/2009 6:00:44 AM


Gael Fraiteur

SharpCrafters
This is possible by developing a custom task. The collection of these custom attributes is in this.Project.Module.AssemblyManifest.CustomAttributes. Find your and remove it.

You may want to look at sample PostSharp.Samples.Trace to see how to work with PostSharp Core. What you want to do is very easy.
Post #642
Posted 11/25/2009 9:13:03 AM


Community Member
Thank you. Sorry, that was silly to ask. Here is code if anybody will need that

LinkedList<CustomAttributeDeclaration> customAttributesToRemove = new LinkedList<CustomAttributeDeclaration>();
               foreach (CustomAttributeDeclaration customAttribute in this.Project.Module.AssemblyManifest.CustomAttributes)
               {
                   if ((customAttribute.Constructor.DeclaringType is TypeRefDeclaration) &&
                       (customAttribute.Constructor.DeclaringType as PostSharp.CodeModel.TypeRefDeclaration).Name.Equals("MyApplicationAttribute"))
                       customAttributesToRemove.AddLast(customAttribute);
               }
               foreach (CustomAttributeDeclaration customAttribute in customAttributesToRemove)
                   this.Project.Module.AssemblyManifest.CustomAttributes.Remove(customAttribute);
Post #643
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 11:45am

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.673. 8 queries. Compression Disabled.