AssemblyInfo - Setting some properties using static class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have got a massive project built under c#. Needing to make massive changes
as a result to one of the AssemblyInfo attributes.

How is it possible to to set the AssemblyCompany by using a static class?

I tried:

[assembly: AssemblyCompany(Test.ApplicationInformation.CompanyName)]

but did not work. I also want to do this with other parts too so that we can
use the same details throught the project with out having to type again and
change in the future if a change is made.
 
How is it possible to to set the AssemblyCompany by using a static class?

You can use constants in the attribute declaration, but you can't
access any properties or fields. How did you declare
ApplicationInformation.CompanyName?



Mattias
 
Was as a static class
namespace Test.Application
public Information
{
static public string DefaultAssemblyCompanyName
{
get
{
return "CompanyName";
}
}
}
}
 
Was as a static class
namespace Test.Application
public Information
{
static public string DefaultAssemblyCompanyName
{
get
{
return "CompanyName";
}
}
}
}


That's a static property. If you change it to

class Information
{
public const string DefaultAssemblyCompanyName = "CompanyName";
}

you should be able to use it in an attribute.



Mattias
 
Thanks, this works! Will save me a lot of typing!

Thanks again for the quick response, it's good when you are working on a
project to be able to get another bit of it completed instead of putting a
side.
 
Got another quick one for you:

This does not work:

public const string DefaultAssemblyCopyright = "© Copyright 2004 - " +
System.DateTime.Now.Year.ToString() + ", All Rights Reserved.";

How can I assign this to a const, const needs a const is what I get?

I would only have to type the year once but I thought if the computer can do
it why should I do it!
 
It won't work because DateTime.Now is not constant. The thing you have to
remember is that attributes are set at compile time and embedded in the IL,
so if you can't know what it is at compile-time, then it can't be put in the
attribute. I ran into this problem a bit with resource-based attributes, as
the key can be const, but the resource value is not. The fix in that
instance was to come up with a library of resource-based attributes, but the
application (in this case, the compiler/linker) that processes those
attributes must be coded to understand that relationship and convert
accordingly. To fix, MS would either have to introduce something like
[CurrentYearBasedAssemblyCopyright(CopyrightTemplate="Copyright {0}, All
Rights Reserved")]. You could write such an attribute, but the MS build
system wouldn't know what it is.

"Dr. Paul Caesar - CoullByte (UK) Limited"
 
Thanks for the reply, as I thought!

Keith Patrick said:
It won't work because DateTime.Now is not constant. The thing you have to
remember is that attributes are set at compile time and embedded in the IL,
so if you can't know what it is at compile-time, then it can't be put in the
attribute. I ran into this problem a bit with resource-based attributes, as
the key can be const, but the resource value is not. The fix in that
instance was to come up with a library of resource-based attributes, but the
application (in this case, the compiler/linker) that processes those
attributes must be coded to understand that relationship and convert
accordingly. To fix, MS would either have to introduce something like
[CurrentYearBasedAssemblyCopyright(CopyrightTemplate="Copyright {0}, All
Rights Reserved")]. You could write such an attribute, but the MS build
system wouldn't know what it is.

"Dr. Paul Caesar - CoullByte (UK) Limited"
Got another quick one for you:

This does not work:

public const string DefaultAssemblyCopyright = "© Copyright 2004 - " +
System.DateTime.Now.Year.ToString() + ", All Rights Reserved.";

How can I assign this to a const, const needs a const is what I get?

I would only have to type the year once but I thought if the computer can
do
it why should I do it!
 
Back
Top