CodeTimerAttribute¶
CodeTimerAttribute is a method-level attribute ([CodeTimer(enabled)]) used purely as declarative metadata. It carries no behavior of its own; CodeTimer reads it via reflection to decide whether to time a given method.
Purpose¶
- Allow individual instrumented methods to opt in or out of timing via a declarative attribute rather than conditional code.
Context¶
- Namespace:
SAIF.Framework.CodeTimer - Assembly/package:
SAIF.Framework.CodeTimer.dll - Base type:
System.Attribute
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| Enabled | public bool Enabled { get; } |
Read-only flag indicating whether timing is enabled for the attributed method. |
| CodeTimerAttribute | public CodeTimerAttribute(bool enabled) |
Constructor; sets the Enabled flag from the attribute usage, e.g. [CodeTimer(true)]. |
Behavioral notes¶
CodeTimer.Start(MethodBase, ...)andCodeTimer.Stop(MethodBase, ...)look up this attribute viamethod.GetCustomAttributes(typeof(CodeTimerAttribute), false).FirstOrDefault(); if no attribute is present, the attribute-based gating check is skipped and the call proceeds via the private key-based overloads.- The
Enabledproperty is read-only after construction; there is no way to change it once the attribute instance is created.
Constraints and usage notes¶
- Applied to methods as
[CodeTimer(true)]or[CodeTimer(false)]; the constructor argument is required (no parameterless constructor exists). - This attribute only affects the
MethodBase-basedStart/Stopoverloads onCodeTimer; it has no effect on the private key-based overloads used internally.
Sources¶
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerAttribute.cs