The GetAttribute<T>
method retrieves a custom attribute of type T
from the type described by the TypeDescription
instance. This method allows you to specify whether to search for inherited attributes as well.
The GetAttribute<T>
method retrieves a custom attribute of type T
from the type described by the TypeDescription
instance. This method allows you to specify whether to search for inherited attributes as well.
To use the GetAttribute<T>
method, specify the type of attribute you are looking for as the generic type parameter T
. Pass a boolean value to the inherited
parameter to indicate whether to include inherited attributes in the search.
If the attribute is found, it is returned; otherwise, the method returns null
.
// Example of using GetAttribute<T> to retrieve a custom attribute // Assume MyCustomAttribute is a defined attribute class public class MyCustomAttribute : Attribute { public string Description { get; set; } } // Example class with a custom attribute [MyCustomAttribute(Description = "This is a test class.")] public class TestClass { } // Usage TypeDescription typeDescription = TypeLibrary.GetTypeDescription(typeof(TestClass)); MyCustomAttribute attribute = typeDescription.GetAttribute<MyCustomAttribute>(true); if (attribute != null) { Console.WriteLine($"Attribute Description: {attribute.Description}"); } else { Console.WriteLine("Attribute not found."); }