<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Delegates on InternetException</title><link>https://internetexception.com/tags/delegates/</link><description>Recent content in Delegates on InternetException</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 28 Oct 2025 21:14:55 +0100</lastBuildDate><atom:link href="https://internetexception.com/tags/delegates/index.xml" rel="self" type="application/rss+xml"/><item><title>HLinq design</title><link>https://internetexception.com/2025/10/28/hlinq-design/</link><pubDate>Tue, 28 Oct 2025 21:14:55 +0100</pubDate><guid>https://internetexception.com/2025/10/28/hlinq-design/</guid><description>&lt;h2 id="a-bit-of-history"&gt;A bit of history&lt;/h2&gt;&#10;&lt;p&gt;I remember the day when I started writing the HLinq query language. It was weekend and I was experimenting with writing Single endpoints for &lt;a href="https://internetexception.com/2013/02/07/why-i-dont-like-python-anymore/" data-type="post" data-id="228"&gt;Hamster Wheel.&lt;/a&gt; Single endpoints were almost done and next step was to write List endpoint. This would allow to get list of records of specific type. After I got single GET returns correct data for chosen record id, list should not be hard to implement. Then just create, update and delete. Basic CRUD API in Hamster Wheel would be finished. I was thrilled that I actually was able to do such thing.&lt;/p&gt;</description></item><item><title>Middleware in OWIN</title><link>https://internetexception.com/2022/10/25/middleware-in-owin/</link><pubDate>Tue, 25 Oct 2022 15:40:45 +0200</pubDate><guid>https://internetexception.com/2022/10/25/middleware-in-owin/</guid><description>&lt;p&gt;There are 2 ways of writing OWIN middleware in ASP.NET Core.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Pure OWIN - usefull if you want to integrate with OWIN compatible module but not written in C#&lt;/li&gt;&#10;&lt;li&gt;ASP.NET Core OWIN middleware&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="aspnet-core-middleware"&gt;ASP.NET Core Middleware:&lt;/h2&gt;&#10;&lt;p&gt;This type of middleware can be:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;delegate of &lt;code&gt;Func&amp;lt;HttpContext, Func&amp;lt;&lt;/code&gt;Task&amp;gt;&lt;code&gt;, Task&amp;gt;&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;class with &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.imiddleware?view=aspnetcore-7.0" data-type="URL" data-id="https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.imiddleware?view=aspnetcore-7.0"&gt;&lt;code&gt;IMiddleware&lt;/code&gt;&lt;/a&gt; imlementation&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;{&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;// Do work that can write to the Response.&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="c1"&gt;// Do logging or other work that doesn&amp;#39;t write to the Response.&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="p"&gt;});&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="pure-owin-middleware"&gt;Pure OWIN Middleware:&lt;/h2&gt;&#10;&lt;p&gt;This rather would be used to integrate with OWIN middlewares written in different language, so that ASP.NET Core implementation directly is not possible.&lt;/p&gt;</description></item><item><title>Covariance and Contravariance</title><link>https://internetexception.com/2022/10/19/covariance-and-contravariance/</link><pubDate>Wed, 19 Oct 2022 16:21:04 +0200</pubDate><guid>https://internetexception.com/2022/10/19/covariance-and-contravariance/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;enables implicit reference conversions for&#10;&lt;ul&gt;&#10;&lt;li&gt;arrays&lt;/li&gt;&#10;&lt;li&gt;delegates&lt;/li&gt;&#10;&lt;li&gt;generic type arguments&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Covariance&lt;/strong&gt; preserves assignment compatibility&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Contravariance&lt;/strong&gt; reverses assignment compatibility&lt;/li&gt;&#10;&lt;li&gt;allows for matching signatures of delegates and method groups&#10;&lt;ul&gt;&#10;&lt;li&gt;to assign to delegates from method that returns more derived types - &lt;strong&gt;covariance&lt;/strong&gt;&lt;/li&gt;&#10;&lt;li&gt;to assign to delegates from method that returns less derived types - &lt;strong&gt;contravariance&lt;/strong&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Covariance&lt;/strong&gt; and &lt;strong&gt;Contravariance&lt;/strong&gt; are supported in &lt;strong&gt;Generics&lt;/strong&gt; for implicit conversions for type parameters&#10;&lt;ul&gt;&#10;&lt;li&gt;allows method to have more derived return type than defined by generic type parameter of the interface&lt;/li&gt;&#10;&lt;li&gt;this allows implicit conversions from one generic interface to another (from &lt;code&gt;IEnumerable&amp;lt;string&amp;gt;&lt;/code&gt; to &lt;code&gt;IEnumerable&amp;lt;object&amp;gt;&lt;/code&gt; even if first does not inherits from second)&lt;/li&gt;&#10;&lt;li&gt;allows generic types to have less derived argument types than specified by the generic parameter of the interface (implementation of &lt;code&gt;IEqualityComparer&amp;lt;BaseClass&amp;gt;&lt;/code&gt; can be implicitly converted to &lt;code&gt;IEqualityComparer&amp;lt;DerivedClass&amp;gt;&lt;/code&gt; because &lt;code&gt;IEqualityComparer.Equals&lt;/code&gt; is contravariant)&lt;/li&gt;&#10;&lt;li&gt;implicit conversions works for interfaces but not classes that implement from those interfaces (i.e. this won&amp;rsquo;t work &lt;code&gt;List&amp;lt;Object&amp;gt; list = new List&amp;lt;String&amp;gt;()&lt;/code&gt;)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;em&gt;Assignment compatibility&lt;/em&gt; is when object of a more derived type is assigned to an object of a less derived type.&lt;/p&gt;</description></item><item><title>Dynamic runtime delegates conversion</title><link>https://internetexception.com/2017/05/07/dynamic-runtime-delegates-conversion/</link><pubDate>Sun, 07 May 2017 11:53:00 +0200</pubDate><guid>https://internetexception.com/2017/05/07/dynamic-runtime-delegates-conversion/</guid><description>&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;&#10;&lt;p&gt;Delegates can be converted easily to another type if you know types of those delegates. But if you do not know it is impossible without really complicated code.&lt;/p&gt;</description></item><item><title>Detecting software keyboard events in Xamarin Android</title><link>https://internetexception.com/2017/02/03/detecting-software-keyboard-events-in-xamarin-android/</link><pubDate>Fri, 03 Feb 2017 23:31:00 +0100</pubDate><guid>https://internetexception.com/2017/02/03/detecting-software-keyboard-events-in-xamarin-android/</guid><description>&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;&#10;&lt;p&gt;It is quite strange that you can&amp;rsquo;t easily detect if software keyboard is visible or not on Android. Because of that, it is also complicated thing to do in Xamarin.&lt;/p&gt;</description></item><item><title>Genereting proxies during runtime using Reflection.Emit</title><link>https://internetexception.com/2016/10/07/genereting-proxies-during-runtime-using-reflection-emit/</link><pubDate>Fri, 07 Oct 2016 12:29:00 +0200</pubDate><guid>https://internetexception.com/2016/10/07/genereting-proxies-during-runtime-using-reflection-emit/</guid><description>&lt;p&gt;&lt;em&gt;Reflection.Emit&lt;/em&gt; is very powerful tool. It creates IL code and since C# is converted into IL too, we have the same functionality as in C# and even more. It is very powerful and at the same time very complicated. Because of that it is worth to discuss how and for what it should be used. One idea is to create dynamic code with automatic implementations of interfaces - proxy types.&lt;/p&gt;</description></item><item><title>Faster than Reflection: Delegates. Part 3.</title><link>https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/</link><pubDate>Fri, 02 Sep 2016 13:15:00 +0200</pubDate><guid>https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/</guid><description>&lt;p&gt;&lt;strong&gt;This is third article in series, that explains how to create delegates for public and non-public members of public, non-public or not known in compile-time types. If you are not familiar with previous articles and looking for detailed explanation of how delegates works, how they are created and why, I strongly encourage you to read first two. If you are just looking for a way to create delegates for methods or constructors it is not necessary.&lt;/strong&gt; Code with new features and with bug fixes is available on &lt;a href="https://github.com/npodbielski/Delegates" target="_blank" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&#10; and as &lt;a href="https://www.nuget.org/packages/DelegatesFactory/1.0.0" target="_blank" rel="noopener noreferrer"&gt;Nuget&lt;/a&gt;&#10; package.&lt;/p&gt;</description></item><item><title>Faster than Reflection: Delegates. Part 2.</title><link>https://internetexception.com/2016/08/16/faster-than-reflection-delegates-part-2/</link><pubDate>Tue, 16 Aug 2016 12:59:00 +0200</pubDate><guid>https://internetexception.com/2016/08/16/faster-than-reflection-delegates-part-2/</guid><description>&lt;p&gt;&lt;strong&gt;This is second article in series, that explains how to create delegates for public and non-public members of public, non-public or not known in compile-time types. If you are not familiar with previous article and looking for detailed explanation of how delegates works, how they are created and why, I strongly encourage you to read it first. If you are just looking for a way to create delegates for methods or constructors it is not necessary.&lt;/strong&gt; Last article in series you can find &lt;a href="https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/" title="Third part"&gt;here&lt;/a&gt;&#10;. Code with new features and with bug fixes is available on &lt;a href="https://github.com/npodbielski/Delegates" target="_blank" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&#10; and as &lt;a href="https://www.nuget.org/packages/DelegatesFactory/1.0.0" target="_blank" rel="noopener noreferrer"&gt;Nuget&lt;/a&gt;&#10; package. In previous &lt;a href="https://internetexception.com/2016/08/05/faster-than-reflection-delegates-part-1/"&gt;article&lt;/a&gt;&#10; and first one in series, we covered:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Static&#10;&lt;ol&gt;&#10;&lt;li&gt;Properties&lt;/li&gt;&#10;&lt;li&gt;Fields&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Instance&#10;&lt;ol&gt;&#10;&lt;li&gt;Properties&lt;/li&gt;&#10;&lt;li&gt;Fields&lt;/li&gt;&#10;&lt;li&gt;Indexers&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;Now it is time to cover following members.&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Static&#10;&lt;ol&gt;&#10;&lt;li&gt;Methods&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;Instance&#10;&lt;ol&gt;&#10;&lt;li&gt;Methods&lt;/li&gt;&#10;&lt;li&gt;Constructors&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;/ol&gt;</description></item><item><title>Faster than Reflection: Delegates. Part 1.</title><link>https://internetexception.com/2016/08/05/faster-than-reflection-delegates-part-1/</link><pubDate>Fri, 05 Aug 2016 09:58:00 +0200</pubDate><guid>https://internetexception.com/2016/08/05/faster-than-reflection-delegates-part-1/</guid><description>&lt;p&gt;This article is first part of the series of three. Next ones you can find &lt;a href="https://internetexception.com/2016/08/16/faster-than-reflection-delegates-part-2/" title="Second part"&gt;here&lt;/a&gt;&#10; and &lt;a href="https://internetexception.com/2016/09/02/faster-than-reflection-delegates-part-3/" title="Third part"&gt;here&lt;/a&gt;&#10;. Code for all three articles, with new features and bug fixes is available on &lt;a href="https://github.com/npodbielski/Delegates" target="_blank" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&#10; and as &lt;a href="https://www.nuget.org/packages/DelegatesFactory/1.0.0" target="_blank" rel="noopener noreferrer"&gt;Nuget&lt;/a&gt;&#10; package.&lt;/p&gt;&#10;&lt;h3 id="why-not-reflection"&gt;Why not Reflection?&lt;/h3&gt;&#10;&lt;p&gt;If you working with .NET and C# (probably other languages too), at some point, you will have to write more advanced and generic code, that i.e. reads all properties of a type, searches for attributes, etc. Or maybe you want to call some private method or property? It is not that rare to use some internal mechanism of framework or library. Usually, the first solution involves Reflection. But the thing is: Reflection is slow. Of course, it is sufficient if you need to use Reflection rarely and it is not the main code of the application. If it is used more often at some point, you will probably try to optimize it. And now is the fun part: how to do it?&lt;/p&gt;</description></item><item><title>ViewFactory for Xamarin application</title><link>https://internetexception.com/2016/07/09/viewfactory-for-xamarin-application/</link><pubDate>Sat, 09 Jul 2016 12:37:00 +0200</pubDate><guid>https://internetexception.com/2016/07/09/viewfactory-for-xamarin-application/</guid><description>&lt;h2 id="first-things-first---why"&gt;First things first - Why?&lt;/h2&gt;&#10;&lt;p&gt;First of all I do not like how creating of views and navigation works in Xamarin. There is much boilerplate needed to just navigate from one page to another. Typically like in &lt;a href="https://developer.xamarin.com/guides/xamarin-forms/getting-started/introduction-to-xamarin-forms/#Navigation" target="_blank" rel="noopener noreferrer"&gt;Xamarin documentation&lt;/a&gt;&#10; we have to obtain &lt;code&gt;INavigation&lt;/code&gt; interface instance, create instance of a new page, create instance of view model and all dependencies it requires. When you page do not require view model things are real easy and Xamarin sample is just enough.&lt;/p&gt;</description></item></channel></rss>