| | |
When to use Attributes????
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
It helps organize or flag members of a class. If you're serializing a class you may want to mark the members you want to include in serialization with an attribute, or maybe your logic serializes all public members and you only want to ignore certain members with the
The code automatically generates a Select, Insert, Update, and Delete queries based on the attributes it finds.
Maybe you want to control serialization:
Its just a handy way of going about things at runtime without having to maintain lists. You can reflect members and look for attributes.
XmlIgnore attribute. I wrote a data layer where I "bind" a class to an SQL Table with attributes: C# Syntax (Toggle Plain Text)
[DBTableInfo("vea_Alarm")] public sealed class Alarm : SqlObject { [DBFieldInfo("AlarmId", SqlDbType.Int, PrimaryKey=true, Identity=true)] private int _alarmId = 0; [DBFieldInfo("EventId", SqlDbType.Int)] private int _eventId; [DBFieldInfo("ServerId", SqlDbType.Int)] private int _serverId; [DBFieldInfo("SensorId", SqlDbType.Int)] private int _sensorId; [DBFieldInfo("SensorRow", SqlDbType.Int)] private int _sensorRow; [DBFieldInfo("IOPointNum", SqlDbType.Int)] private int _IOPointNum; [DBFieldInfo("EventNum", SqlDbType.Int)] private int _eventNum; [DBFieldInfo("StartDate", SqlDbType.DateTime)] private DateTime _startDate; [DBFieldInfo("EndDate", SqlDbType.DateTime)] private DateTime _endDate; [DBFieldInfo("CorrectedDate", SqlDbType.DateTime)] private DateTime _correctedDate; [DBFieldInfo("State", SqlDbType.VarChar, Size=DataLength.State)] private string _state; [DBFieldInfo("Alarm", SqlDbType.Bit)] private bool _alarm; [DBFieldInfo("Closed", SqlDbType.Bit)] private bool _closed; [DBFieldInfo("Corrected", SqlDbType.Bit)] private bool _corrected; [DBFieldInfo("IOName", SqlDbType.VarChar, Size=DataLength.IOName)] private string _ioName;
The code automatically generates a Select, Insert, Update, and Delete queries based on the attributes it finds.
Maybe you want to control serialization:
C# Syntax (Toggle Plain Text)
[Serializable] public sealed class SeriesTag { public SeriesTag() { this.Identifier = string.Empty; this.TrendIndex = 0; this.DataSourceGUID = string.Empty; this.SeriesGUID = string.Empty; } public SeriesTag(Series Parent) : this() { this.Parent = Parent; } [XmlIgnore] public Series Parent { get; set; }
Its just a handy way of going about things at runtime without having to maintain lists. You can reflect members and look for attributes.
![]() |
Similar Threads
- set attributes (Visual Basic 4 / 5 / 6)
- Advice on handling varying product attributes... (Database Design)
- Adding Attributes to all XML Nodes (RSS, Web Services and SOAP)
- change window attributes in body onload.. (JavaScript / DHTML / AJAX)
- Attributes Change it on its own (Network Security)
- How to change DIRECTORY ATTRIBUTES through C or C++ (C++)
- Dynamically modifying the CSS attributes through Javascript (JavaScript / DHTML / AJAX)
- Attributes (Java)
Other Threads in the C# Forum
- Previous Thread: Crystal Report Help
- Next Thread: Different character colours in a label (or any other control)?
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# capturing check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development drag draganddrop drawing encryption enum error event excel file files firefox form format forms formupdate function gdi+ httpwebrequest image index input install java label libraries list listbox listener loop mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox running... serialization server sleep socket sql statistics stream string table tcp tcpclientchannel text text-file textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml






