📦 IrbyImaging.Utility – AssetCategory Enum Documentation
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model:
AssetCategoryEnum - Display Attribute & Metadata
- UML Diagram
- Usage Examples & Sample Code
- Helper Methods & Utilities
- Error Handling & Edge Cases
- API Endpoints & Integrations
- Conclusion
🎯 1. Overview & Purpose
The AssetCategory enum is part of the IrbyImaging.Utility namespace and defines a strongly‑typed set of categories representing various hardware assets used within the Irby Imaging ecosystem:
- Purpose: To standardize and centralize asset classification, ensuring consistency across business logic, UI displays, reporting, and data storage layers.
- Intended Use:
- Tagging and filtering asset records (
MobileDevice,Printer, etc.). - Driving UI dropdowns and display labels via the
Displayattribute. - Enabling compile‑time safety, avoiding “magic strings” in code.
- Tagging and filtering asset records (
⚙ 2. Dependencies & Technologies
| Dependency | Version/Info | Purpose |
|---|---|---|
.NET Standard / .NET Framework |
≥ 4.5 | Base runtime for C# enums |
System.ComponentModel.DataAnnotations |
Built‑in .NET library | Provides [Display] attribute support |
Note: There are no external or third‑party NuGet packages required—only the core DataAnnotations library.
🔑 3. Key Functional Areas
- Enum Definition: Defines a fixed set of named constants for asset categories.
- User‑Friendly Labels: Uses
[Display(Name = "...")]to specify human-readable names. - Reflection‑Friendly: Supports tooling and reflection for UI generation and localization.
📊 4. Data Model: AssetCategory Enum
namespace IrbyImaging.Utility
{
/// <summary>
/// A strongly-typed enumeration of all supported asset categories.
/// </summary>
public enum AssetCategory
{
[Display(Name = "Mobile Device")]
MobileDevice,
Computer,
Printer,
Monitor,
Dock,
[Display(Name = "Network Equipment")]
NetworkEquipment,
[Display(Name = "Desk Phone")]
DeskPhone,
[Display(Name = "Office Printer")]
OfficePrinter,
[Display(Name = "Safety Equipment")]
SafetyEquipment
}
}
Members & Display Names:
| Enum Member | Display Name |
|---|---|
| MobileDevice | Mobile Device |
| Computer | Computer |
| Printer | Printer |
| Monitor | Monitor |
| Dock | Dock |
| NetworkEquipment | Network Equipment |
| DeskPhone | Desk Phone |
| OfficePrinter | Office Printer |
| SafetyEquipment | Safety Equipment |
🖋 5. Display Attribute & Metadata
The [Display(Name = "...")] attribute from System.ComponentModel.DataAnnotations serves to:
- Provide a user-friendly label for UI controls, reports, and logs.
- Facilitate localization when paired with resource files.
- Drive model-binding in ASP.NET MVC/Razor forms (
@Html.DisplayFor(...),<select>lists).
📈 6. UML Diagram
classDiagram
class AssetCategory {
<<enumeration>>
+MobileDevice
+Computer
+Printer
+Monitor
+Dock
+NetworkEquipment
+DeskPhone
+OfficePrinter
+SafetyEquipment
}
🛠 7. Usage Examples & Sample Code
7.1. Rendering a Dropdown in ASP.NET MVC
@using IrbyImaging.Utility
@model YourViewModel
<label>Asset Category:</label>
@Html.DropDownListFor(m => m.SelectedCategory,
Enum.GetValues(typeof(AssetCategory))
.Cast<AssetCategory>()
.Select(c => new SelectListItem {
Value = c.ToString(),
Text = GetDisplayName(c)
}),
"-- Select Category --")
7.2. Retrieving the Display Name via Reflection
using System;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
public static string GetDisplayName(AssetCategory category)
{
var memberInfo = category.GetType()
.GetMember(category.ToString())
.FirstOrDefault();
var displayAttr = memberInfo?
.GetCustomAttribute<DisplayAttribute>();
return displayAttr?.Name ?? category.ToString();
}
// Usage
Console.WriteLine(GetDisplayName(AssetCategory.DeskPhone));
// Output: "Desk Phone"
🧰 8. Helper Methods & Utilities
While the enum itself provides no helper methods, you may define extension methods to streamline working with it:
public static class AssetCategoryExtensions
{
public static string ToFriendlyString(this AssetCategory category) =>
category.GetType()
.GetMember(category.ToString())
.FirstOrDefault()?
.GetCustomAttribute<DisplayAttribute>()?
.Name
?? category.ToString();
}
🚨 9. Error Handling & Edge Cases
- Invalid Parsing: When converting from string to
AssetCategory, catchArgumentExceptionif the input is not a valid enum name. - Missing DisplayAttribute: Fallback to
Enum.ToString()if[Display]is absent.
try
{
var cat = (AssetCategory) Enum.Parse(typeof(AssetCategory), inputString);
}
catch (ArgumentException)
{
// Handle unknown category
}
🔌 10. API Endpoints & Integrations
This file does not define any HTTP endpoints. However,
AssetCategoryis often used in:
- Web APIs: As part of request/response DTOs.
- Database Models: Mapped to
nvarcharorintcolumns via EF Core. - Reporting Engines: Filtering and grouping by asset category.
🎁 11. Conclusion
The AssetCategory enum is a simple yet powerful utility building block. By centralizing asset classifications:
- You achieve type safety and compile‑time checks.
- You enable consistent UI labels and localization.
- You simplify filtering, sorting, and reporting on assets.
Leverage the sample code and extension methods above to integrate AssetCategory seamlessly into your application’s UI, business logic, and data layers. 🚀
© 2022 IrbyImaging. All rights reserved.