{"id":2193,"date":"2024-10-18T10:34:10","date_gmt":"2024-10-18T10:34:10","guid":{"rendered":"https:\/\/www.w3computing.com\/articles\/?p=2193"},"modified":"2024-10-18T10:35:14","modified_gmt":"2024-10-18T10:35:14","slug":"how-to-use-reflection-to-inspect-types-at-runtime-in-csharp","status":"publish","type":"post","link":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/","title":{"rendered":"How to Use Reflection to Inspect Types at Runtime in C#"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata about objects, classes, and other entities in your code without having to know them at compile time. While reflection can be useful for a variety of purposes\u2014from dynamic object creation to testing and debugging\u2014it must also be used with caution, as it can impact performance and security. This tutorial will guide you through the essential concepts, use cases, and practical examples of using reflection in C#.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Reflection?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reflection is the ability of a program to inspect and interact with its own structure, metadata, and code during runtime. In C#, reflection is implemented through the classes in the <code>System.Reflection<\/code> namespace. With reflection, you can:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Discover Type Information<\/strong>: You can examine metadata such as class names, methods, properties, fields, and events of a type.<\/li>\n\n\n\n<li><strong>Invoke Methods Dynamically<\/strong>: Reflection allows you to invoke methods on objects dynamically, even if the method names and parameters are not known until runtime.<\/li>\n\n\n\n<li><strong>Access Private Members<\/strong>: It can be used to access private fields and methods, which might otherwise be inaccessible through traditional object-oriented programming techniques.<\/li>\n\n\n\n<li><strong>Create Instances Dynamically<\/strong>: You can instantiate objects at runtime, even if the exact type isn&#8217;t known at compile time.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">While reflection opens the door to dynamic behaviors and advanced use cases, its cost in terms of performance and security should not be overlooked. Excessive use of reflection can slow down your application, and accessing private members can lead to fragile code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">When to Use Reflection<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reflection is most useful in scenarios where the type information isn&#8217;t available at compile time. Some of the most common scenarios include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Dynamic loading of assemblies<\/strong>: If your application needs to load external assemblies at runtime (for example, plugins or modules), reflection allows you to discover types and methods in the loaded assembly.<\/li>\n\n\n\n<li><strong>Object serialization and deserialization<\/strong>: Some frameworks use reflection to automatically serialize or deserialize objects, even if the object types are not known ahead of time.<\/li>\n\n\n\n<li><strong>Testing and debugging<\/strong>: Unit testing frameworks like NUnit and MSTest use reflection to discover test methods.<\/li>\n\n\n\n<li><strong>Framework or library development<\/strong>: If you&#8217;re building a library that interacts with other code dynamically, reflection can be helpful for inspecting and modifying objects.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Despite its versatility, reflection is typically avoided in performance-critical sections of the code. Modern development practices suggest relying on static type information whenever possible to avoid the overhead reflection may introduce.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Concepts of Reflection in C<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before diving into practical examples, let\u2019s discuss a few key concepts that are fundamental to understanding how reflection works in C#.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Assemblies<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">An assembly is the building block of .NET applications. It\u2019s a compiled unit that can contain types, resources, and metadata. Assemblies can be either executable (.exe) or libraries (.dll), and they store all the code and metadata needed for an application to run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using reflection, you can load and inspect assemblies at runtime using methods provided by the <code>System.Reflection<\/code> namespace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Types<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>Type<\/code> in .NET represents any data structure, including classes, interfaces, enums, arrays, and structs. The <code>System.Type<\/code> class is the key entry point for inspecting types in reflection. Through a <code>Type<\/code> object, you can discover details about a class, such as its name, methods, fields, properties, events, base class, and implemented interfaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Members<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Members of a class include methods, fields, properties, events, and constructors. Reflection allows you to inspect and interact with these members using methods like <code>GetMethods()<\/code>, <code>GetFields()<\/code>, <code>GetProperties()<\/code>, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Type Information with Reflection<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In C#, the primary class for working with reflection is <code>System.Type<\/code>. This class provides the basic functionality you need to inspect types. To obtain a <code>Type<\/code> object, you have several options:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use the <code>typeof()<\/code> operator, which returns the <code>Type<\/code> object for a known type at compile time.<\/li>\n\n\n\n<li>Call <code>GetType()<\/code> on an instance of an object to obtain its runtime type.<\/li>\n\n\n\n<li>Use <code>Assembly.GetType()<\/code> to load a type by its name at runtime from an assembly.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here are examples of each approach:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        <span class=\"hljs-comment\">\/\/ Option 1: Using typeof operator<\/span>\n        Type stringType = <span class=\"hljs-keyword\">typeof<\/span>(<span class=\"hljs-keyword\">string<\/span>);\n        Console.WriteLine(stringType.FullName);\n\n        <span class=\"hljs-comment\">\/\/ Option 2: Using GetType on an instance<\/span>\n        <span class=\"hljs-keyword\">object<\/span> obj = <span class=\"hljs-string\">\"Hello, World!\"<\/span>;\n        Type objType = obj.GetType();\n        Console.WriteLine(objType.FullName);\n\n        <span class=\"hljs-comment\">\/\/ Option 3: Using Assembly to get a type by name<\/span>\n        Type typeFromAssembly = Type.GetType(<span class=\"hljs-string\">\"System.Int32\"<\/span>);\n        Console.WriteLine(typeFromAssembly.FullName);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Getting Type Information<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have obtained a <code>Type<\/code> object, you can inspect it to discover the metadata associated with the type. This includes the class name, namespace, base type, and a list of members. Let\u2019s explore some common reflection methods for accessing type information.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n<span class=\"hljs-keyword\">using<\/span> System.Reflection;\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SampleClass<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> MyProperty { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">MyMethod<\/span>(<span class=\"hljs-params\"><\/span>)<\/span> { }\n}\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        Type type = <span class=\"hljs-keyword\">typeof<\/span>(SampleClass);\n\n        <span class=\"hljs-comment\">\/\/ Get the name of the type<\/span>\n        Console.WriteLine(<span class=\"hljs-string\">\"Type Name: \"<\/span> + type.Name);\n\n        <span class=\"hljs-comment\">\/\/ Get the namespace<\/span>\n        Console.WriteLine(<span class=\"hljs-string\">\"Namespace: \"<\/span> + type.Namespace);\n\n        <span class=\"hljs-comment\">\/\/ Get the base type<\/span>\n        Console.WriteLine(<span class=\"hljs-string\">\"Base Type: \"<\/span> + type.BaseType);\n\n        <span class=\"hljs-comment\">\/\/ Get the properties<\/span>\n        PropertyInfo&#91;] properties = type.GetProperties();\n        <span class=\"hljs-keyword\">foreach<\/span> (<span class=\"hljs-keyword\">var<\/span> prop <span class=\"hljs-keyword\">in<\/span> properties)\n        {\n            Console.WriteLine(<span class=\"hljs-string\">\"Property: \"<\/span> + prop.Name);\n        }\n\n        <span class=\"hljs-comment\">\/\/ Get the methods<\/span>\n        MethodInfo&#91;] methods = type.GetMethods();\n        <span class=\"hljs-keyword\">foreach<\/span> (<span class=\"hljs-keyword\">var<\/span> method <span class=\"hljs-keyword\">in<\/span> methods)\n        {\n            Console.WriteLine(<span class=\"hljs-string\">\"Method: \"<\/span> + method.Name);\n        }\n\n        <span class=\"hljs-comment\">\/\/ Get the fields<\/span>\n        FieldInfo&#91;] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);\n        <span class=\"hljs-keyword\">foreach<\/span> (<span class=\"hljs-keyword\">var<\/span> field <span class=\"hljs-keyword\">in<\/span> fields)\n        {\n            Console.WriteLine(<span class=\"hljs-string\">\"Field: \"<\/span> + field.Name);\n        }\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we use the <code>Type<\/code> object to get information about the class <code>SampleClass<\/code>. We can retrieve the name, namespace, base type, properties, methods, and fields of the class using reflection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Fields and Properties<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Reflection allows you to access fields and properties, including private ones, dynamically at runtime. To access a property or field, you can use the <code>PropertyInfo<\/code> or <code>FieldInfo<\/code> classes respectively. These classes provide methods to get or set the value of the property or field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n<span class=\"hljs-keyword\">using<\/span> System.Reflection;\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Person<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Name { <span class=\"hljs-keyword\">get<\/span>; <span class=\"hljs-keyword\">set<\/span>; }\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-keyword\">int<\/span> age;\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">Person<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> name, <span class=\"hljs-keyword\">int<\/span> age<\/span>)<\/span>\n    {\n        Name = name;\n        <span class=\"hljs-keyword\">this<\/span>.age = age;\n    }\n}\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        Person person = <span class=\"hljs-keyword\">new<\/span> Person(<span class=\"hljs-string\">\"Alice\"<\/span>, <span class=\"hljs-number\">30<\/span>);\n        Type type = person.GetType();\n\n        <span class=\"hljs-comment\">\/\/ Access public property<\/span>\n        PropertyInfo property = type.GetProperty(<span class=\"hljs-string\">\"Name\"<\/span>);\n        Console.WriteLine(<span class=\"hljs-string\">\"Property Name: \"<\/span> + property.GetValue(person));\n\n        <span class=\"hljs-comment\">\/\/ Access private field<\/span>\n        FieldInfo field = type.GetField(<span class=\"hljs-string\">\"age\"<\/span>, BindingFlags.NonPublic | BindingFlags.Instance);\n        Console.WriteLine(<span class=\"hljs-string\">\"Field Age: \"<\/span> + field.GetValue(person));\n\n        <span class=\"hljs-comment\">\/\/ Set new values using reflection<\/span>\n        property.SetValue(person, <span class=\"hljs-string\">\"Bob\"<\/span>);\n        field.SetValue(person, <span class=\"hljs-number\">40<\/span>);\n\n        Console.WriteLine(<span class=\"hljs-string\">\"Updated Name: \"<\/span> + person.Name);\n        Console.WriteLine(<span class=\"hljs-string\">\"Updated Age (via reflection): \"<\/span> + field.GetValue(person));\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In the above example, we use reflection to inspect and manipulate both public and private members of the <code>Person<\/code> class. Notice how the <code>BindingFlags.NonPublic<\/code> and <code>BindingFlags.Instance<\/code> flags are used to access the private field <code>age<\/code>. Reflection provides access to private members, which can be useful for testing or debugging, though this should be used cautiously.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Invoking Methods Dynamically<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">One of the most powerful features of reflection is the ability to invoke methods dynamically at runtime. This is especially useful when working with types that are not known until runtime, such as in plugin systems or serialization frameworks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can invoke a method using the <code>MethodInfo<\/code> class and its <code>Invoke<\/code> method. Here&#8217;s an example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n<span class=\"hljs-keyword\">using<\/span> System.Reflection;\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Calculator<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> <span class=\"hljs-title\">Add<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">int<\/span> x, <span class=\"hljs-keyword\">int<\/span> y<\/span>)<\/span>\n    {\n        <span class=\"hljs-keyword\">return<\/span> x + y;\n    }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-keyword\">int<\/span> <span class=\"hljs-title\">Subtract<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">int<\/span> x, <span class=\"hljs-keyword\">int<\/span> y<\/span>)<\/span>\n    {\n        <span class=\"hljs-keyword\">return<\/span> x - y;\n    }\n}\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        Calculator calculator = <span class=\"hljs-keyword\">new<\/span> Calculator();\n        Type type = <span class=\"hljs-keyword\">typeof<\/span>(Calculator);\n\n        <span class=\"hljs-comment\">\/\/ Invoke public method<\/span>\n        MethodInfo addMethod = type.GetMethod(<span class=\"hljs-string\">\"Add\"<\/span>);\n        <span class=\"hljs-keyword\">object<\/span> result = addMethod.Invoke(calculator, <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">object<\/span>&#91;] { <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-number\">10<\/span> });\n        Console.WriteLine(<span class=\"hljs-string\">\"Result of Add: \"<\/span> + result);\n\n        <span class=\"hljs-comment\">\/\/ Invoke private method<\/span>\n        MethodInfo subtractMethod = type.GetMethod(<span class=\"hljs-string\">\"Subtract\"<\/span>, BindingFlags.NonPublic | BindingFlags.Instance);\n        <span class=\"hljs-keyword\">object<\/span> subtractResult = subtractMethod.Invoke(calculator, <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">object<\/span>&#91;] { <span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">5<\/span> });\n        Console.WriteLine(<span class=\"hljs-string\">\"Result of Subtract: \"<\/span> + subtractResult);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we dynamically invoke the <code>Add<\/code> and <code>Subtract<\/code> methods on the <code>Calculator<\/code> class. Note that <code>Subtract<\/code> is a private method, and we use <code>BindingFlags.NonPublic<\/code> to access it. By using `<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MethodInfo.Invoke()`, you can invoke methods dynamically without needing to know the exact method signatures at compile time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Working with Constructors<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Just like methods, constructors can also be invoked dynamically using reflection. The <code>ConstructorInfo<\/code> class provides access to constructors, and you can use its <code>Invoke()<\/code> method to create new instances of a type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s an example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n<span class=\"hljs-keyword\">using<\/span> System.Reflection;\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Person<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Name { <span class=\"hljs-keyword\">get<\/span>; }\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">int<\/span> Age { <span class=\"hljs-keyword\">get<\/span>; }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">Person<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> name, <span class=\"hljs-keyword\">int<\/span> age<\/span>)<\/span>\n    {\n        Name = name;\n        Age = age;\n    }\n}\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        Type type = <span class=\"hljs-keyword\">typeof<\/span>(Person);\n\n        <span class=\"hljs-comment\">\/\/ Get the constructor<\/span>\n        ConstructorInfo constructor = type.GetConstructor(<span class=\"hljs-keyword\">new<\/span> Type&#91;] { <span class=\"hljs-keyword\">typeof<\/span>(<span class=\"hljs-keyword\">string<\/span>), <span class=\"hljs-keyword\">typeof<\/span>(<span class=\"hljs-keyword\">int<\/span>) });\n\n        <span class=\"hljs-comment\">\/\/ Create an instance dynamically<\/span>\n        <span class=\"hljs-keyword\">object<\/span> personInstance = constructor.Invoke(<span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">object<\/span>&#91;] { <span class=\"hljs-string\">\"John\"<\/span>, <span class=\"hljs-number\">25<\/span> });\n\n        <span class=\"hljs-comment\">\/\/ Display the instance information<\/span>\n        PropertyInfo nameProperty = type.GetProperty(<span class=\"hljs-string\">\"Name\"<\/span>);\n        PropertyInfo ageProperty = type.GetProperty(<span class=\"hljs-string\">\"Age\"<\/span>);\n\n        Console.WriteLine(<span class=\"hljs-string\">\"Name: \"<\/span> + nameProperty.GetValue(personInstance));\n        Console.WriteLine(<span class=\"hljs-string\">\"Age: \"<\/span> + ageProperty.GetValue(personInstance));\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we use reflection to create an instance of the <code>Person<\/code> class by dynamically invoking its constructor. This is useful when you don\u2019t know the exact class or its constructor parameters at compile time but need to instantiate the class at runtime.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exploring Attributes with Reflection<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Attributes in C# are a way to add metadata to your classes, methods, properties, and other elements of your code. Using reflection, you can inspect these attributes at runtime. This is particularly useful when working with custom attributes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consider this example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n\n&#91;<span class=\"hljs-meta\">AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)<\/span>]\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">CustomAttribute<\/span> : <span class=\"hljs-title\">Attribute<\/span>\n{\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">string<\/span> Description { <span class=\"hljs-keyword\">get<\/span>; }\n\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-title\">CustomAttribute<\/span>(<span class=\"hljs-params\"><span class=\"hljs-keyword\">string<\/span> description<\/span>)<\/span>\n    {\n        Description = description;\n    }\n}\n\n&#91;<span class=\"hljs-meta\">Custom(<span class=\"hljs-meta-string\">\"This is a sample class\"<\/span>)<\/span>]\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SampleClass<\/span>\n{\n    &#91;<span class=\"hljs-meta\">Custom(<span class=\"hljs-meta-string\">\"This is a sample method\"<\/span>)<\/span>]\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">SampleMethod<\/span>(<span class=\"hljs-params\"><\/span>)<\/span> { }\n}\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        Type type = <span class=\"hljs-keyword\">typeof<\/span>(SampleClass);\n\n        <span class=\"hljs-comment\">\/\/ Check if the class has the custom attribute<\/span>\n        <span class=\"hljs-keyword\">if<\/span> (Attribute.IsDefined(type, <span class=\"hljs-keyword\">typeof<\/span>(CustomAttribute)))\n        {\n            CustomAttribute attr = (CustomAttribute)Attribute.GetCustomAttribute(type, <span class=\"hljs-keyword\">typeof<\/span>(CustomAttribute));\n            Console.WriteLine(<span class=\"hljs-string\">\"Class Attribute: \"<\/span> + attr.Description);\n        }\n\n        <span class=\"hljs-comment\">\/\/ Check if the method has the custom attribute<\/span>\n        MethodInfo method = type.GetMethod(<span class=\"hljs-string\">\"SampleMethod\"<\/span>);\n        <span class=\"hljs-keyword\">if<\/span> (Attribute.IsDefined(method, <span class=\"hljs-keyword\">typeof<\/span>(CustomAttribute)))\n        {\n            CustomAttribute attr = (CustomAttribute)Attribute.GetCustomAttribute(method, <span class=\"hljs-keyword\">typeof<\/span>(CustomAttribute));\n            Console.WriteLine(<span class=\"hljs-string\">\"Method Attribute: \"<\/span> + attr.Description);\n        }\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we define a custom attribute <code>CustomAttribute<\/code> and apply it to a class and a method. Using reflection, we can inspect whether the class and method have the attribute applied and retrieve its description at runtime.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dynamic Assembly Loading<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In advanced scenarios, you might need to load assemblies dynamically at runtime, especially in plugin architectures or systems that support extensions. The <code>System.Reflection.Assembly<\/code> class allows you to load an assembly by its name or path and inspect its types and members.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s how to dynamically load an assembly and inspect its types:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"C#\" data-shcb-language-slug=\"cs\"><span><code class=\"hljs language-cs\"><span class=\"hljs-keyword\">using<\/span> System;\n<span class=\"hljs-keyword\">using<\/span> System.Reflection;\n\n<span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Program<\/span>\n{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">Main<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>\n    {\n        <span class=\"hljs-comment\">\/\/ Load an assembly by its name<\/span>\n        Assembly assembly = Assembly.Load(<span class=\"hljs-string\">\"mscorlib\"<\/span>);\n\n        <span class=\"hljs-comment\">\/\/ Get types in the assembly<\/span>\n        Type&#91;] types = assembly.GetTypes();\n        <span class=\"hljs-keyword\">foreach<\/span> (<span class=\"hljs-keyword\">var<\/span> type <span class=\"hljs-keyword\">in<\/span> types)\n        {\n            Console.WriteLine(<span class=\"hljs-string\">\"Type: \"<\/span> + type.FullName);\n        }\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">C#<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">cs<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we load the <code>mscorlib<\/code> assembly (which contains core .NET classes like <code>System.String<\/code>, <code>System.Int32<\/code>, etc.) and list all the types defined within it. This is useful when you need to explore types from external assemblies at runtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Reflection is a powerful tool in C# that allows you to inspect and manipulate types, properties, methods, fields, and attributes at runtime. Whether you&#8217;re working with dynamic object creation, building extensible frameworks, or inspecting metadata for testing and debugging, reflection opens up new possibilities in your application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That said, reflection comes with performance costs and can expose private members, which might undermine encapsulation and security. Therefore, it&#8217;s best used judiciously and in scenarios where the flexibility it provides is truly necessary. For everyday programming, relying on static type information and traditional object-oriented principles is usually more efficient and safer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, we covered the basics of reflection, including how to inspect types, access members, invoke methods, create instances, and work with attributes. By applying these concepts, you can leverage the full power of reflection in your C# applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata about objects, classes, and other entities in your code without having to know them at compile time. While reflection can be useful for a variety of purposes\u2014from dynamic object creation to testing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8,4],"tags":[],"class_list":["post-2193","post","type-post","status-publish","format-standard","category-csharp","category-programming-languages","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Use Reflection to Inspect Types at Runtime in C#<\/title>\n<meta name=\"description\" content=\"In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use Reflection to Inspect Types at Runtime in C#\" \/>\n<meta property=\"og:description\" content=\"In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-18T10:34:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-18T10:35:14+00:00\" \/>\n<meta name=\"author\" content=\"w3compadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"w3compadmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/\"},\"author\":{\"name\":\"w3compadmin\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"headline\":\"How to Use Reflection to Inspect Types at Runtime in C#\",\"datePublished\":\"2024-10-18T10:34:10+00:00\",\"dateModified\":\"2024-10-18T10:35:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/\"},\"wordCount\":1338,\"articleSection\":[\"C#\",\"Programming Languages\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/\",\"name\":\"How to Use Reflection to Inspect Types at Runtime in C#\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\"},\"datePublished\":\"2024-10-18T10:34:10+00:00\",\"dateModified\":\"2024-10-18T10:35:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"description\":\"In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Articles Home\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming Languages\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/programming-languages\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Use Reflection to Inspect Types at Runtime in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\",\"name\":\"Developer Articles Hub\",\"description\":\"\",\"alternateName\":\"Developer Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\",\"name\":\"w3compadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"contentUrl\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266\",\"caption\":\"w3compadmin\"},\"sameAs\":[\"http:\\\/\\\/w3computing.com\\\/articles\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use Reflection to Inspect Types at Runtime in C#","description":"In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/","og_locale":"en_US","og_type":"article","og_title":"How to Use Reflection to Inspect Types at Runtime in C#","og_description":"In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata","og_url":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/","article_published_time":"2024-10-18T10:34:10+00:00","article_modified_time":"2024-10-18T10:35:14+00:00","author":"w3compadmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"w3compadmin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/#article","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/"},"author":{"name":"w3compadmin","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"headline":"How to Use Reflection to Inspect Types at Runtime in C#","datePublished":"2024-10-18T10:34:10+00:00","dateModified":"2024-10-18T10:35:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/"},"wordCount":1338,"articleSection":["C#","Programming Languages"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/","url":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/","name":"How to Use Reflection to Inspect Types at Runtime in C#","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/#website"},"datePublished":"2024-10-18T10:34:10+00:00","dateModified":"2024-10-18T10:35:14+00:00","author":{"@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"description":"In C#, reflection is a powerful feature that allows you to inspect and manipulate types at runtime. It enables you to explore metadata","breadcrumb":{"@id":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.w3computing.com\/articles\/how-to-use-reflection-to-inspect-types-at-runtime-in-csharp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Articles Home","item":"https:\/\/www.w3computing.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Programming Languages","item":"https:\/\/www.w3computing.com\/articles\/programming-languages\/"},{"@type":"ListItem","position":3,"name":"How to Use Reflection to Inspect Types at Runtime in C#"}]},{"@type":"WebSite","@id":"https:\/\/www.w3computing.com\/articles\/#website","url":"https:\/\/www.w3computing.com\/articles\/","name":"Developer Articles Hub","description":"","alternateName":"Developer Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.w3computing.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561","name":"w3compadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","url":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","contentUrl":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1780141266","caption":"w3compadmin"},"sameAs":["http:\/\/w3computing.com\/articles"]}]}},"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"w3compadmin","author_link":"https:\/\/www.w3computing.com\/articles\/author\/w3compadmin\/"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/2193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/comments?post=2193"}],"version-history":[{"count":3,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/2193\/revisions"}],"predecessor-version":[{"id":2196,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/2193\/revisions\/2196"}],"wp:attachment":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/media?parent=2193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/categories?post=2193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/tags?post=2193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}