{"id":28271,"date":"2019-09-18T00:00:00","date_gmt":"2019-09-17T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/migliora-il-tuo-codice-con-la-reflection\/"},"modified":"2021-05-20T18:53:07","modified_gmt":"2021-05-20T16:53:07","slug":"improve-you-code-with-reflection","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/","title":{"rendered":"Improve you code with Reflection"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"28266\" data-permalink=\"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/attachment\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"f7b025a6-cd86-4360-afdc-4a63c29a3ad6\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-28266\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Reflection is a .NET framework functionality that allows us to inspect and manipulate the Metadata and the code compiled in a .NET assembly at runtime. It is a very powerful feature, but, as all the instruments at our disposal, we should understand how it works to use it properly<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assemblies provide essential information to recognize Types&nbsp;implementations to the Common Language Runtime. An assembly can be considered as a collection of types and resources, forming a logical unit of functionality, created to interact. They consist of one or more independent units, called Modules. Information important to us are contained in the main module, and they are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Assembly Manifest, that contains in turn the assembly name, the version and a catalog&nbsp;of all modules contained in it.<\/li><li>Metadata, that contain a complete description of all displayed types, included methods, fields, parameters and constructors, any reference to external assemblies and the IL (Intermediate Language), which has been compiled from the source code and is the actual executable part of the assembly.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">An assembly, compiled in IL (Intermediate Language), is compiled in machine language by the JIT compiler (Just in Time Compiler), also called&nbsp;<strong>JITter<\/strong>. The native code is produced when required, that\u2019s to say, for example, the first time a method is invoked, it will be compiled and saved. It will be available in the cache for next calls and then we save the compiling time. When not used, assemblies would not be loaded. This means that they represent an effective manner to manage resources in big projects. The benefit of&nbsp;<strong>JIT compilation<\/strong>&nbsp;is that it could be done dynamically, in order to take advantage of&nbsp;the underlying system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using Metadata we can dynamically create instances of Types, we can invoke methods, obtain and set properties and fields values or inspection attributes.<br>C# provides us classes and methods to execute these and much else, using the so-called Reflection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Classes that much interest us for the use of Reflection are three:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Type Class<\/em><br>The class type is an abstract class, that would be used to access to Metadata through the Reflection classes. Using a&nbsp;<strong>Type<\/strong>&nbsp;object, it is possible to obtain information related to a class such as constructors, methods, fields, properties and events.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Activator Class<\/em><br>This class contains methods used to dynamically create an instance of a Type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Assembly Class<\/em><br>This abstract class allows us to load, manipulate and obtain information on an assembly and to identify all Types contained in it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s look at a practical example, using the Reflection and personalized attributes to map objects&#8217; properties.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Although Entity Framework and the namespace&nbsp;<em>System.ComponentModel.DataAnnotations<\/em>&nbsp;already provide us with tools to make it, we may need to build our level or our tool to access data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can implement our version of these data annotations as Personalized Attributes. To create a personalized attribute in C#, we simply create a class, that inherits from&nbsp;<em>System.Attribute<\/em>. For example, if we want to implement our attribute [<strong>PrimaryKey<\/strong>] to indicate that a specific property on a class of our application represents the primary key of our database, we can create the following personalized attribute:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class PrimaryKeyAttribute : Attribute { }\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Attributes can even transmit information&nbsp;if needed. Let\u2019s consider a way to map a property on a specific database column name.<br>Then we create a class, that inherits from&nbsp;<em>System.Attribute<\/em>, but this time we will add a property and a constructor<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class DbColumnAttribute : Attribute\n{\n\u00a0\u00a0\u00a0\u00a0public string Name { get; set; }\n\u00a0\u00a0\u00a0\u00a0public DbColumnAttribute(string name)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0this.Name = name;\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now suppose we inherit a database that should be integrated with our existing code. In the table containing all information about the client, the&nbsp;names of columns are lowercase and separated by an underscore, to better understand the context. Shown below, the SQL code of the creation on the mentioned table:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nCREATE TABLE Users (\n\u00a0\u00a0\u00a0\u00a0id_user int IDENTITY(1,1) PRIMARY KEY NOT NULL,\n\u00a0\u00a0\u00a0\u00a0first_name varchar(50) NOT NULL,\n\u00a0\u00a0\u00a0\u00a0last_name varchar(50) NOT NULL,\n\u00a0\u00a0\u00a0\u00a0email varchar(50) NOT NULL\n);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">And this is how our User class will appear with column name attributes:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class User\n{\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0&#x5B;PrimaryKey]\n\u00a0\u00a0\u00a0\u00a0&#x5B;DbColumn(&quot;id_user&quot;)]\n\u00a0\u00a0\u00a0\u00a0public int UserId { get; set; }\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;DbColumn(&quot;first_name&quot;)]\n\u00a0\u00a0\u00a0\u00a0public string Name { get; set; }\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;DbColumn(&quot;last_name&quot;)]\n\u00a0\u00a0\u00a0\u00a0public string Surname { get; set; }\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0&#x5B;DbColumn(&quot;email&quot;)]\n\u00a0\u00a0\u00a0\u00a0public string Email { get; set; }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We can now write a method that allows us to map properties of our class on the specific column name of the database, using Reflection:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nstatic void DbColumnsMappingMethod&lt;T&gt; (T obj) where T : new()\n{\n\u00a0\u00a0\u00a0\u00a0\/\/ Get the istance&#039;s Type object\n\u00a0\u00a0\u00a0\u00a0Type type = obj.GetType();\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/ Get a list of the public properties of the Type object as PropertyInfo objects\n\u00a0\u00a0\u00a0\u00a0PropertyInfo&#x5B;] objectPropertiesList = type.GetProperties();\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Search properties for the object: {0}&quot;, type.Name);\n\u00a0\u00a0\u00a0\u00a0foreach (var objectProperty in objectPropertiesList)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Get custom attributes of object&#039;s properties\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var customAttributes = objectProperty.GetCustomAttributes(false);\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0string message = &quot;The property {0} will be mapped with the database column {1}&quot;;\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Mapping custom attributes with DB columns\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var mappedColumn = customAttributes\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.FirstOrDefault(a =&gt; a.GetType() == typeof(DbColumnAttribute));\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (mappedColumn != null)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0DbColumnAttribute dbColumn = mappedColumn as DbColumnAttribute;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(message, objectProperty.Name, dbColumn.Name);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">We can even write a method that analyzes properties and attributes of an object and search for its primary key, using reflection:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nstatic void PrimaryKeySearchMethod&lt;T&gt; (T obj) where T : new()\n{\n\u00a0\u00a0\u00a0\u00a0\/\/ Get the istance&#039;s Type object\n\u00a0\u00a0\u00a0\u00a0Type type = obj.GetType();\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/ Get a list of the public properties of the Type object as PropertyInfo objects\n\u00a0\u00a0\u00a0\u00a0PropertyInfo&#x5B;] objectPropertiesList = type.GetProperties();\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Search Primary Key for the object: {0}&quot;, type.Name);\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0\/\/ Primary Key search\n\u00a0\u00a0\u00a0\u00a0var primaryKey = objectPropertiesList\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.FirstOrDefault(p =&gt; p.GetCustomAttributes(false)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.Any(a =&gt; a.GetType() == typeof(PrimaryKeyAttribute)));\n\u00a0\u00a0\n\u00a0\u00a0\u00a0\u00a0if (primaryKey != null)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0string message = &quot;The Primary Key for {0} class is the property: {1}&quot;;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(message, type.Name, primaryKey.Name);\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">In the code above, we pass to the method a generic object of T type, which means that this method can be used with any domain object, to verify the existence of an attribute. [<strong>PrimaryKey<\/strong>].<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First of all, we can use the method&nbsp;<em>GetType()&nbsp;<\/em>to find information about the object&nbsp;<strong>Type<\/strong>, then we call the method&nbsp;<em>GetProperties()&nbsp;<\/em>of the&nbsp;<strong>Type<\/strong>&nbsp;instance, which returns an array of&nbsp;<strong>PropertyInfo<\/strong>&nbsp;objects.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Successively, we execute the iteration using LINQ on every&nbsp;<strong>PropertyInfo<\/strong>&nbsp;instances and we call the method&nbsp;<em>GetCustomAttributes()<\/em>, which returns an object matrix, that represents&nbsp;<em>CustomAttributes<\/em>&nbsp;found on that property. We can now check the type of every&nbsp;<em>CustomAttributes<\/em>&nbsp;object and, if it is of&nbsp;<strong>PrimaryKeyAttribute<\/strong>&nbsp;type, we know that we have found a property that represents a primary key in our database.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We should specify that the use of Reflection may cause a worse performing of our code, but thanks to the power of today&#8217;s processors, this problem would be noted only when the code is used repeatedly in a great application context. We can weaken this problem with the use of abstractions instead of concrete Types, a best practice that usually results in the use of an interface instead of a concrete class. Using an interface, we can find that most of our code interacts with the abstraction, instead of with the dynamically created Type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If needed, we can dynamically load an assembly only when the application starts; then dynamically load Types contained in it, verifying they have been loaded only once: as a Type has been obtained, we can use it using an interface that our application will use to make all calls to methods: in this way, there will be no dynamic calls through&nbsp;<strong>MethodInfo<\/strong>&nbsp;and the&nbsp;<em>Invoke<\/em>&nbsp;method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This simple strategy example will help us to minimize the decline in performance and, since interfaces only have public members, we avoid interacting with private members of the class. The result would be that we will delimit the use of Reflection only to those parts of the application we need it, maximizing PERFORMANCES and keeping the FLEXIBILITY we need.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See you next!<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Add functionality to your C# code by inspecting it with Reflection<\/p>\n","protected":false},"author":196716244,"featured_media":28266,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637384],"class_list":["post-28271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-c-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Improve you code with Reflection - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Improve you code with Reflection - Blexin\" \/>\n<meta property=\"og:description\" content=\"Add functionality to your C# code by inspecting it with Reflection\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2019-09-17T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-20T16:53:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i2.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Francesco Vastarella\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Francesco Vastarella\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/\"},\"author\":{\"name\":\"Francesco Vastarella\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\"},\"headline\":\"Improve you code with Reflection\",\"datePublished\":\"2019-09-17T22:00:00+00:00\",\"dateModified\":\"2021-05-20T16:53:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/\"},\"wordCount\":1072,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"C#\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/\",\"name\":\"Improve you code with Reflection - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2019-09-17T22:00:00+00:00\",\"dateModified\":\"2021-05-20T16:53:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/improve-you-code-with-reflection\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Improve you code with Reflection\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/388dae0ca9df603c88b5e41e29cf2d4d\",\"name\":\"Francesco Vastarella\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g\",\"caption\":\"Francesco Vastarella\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/francesco-vastarellablexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Improve you code with Reflection - Blexin","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:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/","og_locale":"en_US","og_type":"article","og_title":"Improve you code with Reflection - Blexin","og_description":"Add functionality to your C# code by inspecting it with Reflection","og_url":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/","og_site_name":"Blexin","article_published_time":"2019-09-17T22:00:00+00:00","article_modified_time":"2021-05-20T16:53:07+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i2.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Francesco Vastarella","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Francesco Vastarella","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/"},"author":{"name":"Francesco Vastarella","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d"},"headline":"Improve you code with Reflection","datePublished":"2019-09-17T22:00:00+00:00","dateModified":"2021-05-20T16:53:07+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/"},"wordCount":1072,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1","keywords":["C#"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/","url":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/","name":"Improve you code with Reflection - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1","datePublished":"2019-09-17T22:00:00+00:00","dateModified":"2021-05-20T16:53:07+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/improve-you-code-with-reflection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"Improve you code with Reflection"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/388dae0ca9df603c88b5e41e29cf2d4d","name":"Francesco Vastarella","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3b8deedae8f35372d5fba49f918006fb0a58a2943aff6ae52d3ff188e0c441bb?s=96&d=identicon&r=g","caption":"Francesco Vastarella"},"url":"https:\/\/blexin.com\/en\/author\/francesco-vastarellablexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/f7b025a6-cd86-4360-afdc-4a63c29a3ad6.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-7lZ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716244"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=28271"}],"version-history":[{"count":6,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28271\/revisions"}],"predecessor-version":[{"id":31972,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28271\/revisions\/31972"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/28266"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=28271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=28271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=28271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}