extension-methods

Subscribe and immediately unsubscribe after first action

吃可爱长大的小学妹 提交于 2021-01-27 03:57:46
问题 I want to subscribe on an IObservable<T> and unsubscribe (dipose) the subscription right after receiving the first element of type T , i.e. I only want to call the action on the very first element I get after subscribing. This is the approach I came up with: public static class Extensions { public static void SubscribeOnce<T>(this IObservable<T> observable, Action<T> action) { IDisposable subscription = null; subscription = observable.Subscribe(t => { action(t); subscription.Dispose(); }); }

How to use Extension methods in Powershell?

依然范特西╮ 提交于 2021-01-26 03:09:12
问题 I have the following code: using System public static class IntEx { /// <summary> /// Yields a power of the given number /// </summary> /// <param name="number">The base number</param> /// <param name="powerOf">the power to be applied on te base number</param> /// <returns>Powers applied to the base number</returns> public static IEnumerable<int> ListPowersOf(this int number, int powerOf) { for (var i = number; ; i <<= powerOf) { yield return i; } } } I've loaded the dll in Powershell(Windows

Extension methods for two different classes

旧时模样 提交于 2021-01-07 01:19:48
问题 I have a situation where in C# I consume data via an OData API. Actually, there are two different OData endpoints (two different models), where one is a superset of the other. I have created two different C# projects (A and B) which contain code to interact with the two API's. The code is automatically generated using Unchase OData Connected Service extension. As a result, project A and project B both contain a class ODataService , which is the main type to interact with. Depending on whether

Extension methods for two different classes

爷,独闯天下 提交于 2021-01-07 01:14:27
问题 I have a situation where in C# I consume data via an OData API. Actually, there are two different OData endpoints (two different models), where one is a superset of the other. I have created two different C# projects (A and B) which contain code to interact with the two API's. The code is automatically generated using Unchase OData Connected Service extension. As a result, project A and project B both contain a class ODataService , which is the main type to interact with. Depending on whether

type extension on a list in F#

佐手、 提交于 2020-12-13 03:34:19
问题 Let's say I have a type: let MyType = some info ... but, it is commonly used in a list: MyType list so I can define: let MyTypeList = MyType list is there a way to define a type augmentation on MyTypeList? my practical case is that the type returns results of some work, it is handled in batches and I have some code that tell me if the whole batch is ok, if it is partially ok, or if everything went wrong. If I could add extensions to the list type, the syntax would be simpler. let a :

type extension on a list in F#

笑着哭i 提交于 2020-12-13 03:25:52
问题 Let's say I have a type: let MyType = some info ... but, it is commonly used in a list: MyType list so I can define: let MyTypeList = MyType list is there a way to define a type augmentation on MyTypeList? my practical case is that the type returns results of some work, it is handled in batches and I have some code that tell me if the whole batch is ok, if it is partially ok, or if everything went wrong. If I could add extensions to the list type, the syntax would be simpler. let a :

Flutter extension-methods not working, it says “undefined class” and “requires the extension-methods language feature”

好久不见. 提交于 2020-12-05 05:00:34
问题 I'm slowly building my personal website over at dlblack.dev, and I'm trying to spice it up a little bit. For example, from a computer (rather than a tablet or phone since they don't have mouse pointers), if you hover over any of the clickable items, it doesn't change your mouse pointer to indicate it's clickable, and the clickable object doesn't change at all. I've decided to follow this FilledStacks tutorial, but it doesn't mention anything about fixing this problem. Essentially what's

C#: SkipLast implementation

非 Y 不嫁゛ 提交于 2020-08-24 03:44:10
问题 I needed a method to give me all but the last item in a sequence. This is my current implementation: public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source) { using (IEnumerator<T> iterator = source.GetEnumerator()) { if(iterator.MoveNext()) while(true) { var current = iterator.Current; if(!iterator.MoveNext()) yield break; yield return current; } } } What I need it for is to do something with all the items except the last one. In my case I have a sequence of objects with various