Attributes VS Property!

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

Guest

Hi i had 1 question.

I had 2 ways to doing this, but i not sure which is the best way. My colleague ask me this and i had no idea why i choose either one of these.

I want to get version number of a library. Just ignore AssemblyInfo for a while, as i need to set version of each class within the library.

1st way:

by custom attributes

Example
[VersionAttribute("1.0.0.1")]
public class Animal
{

}

or

2nd way:

private string versionNumber = "1.0.0.1";

public string VersionNumber
{
get
{
return versionNumber;
}
}

Please help. Thanks. I just need a confirmation, well i would prefer attributes as it is easy.
 
Hi i had 1 question.

I had 2 ways to doing this, but i not sure which is the best way. My colleague
ask me this and i had no idea why i choose either one of these.

I want to get version number of a library. Just ignore AssemblyInfo for a
while, as i need to set version of each class within the library.

1st way:

by custom attributes

Example
[VersionAttribute("1.0.0.1")]
public class Animal
2nd way:

private string versionNumber = "1.0.0.1";


Please help. Thanks. I just need a confirmation, well i would prefer attributes
as it is easy.

I think you're right, because using a private string member adds stuff
to the class which has nothing to do with what the class actually does.
Adding an Attribute to a class adds information relevant to the class,
and version is as relevant as most other stuff.
 
Hi Simon Smith,

Does it means using attributes is the right way to do it? I just need some
verification. :)

Thanks again.

For this, then yes, I think an attribute is the right way.
 
Hi,

Simon is right. Version is like a Meta information of the class and has
nothing with the implementation. Adding it as an attribute automattically
adds this information to the type metadata and can be extracted thru
reflection.


--
HTH,
Manoj G
[MVP , Visual Developer - Visual Basic ]
http://msmvps.com/manoj/

Chua Wen Ching said:
Hi Simon Smith,

Does it means using attributes is the right way to do it? I just need some verification. :)

Thanks again.
--
Regards,
Chua Wen Ching :)


Simon Smith said:
Hi i had 1 question.

I had 2 ways to doing this, but i not sure which is the best way. My colleague
ask me this and i had no idea why i choose either one of these.

I want to get version number of a library. Just ignore AssemblyInfo for a
while, as i need to set version of each class within the library.

1st way:

by custom attributes

Example
[VersionAttribute("1.0.0.1")]
public class Animal
2nd way:

private string versionNumber = "1.0.0.1";


Please help. Thanks. I just need a confirmation, well i would prefer attributes
as it is easy.

I think you're right, because using a private string member adds stuff
to the class which has nothing to do with what the class actually does.
Adding an Attribute to a class adds information relevant to the class,
and version is as relevant as most other stuff.
 
Hi Manoj G,

Thanks. I will bear that in mind :)
--
Regards,
Chua Wen Ching :)


Manoj G said:
Hi,

Simon is right. Version is like a Meta information of the class and has
nothing with the implementation. Adding it as an attribute automattically
adds this information to the type metadata and can be extracted thru
reflection.


--
HTH,
Manoj G
[MVP , Visual Developer - Visual Basic ]
http://msmvps.com/manoj/

Chua Wen Ching said:
Hi Simon Smith,

Does it means using attributes is the right way to do it? I just need some verification. :)

Thanks again.
--
Regards,
Chua Wen Ching :)


Simon Smith said:
On 06 Jul 2004 12:48, "Chua Wen Ching" wrote:
Hi i had 1 question.

I had 2 ways to doing this, but i not sure which is the best way. My colleague
ask me this and i had no idea why i choose either one of these.

I want to get version number of a library. Just ignore AssemblyInfo for a
while, as i need to set version of each class within the library.

1st way:

by custom attributes

Example
[VersionAttribute("1.0.0.1")]
public class Animal

2nd way:

private string versionNumber = "1.0.0.1";



Please help. Thanks. I just need a confirmation, well i would prefer attributes
as it is easy.

I think you're right, because using a private string member adds stuff
to the class which has nothing to do with what the class actually does.
Adding an Attribute to a class adds information relevant to the class,
and version is as relevant as most other stuff.
 
Hi WillemM,

Thanks for your tips :) I will bear that in mind. Cheers.
--
Regards,
Chua Wen Ching :)


WillemM said:
I prefer the attribute, since it's a class attribute and has nothing to do with the actual code :)

Chua Wen Ching said:
Hi i had 1 question.

I had 2 ways to doing this, but i not sure which is the best way. My colleague ask me this and i had no idea why i choose either one of these.

I want to get version number of a library. Just ignore AssemblyInfo for a while, as i need to set version of each class within the library.

1st way:

by custom attributes

Example
[VersionAttribute("1.0.0.1")]
public class Animal
{

}

or

2nd way:

private string versionNumber = "1.0.0.1";

public string VersionNumber
{
get
{
return versionNumber;
}
}

Please help. Thanks. I just need a confirmation, well i would prefer attributes as it is easy.
 
Back
Top