473,396 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Attributes VS Property!

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.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
6 1887
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.

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook
Nov 16 '05 #2
On 06 Jul 2004 15:24, "Chua Wen Ching" wrote:
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.

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP for Outlook
Nov 16 '05 #3
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" <ch************@nospam.hotmail.com> wrote in message
news:2E**********************************@microsof t.com...
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" wrote:
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 colleagueask 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 awhile, 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 attributesas 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.

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook

Nov 16 '05 #4
Hi Simon Smith,

Thanks again.
--
Regards,
Chua Wen Ching :)
"Simon Smith" wrote:
On 06 Jul 2004 15:24, "Chua Wen Ching" wrote:
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.

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP for Outlook

Nov 16 '05 #5
Hi Manoj G,

Thanks. I will bear that in mind :)
--
Regards,
Chua Wen Ching :)
"Manoj G [MVP]" wrote:
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" <ch************@nospam.hotmail.com> wrote in message
news:2E**********************************@microsof t.com...
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" wrote:
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.

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook


Nov 16 '05 #6
Hi WillemM,

Thanks for your tips :) I will bear that in mind. Cheers.
--
Regards,
Chua Wen Ching :)
"WillemM" wrote:
I prefer the attribute, since it's a class attribute and has nothing to do with the actual code :)

"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
{

}

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.
--
Regards,
Chua Wen Ching :)

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
Hi, I am messing around with custom attributes and may have understood the concept a bit wrong:- I have a simple class that has a few public properties that individually have custom...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
3
by: redefined.horizons | last post by:
I've been reading about Python Classes, and I'm a little confused about how Python stores the state of an object. I was hoping for some help. I realize that you can't create an empty place holder...
5
by: Kimmo Laine | last post by:
Hi is there a way to change propertys attribute from the code? Let´s say that i have the following property in my class: public int Count } Is there a way to change the displayname, from...
2
by: P4trykx | last post by:
Hello I'm want to add some custom attributes to WebControls using WebControl.Attributes.Add("abc","234"); So the html output will look like this, <input type="hidden" abc="123" /etc. I know...
23
by: Frank Millman | last post by:
Hi all I have a small problem. I have come up with a solution, but I don't know if it is a) safe, and b) optimal. I have a class with a number of attributes, but for various reasons I cannot...
5
by: florin | last post by:
hi Is there a "simple" way to add attributes to a class/property at runtime? What I try to do is set the default editor for a class/property at runtime (I know I can set this very easy by...
1
by: jason.cipriani | last post by:
I'm just recently starting to use XML for storing data, and I am wondering when it is more appropriate to use child node values instead of node attributes -- and in general, what are good ways to...
7
by: bstieve | last post by:
Hi all, i'm looking at the next problem. i'm trying to get the names of attributes of object or of types. example class test private name as string sub new (byval test as string) me.name =...
5
by: King | last post by:
I am new to python and getting into classes. Here I am trying to create subtype of built in types with some additional attributes and function. 'Attributes' is the main class and holds all the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.