---
title: CodeTimerAttribute
summary: API reference for CodeTimerAttribute.
status: draft
owner: <owner>
last_reviewed: 2026-07-23
library: SAIF.Framework.CodeTimer
reference_type: package
---

# CodeTimerAttribute

`CodeTimerAttribute` is a method-level attribute (`[CodeTimer(enabled)]`) used purely as declarative metadata. It carries no behavior of its own; [CodeTimer](CodeTimer.md) 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, ...)` and `CodeTimer.Stop(MethodBase, ...)` look up this attribute via `method.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 `Enabled` property 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`-based `Start`/`Stop` overloads on `CodeTimer`; it has no effect on the private key-based overloads used internally.

## Sources
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerAttribute.cs
