Last active
November 15, 2022 12:53
-
-
Save MartinZikmund/9e236f404794eb47936c2eeb9c438a70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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