Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Last active November 15, 2022 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinZikmund/9e236f404794eb47936c2eeb9c438a70 to your computer and use it in GitHub Desktop.
Save MartinZikmund/9e236f404794eb47936c2eeb9c438a70 to your computer and use it in GitHub Desktop.
using System.Reflection;
var attributeData = CustomAttributeData.GetCustomAttributes(typeof(TestClass))[0];
Console.WriteLine(attributeData.AttributeType == typeof(TestAttribute)); // true
Console.WriteLine(attributeData.ConstructorArguments[0].Value); // "Hello World"
[Test("Hello, world!")]
public class TestClass
{
}
public class TestAttribute : Attribute
{
public TestAttribute(string greeting) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment