So haven’t posted for a while, was in home city Hong Kong for holidays and busy with work releasing software, gonna be posting a few more things coming up this month so be tuned in 🙂
So sometimes you will get these strange errors or exceptions when using Linq Sequence contains no matching element For example if you use
1 |
var result = myEnumerableCollection.First(x => x.Name == person.Name); |
This will throw InvalidOperationException with Sequence contains no matching element. But if you use
1 2 3 |
var result = myEnumerableCollection.FirstOrDefault(x => x.Name == person.Name); if(result == null) //did not find in the collection something went wrong or ..... |
Which will return you a null if its not found then you can check if the […]
So I was going through some code of codebettercanvas and found it interesting of Karl Seguin using Html Helper extension for his form tags, which has its elegance. e.g
1 |
<form id="login" action="!{Html.LinkTo<HomeController>(c => c.Login()) }" method="post"> |
Basically it calls an extension method called LinkTo with a generic controller and a lamda for calling its action, the extension method looks like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public static class HtmlExtensions { private static readonly string _applicationPath = HttpContext.Current.Request.ApplicationPath == "/" ? string.Empty : HttpContext.Current.Request.ApplicationPath; //other method removed public static string LinkTo(this HtmlHelper html, Expression<Func<T, ActionResult>> action) { var body = action.Body as MethodCallExpression; if (body == null) { throw new InvalidOperationException("Expression must be a method call"); } var controller = typeof(T).Name.Replace("Controller", string.Empty); return string.Format("{0}/{1}/{2}", _applicationPath, controller, body.Method.Name); } } |
[…]
How to do safe base64 url encoding in ASP .NET, I came into a problem of url encoding in IIS 7 where it does not like “+”, “/” in the Url. Basically a Url that looks like of like this http://fake.abc/TIRlcEq0umjO6uJqtqvnkUGntUzv19rK+8mcvPK5qL1bwEZtEUqTlc3iF/TomuXU746Il5IF2iN9SeYuYDqt6SQzfdrv+Ltug2KZteKlYawc= I know you may say what is this??? Its actually some kind of encrypted […]
So was just in the process of installing SQL2005 on one of our VM to test some stuff. Guess what install went great with Client Tools selected, but unfortunately SQL Management Studio doesn’t get installed??? Why ohhh why? I cannot find SQL Management Studio after install of SQL2005 So anyways, the solution is quite simple […]
So there is this character (antagonist) in this TV series “Heroes”, and his name is Sylar People might also know him from the new Star Trek movie, where he plays the young Spock. Anyways, back to the Sylar character, in the show he plays a serial killer who kills people with ability (e.g flying, shooting […]
The Law of Demeter (LoD), or Principle of Least Knowledge, is a design guideline for developing software, particularly object-oriented programs. (wikipedia) While everyday working on code that was written by lazy coders or junior coders I see a lot of violation of this law. I think every programmer should know the Law of Demeter by […]