Resolving extension methods/LINQ ambiguity

This is probably one of those rare cases where it makes sense to use an extern alias. In the properties page for the reference to System.Core (i.e. under References, select System.Core, right-click and select “Properties”), change the “Aliases” value to “global,SystemCore” (or just “SystemCore” if it’s blank to start with). Then in your code, write: … 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

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

Interesting “params of ref” feature, any workarounds?

This is not possible. To explain why, first read my essay on why it is that we optimize deallocation of local variables of value type by putting them on the stack: https://web.archive.org/web/20100224071314/http://blogs.msdn.com/ericlippert/archive/2009/05/04/the-stack-is-an-implementation-detail-part-two.aspx Now that you understand that, it should be clear why you cannot store a “ref bool” in an array. If you could, then … Read more

Extension methods syntax vs query syntax

Honestly, sometimes it can be situational once you start using Funcs and Actions. Say you are using these three funcs: Func<DataClasses.User, String> userName = user => user.UserName; Func<DataClasses.User, Boolean> userIDOverTen = user => user.UserID < 10; Func<DataClasses.User, Boolean> userIDUnderTen = user => user.UserID > 10; As you can see the first one replaces the lamdba … 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