Hilarious, but it is so true. This is exactly what happens in most cases. How would you sell F# to your boss?
Hilarious, but it is so true. This is exactly what happens in most cases. How would you sell F# to your boss?
Microsoft previews Windows 8 at the BUILD Conference Day 1 keynote. Below after the break is my brief summary of what was shown and announced: Continue reading »
Ever since the announcement of a paid-for product, .NET Reflector by RedGate which has been a free application that is now an essential tool to many .NET developers, there has been an uproar among the community developers regarding this move to completely change a free essential developer tool to a paid-for app.
JetBrains, the creator of the famous and popular ReSharper, dotTrace and dotCover, has now created a free decompiler tool that’s similar (if not better) than .NET Reflector called dotPeek.
dotPeek offers:
Learn more about dotPeek and download an early build. Please submit bug reports and feature requests to the dotPeek issue tracker, and discuss the tool on the dotPeek forum.
For latest news and hints, follow dotPeek on twitter or like JetBrains on Facebook
Finally, have in mind that decompiling will also be available right in Visual Studio as part of the upcoming ReSharper 6.
This is my little research today for some work I’m helping out. So you have a Unicode encoded HTML string (or url), e.g. “津津有味”, that you want to convert to an actual unicode string, in this case “津津有味”, but you don’t have the trusty use of HtmlUtility.HtmlDecode or anything on hand (for example you’re using the compact framework like myself). Here’s how you convert those numbers into actual unicode characters.
[sourcecode language="csharp"]
// Convert the number into a short – you can make this a little more safe by using short.TryParse instead
ushort mycode = Convert.ToUInt16("27941");
// Now convert that integer into a byte array
byte[] mybytes = BitConverter.GetBytes(mycode);
// We have our byte array, convert to a string! Tada!
string mystring = Encoding.Unicode.GetString(mybytes);
[/sourcecode]
And there we have it. In order to parse all the unicode encoded numbers out, you just need a simple regular expression which I’m sure you can figure out.
I hope that helps someone out there, because it took me some time inspecting variables in order to get it right.
I thought I’ll post this in case anyone else encounters this problem. The purpose of the method is to get back a set of ClientContacts filtering based on the ClientID and select only those active if the onlyActive parameter is true, else ignore the IsActive filter and return all the records.
Here’s my LINQ query with a simple if-else shortcut within it:
[sourcecode language="csharp" highlight="5"]
public IQueryable<ClientContact> GetClientContactByClient(int clientID, bool onlyActive)
{
return from clientContact in this.db.ClientContacts
where clientContact.Client_AutoID == clientID &&
onlyActive ? clientContact.IsActive : true
select clientContact;
}
[/sourcecode]
Notice line 5? Here’s where I got this code wrong. The above code generates the following SQL statement:
[sourcecode language="sql"]
SELECT *
FROM [dbo].[ClientContacts] AS [t0]
WHERE (
(CASE
WHEN [t0].[Client_AutoID] = @p0 THEN CONVERT(Int,[t0].[IsActive])
ELSE @p1
END)) = 1
[/sourcecode]
If you actually work it out, this SQL statement will always return all records.
Here’s the change I made on the code to fix it.
[sourcecode language="csharp" highlight="5"]
public IQueryable<ClientContact> GetClientContactByClient(int clientID, bool onlyActive)
{
return from clientContact in this.db.ClientContacts
where clientContact.Client_AutoID == clientID &&
(onlyActive ? clientContact.IsActive : true)
select clientContact;
}
[/sourcecode]
Notice the brackets I added? This resulted in the generation of the following SQL statement:
[sourcecode language="sql"]
SELECT *
FROM [dbo].[ClientContacts] AS [t0]
WHERE ([t0].[Client_AutoID] = @p0) AND ((
(CASE
WHEN @p1 = 1 THEN CONVERT(Int,[t0].[IsActive])
ELSE @p2
END)) = 1)
[/sourcecode]
Again, if you work it out, this is the correct SQL statement to achieve what I want. I didn’t know a set of brackets make such a huge difference in the SQL code generation. Do take note of this when you’re finding out why your LINQ query doesn’t work as you might have thought.
It’s always interesting to see what I’ve done in the past, especially on video. Take a look. I talked about C# 4.0, and SharePoint development. Looking back, I wonder if I would have said the same thing now.
Channel 5.5: Justin Lee at the MVP Summit 2008 from Rob Windsor on Vimeo.