tag:blogger.com,1999:blog-5707533511952913639.post3877227831091684489..comments2024-01-01T23:29:01.200-05:00Comments on Code Crafter: C# Mixins With StateJordãohttp://www.blogger.com/profile/07178574753933019008noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-5707533511952913639.post-71835023373142263872018-11-17T23:55:16.772-05:002018-11-17T23:55:16.772-05:00I hate the getXXX/setXXX pattern, my solution:
...I hate the getXXX/setXXX pattern, my solution:<br /><br /> public interface ISomeMixin<br /> {<br /> public string Name {get; set;}<br /> }<br /><br /> public static class SomeExtensions<br /> {<br /> public static ISomeMixin AsSomeMixin(this object @this)<br /> => Extensions.Extend(@this, () => AsSomeMixin, () => new Classes.SomeMixin);<br /><br /LuisLAPhttps://www.blogger.com/profile/01914225649773478326noreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-75537699276046367442018-11-17T23:40:44.389-05:002018-11-17T23:40:44.389-05:00But vs can't show intellisense with dynamic ob...But vs can't show intellisense with dynamic objects.LuisLAPhttps://www.blogger.com/profile/01914225649773478326noreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-8940080751894260122017-04-18T05:00:07.251-04:002017-04-18T05:00:07.251-04:00You could reduce all of this code to:
public ...You could reduce all of this code to:<br /><br /> public static class ObjectExtensions<br /> {<br /> private static ConditionalWeakTable extendedData = new ConditionalWeakTable();<br /> public static dynamic DynamicProperties(this object obj) => extendedData.GetValue(obj, _ => new ExpandoObject());<br /> }Anonymoushttps://www.blogger.com/profile/07212872198932453453noreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-40440948159606987722013-08-16T11:05:51.463-04:002013-08-16T11:05:51.463-04:00Can Anonymous update his example with the <>...Can Anonymous update his example with the <> tags back? Pretty please?Harleyhttps://www.blogger.com/profile/09901057646358870133noreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-61516666975581693262013-07-18T12:58:48.462-04:002013-07-18T12:58:48.462-04:00Interesting idea! Thanks for sharing.Interesting idea! Thanks for sharing.Jordãohttps://www.blogger.com/profile/07178574753933019008noreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-65453185735118542062013-07-17T15:29:08.617-04:002013-07-17T15:29:08.617-04:00It broke my code and stripped the <> tags.It broke my code and stripped the <> tags.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-13227659434840070562013-07-17T15:26:55.474-04:002013-07-17T15:26:55.474-04:00For a slightly more eloquent approach, you can uti...For a slightly more eloquent approach, you can utilize the generic type system to your advantage.<br />Since there is no real benefit to define TKey as a specific type for ConditionalWeakTable,<br />and under the covers it gets treated like an object reference type anyhow. We can use "object" as the key.<br /><br />The only benefits for a type parameter are to prevent attempts to use Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5707533511952913639.post-63166876156134767482013-03-29T18:26:48.497-04:002013-03-29T18:26:48.497-04:00Amazing. Thanks for sharing!Amazing. Thanks for sharing!Anonymoushttps://www.blogger.com/profile/06792561427703080446noreply@blogger.com