FindAll vs Where extension-method

Well, FindAll copies the matching elements to a new list, whereas Where just returns a lazily evaluated sequence – no copying is required. I’d therefore expect Where to be slightly faster than FindAll even when the resulting sequence is fully evaluated – and of course the lazy evaluation strategy of Where means that if you … Read more

Is it possible to implement mixins in C#?

It really depends on what you mean by “mixin” – everyone seems to have a slightly different idea. The kind of mixin I’d like to see (but which isn’t available in C#) is making implementation-through-composition simple: public class Mixin : ISomeInterface { private SomeImplementation impl implements ISomeInterface; public void OneMethod() { // Specialise just this … Read more

How to use Active Support core extensions

Since using Rails should handle this automatically I’m going to assume you’re trying to add Active Support to a non-Rails script. Read “How to Load Core Extensions”. Active Support’s methods got broken into smaller groups in Rails 3, so we don’t end up loading a lot of unneeded stuff with a simple require ‘activesupport’. Now … Read more

Using extension methods in .NET 2.0?

Like so: // you need this once (only), and it must be in this namespace namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] public sealed class ExtensionAttribute : Attribute {} } // you can have as many of these as you like, in any namespaces public static class MyExtensionMethods { public static int MeasureDisplayStringWidth ( … Read more

The operation cannot be completed because the DbContext has been disposed error

This question & answer lead me to believe that IQueryable require an active context for its operation. That means you should try this instead: try { IQueryable<User> users; using (var dataContext = new dataContext()) { users = dataContext.Users.Where(x => x.AccountID == accountId && x.IsAdmin == false); if(users.Any() == false) { return null; } else { … Read more

Ambiguous call between two C# extension generic methods one where T:class and other where T:struct

EDIT: I’ve now blogged about this in more detail. My original (and I now believe incorrect) thought: generic constraints aren’t taken into account during the overload resolution and type inference phases – they’re only used to validate the result of the overload resolution. EDIT: Okay, after a lot of going round on this, I think … Read more

Swift extension example

Creating an extension Add a new swift file with File > New > File… > iOS > Source > Swift File. You can call it what you want. The general naming convention is to call it TypeName+NewFunctionality.swift. Example 1 – Double Double+Conversions.swift import Swift // or Foundation extension Double { func celsiusToFahrenheit() -> Double { … Read more

techhipbettruvabetnorabahisbahis forumu