{"id":701,"date":"2013-08-06T13:39:09","date_gmt":"2013-08-06T13:39:09","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=701"},"modified":"2013-08-06T15:37:43","modified_gmt":"2013-08-06T15:37:43","slug":"friend-assemblies-or-how-to-make-internals-visible-to-other-assemblies","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/friend-assemblies-or-how-to-make-internals-visible-to-other-assemblies\/","title":{"rendered":"Friend assemblies (or how to make internals visible to other assemblies)"},"content":{"rendered":"<p>As you know, the <strong>internal<\/strong> modifier denotes that types and type members are only accessible by code from the same assembly.<\/p>\n<p>Therefore the DoSomething method in the following is not visible to other assemblies but can be using by code within the assembly which contains this type<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic class MyClass\r\n{\r\n   internal int DoSomething()\r\n   {\r\n   }\r\n}\r\n<\/pre>\n<p>In some cases it&#8217;s useful to have internal types or type members visible to other assemblies, but limited to only those assemblies. These assemblies are known as <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/0tke9fxk.aspx\" title=\"Friend Assemblies\" target=\"_blank\">friend assemblies<\/a>.<\/p>\n<p>To denote the friend assemblies we add the InternalsVisibleTo attribute to the assembly who hosts the internals and specify the friend assembly in the following manner<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;assembly: InternalsVisibleTo(&quot;FriendAssembly&quot;)]\r\n<\/pre>\n<p>Now the FriendAssembly can access the DoSomething method on type MyClass.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you know, the internal modifier denotes that types and type members are only accessible by code from the same assembly. Therefore the DoSomething method in the following is not visible to other assemblies but can be using by code within the assembly which contains this type public class MyClass { internal int DoSomething() { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-701","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=701"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":703,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/701\/revisions\/703"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}