Could Any Body Let me clear where should I use Custom attribute.
I Know I can declare some metadat information to a type let say method or class or ineterface and get that information at runtime using reflection.I find it's one use in O/R mapping.
But Why should i declare a attribute
For example I have to declare a field for O/R mapping of a field in a table tblEmployee.I make a class Employee and in it make a property EmployeeID.In the property I declare a variable Of type String name fieldname and assign it value emloyee_id.
Then Couldn't I get the fieldname variable of the property at runtime using reflection.
I Also Want's to be clear what is the benefit of this way against declaring the attribute and get its information at runtime.
I have done it by the help of david hayden article http://davidhayden.com/blog/dave/archive/2006/03/07/2876.aspx.
I my self Find a little thing that if we have to provide some information to the let say interface then I should use attribute.
But please let me help for the concepts of attribute.
Please if any body knows any good article then help me
Thanks

Usage of Custom Attributes
Jacob Bolan
I think the following was the key question in your post and i'll try to answer it as good as i can.
You could get te name of the variable at runtime using reflection, the attribute is used to define for instance which field in the table this variable should map too. Ofcourse you could say that an attribute isn't needed if your table fieldname and your variable name are the same.
The benefit of getting the name of the variable directly using reflection instead of getting the attribute is that its faster. If you get the attribute information you need to do one more relfection operation (GetCustomAttributes or something along those lines). Which will perform a bit worse then getting the name of the variable only.
The downside on this is that your table fieldnames always need to be the same as the variable name (or at least a name that is derived from it). This ofcourse is not needed with the attribute approach. Also, other data can also be provided using attributes. For instance if a field is a key, or part of an index (and which index), or the database type (if this is different from the runtime type) of the field.
I hope this helps a bit. I have no idea what good tutorials about attributes are. It has been a while since i had to learn it myself.
mark_hykurama
I want's to let you know my situation.I have created entities classes along with properties which names are little different from the name of the fields that is
employee_id field maps with a property named EmployeeName.I have Created a generic method to insert value in the table according to the class.I am getting the class information at runtime by the help of reflection.For the mapping of properties to the field I have three choices
1, I could make a XML File "Object mapper" which will only contains the mapping of field to properties.
2, I could use attributes and get the information at runtime of properties.
3,I also have a simple workaround.Create a Method Which get a String (that is of a format of propertyName) PaaSeeDii and return a string (that is of a format of fieldname) paa_see_dii.
What will be the best approach
In My case I think Reflection
Pinky Lano