DCSIMG
Tips - IronShay

Browse by Tags

All Tags » Tips (RSS)

Razor Tip #2: Output Text in Code Context

Razor, the new ASP.NET MVC view engine is incredible. I like it. A LOT. Great work Microsoft! In this series of posts I’m sharing some handy tips and tricks that can enhance your experience with this new view engine. Enjoy! The Problem Razor is the place where HTML and C# live together in harmony. This is, in my opinion, one of the things that make razor the great view engine that it is. However, there’s a fly in the ointment. Assume you want to output “Good Morning!” if the hour is between 6AM and...
Posted by shayf | with no comments

LINQ Tip: Chain Ordering

Assuming you have the next code: public class Person { public string Name { get; set; } public int Age { get; set; } } public class Whatever { public void Do() { var people = new List<Person> { new Person {Name = "Shay Friedman", Age = 27}, new Person {Name = "Shawn Doe", Age = 51}, new Person {Name = "Elvis Presley", Age = 76} }; } } And now you want to order it first by name and then by age using LINQ. If you were to do that: var orderedPeople = people.OrderBy...
Posted by shayf | with no comments

After installing Process Explorer you get “Windows cannot find “C:\Windows\System32\taskmgr.exe”” when trying to open Task Manager

One of the first steps I do when installing a new computer is downloading process explorer and make it replace the default Windows Task Manager. However, with my new computer not everything went so smooth and after setting Process Explorer to replace the Task Manager, it screwed something up. After that, every time I tried to load the task manager I received the error: “Windows cannot find “C:\Windows\System32\taskmgr.exe”: Such things can drive me crazy! Anyway, I researched a bit and found the...
Posted by shayf | with no comments
תגים:,

A List of Essential Tools for a new Computer

[Note: cross posted from IronShay.com ] This week I got my new laptop and it’s AWESOME! It is a 64-bit Dell Studio XPS 16 with the following specification (the main features): Processor: Intel® Core™ i7-720QM Quad Core Processor 1.6GHz (2.8GHz Turbo Mode, 6MB Cache) Screen: 16' inch RGBLED Full HD 1080p RAM: 8Gb 1333Mhz DDR3 Dual channel HD: 500Gb 7200RPM Graphics: 1GB ATI Radeon  HD 4670 And this is how it looks like: It’s so much fun to work like that! everything just works and you don...
Posted by shayf | with no comments
תגים:, ,

Visual Studio Tip: Compilation Symbols

There are times when we need to use different code statements for different build configurations – this means that some code will not exist in assemblies that are built in certain build configurations. Compilation symbols come to help in this case. You can set a symbol that will exist in  a specific build configuration and then use it inside your code files to write or exclude code when this project is built using this build configuration. The most familiar case of this scenario is debug and...
Posted by shayf | with no comments
תגים:, , , , ,

IronRuby Tip: Using Generic CLR Methods from IronRuby

A while ago I wrote a post about using Generic CLR classes from IronRuby . This time I’ll share with you its less intuitive friend – using generic CLR methods from IronRuby. As a result of Ruby being a duck-typed language which works with types implicitly, generics is not really needed. The whole language is generic… This is why using generic CLR types might become a bit odd for the language. Nonetheless, this fact will not stop us. The price to pay in order to enjoy Ruby in the .Net framework is...
Posted by shayf | 1 comment(s)

A Handy Extension Method: Retrieving Session Variables

[More handy extension methods: raise events safely , get the current page load mode ] Retrieving session variables is a daily task for web developers. In order to fetch a session variable, we should check if it exists and only then convert it to the expected type and use it. For example: int myVal; if (Session[ "MyVar" ] != null ) { int .TryParse(Session[ "MyVar" ], out myVal); } // ... more code ... This is an annoying practice which can be easily replaced by extension methods...

A Handy Extension Method: Raise Events Safely

Raising events is a very common practice. We do that a lot and it’s pretty irritating to check for nullity every time: if (eventHandler != null ) { eventHandler(sender, e); } Here comes extensions methods to our aid again. With only two extension methods, we can cover all possible event handlers and raise our events safely in one line. For example: MyEvent.RaiseSafe( this , EventArgs .Empty); Or MyEvent.RaiseSafe<MyEventArgs>( this , new MyEventArgs(someParameter)); In order to achieve that...

A Handy Extension Method: Get The Current Page Load Mode

I find myself pretty often write code to find out if I’m on a postback, callback or initial page load. I’ve decided to put an end to that and write an extension method to the ScriptManager class that will tell me the mode I’m in. This is what I came up with: public static class Extensions { public enum PageLoadMode { /// <summary> /// Occurs when the page is loaded for the first time. /// </summary> InitialPageLoad, /// <summary> /// Occurs on a regular postback. /// </summary>...

Visual Studio Tip: Keyboard and Mouse Shortcuts

I’ve recently learned a few keyboard\mouse shortcuts in Visual Studio and I thought I would share them with you. Actually some of these tricks will work on every text box in your windows environment (or most of them at least…): Clicking the middle mouse button on a tab closes it. Pressing ALT while selecting text will enable you to select a square area of text: Ctrl+F3 will search for the current selected text down the current file. Shift+F3 will search for the current selected text up the current...
Posted by shayf | 4 comment(s)

C# Tip: Converting Whole Lists in a Single Line of Code

Lately I wanted to convert a list of items from one type to another. There is the straight way of doing so: writing a loop that iterates through the list, converts each item and generates the output list. There is a shorter way though. List has a ConvertAll method. You give it the output type and a delegate that converts a single item and that’s it. Writing this delegate yourself is just annoying… This is where the Convert class comes into action – you can use the Convert.ToXXX as the conversion...
Posted by shayf | 3 comment(s)

Tip: How To Use Generic .Net Classes in IronRuby

In the latest version of IronRuby (0.3), the ability to use Generic .Net classes was added. I couldn’t find anywhere how to do that so I dug it out of the code and now I’ll share it with you! Example #1 - List This is how to define an Int32 list, add two numbers to it and print them: list = System::Collections::Generic::List[System::Int32].new list.add 4 list.add 12 list.each { |x| puts x } Of course we can also use Ruby type like Numeric, String, etc. Example #2 – Dictionary This is how to declare...
Posted by shayf | with no comments
תגים:, ,

SVN Error “Can't open C:\WINDOWS\TEMP\report.tmp Access is denied” on Update

The Problem You try to execute an Update operation and you get an error: “Can't open C:\WINDOWS\TEMP\report.tmp Access is denied”. The Solution This is a server problem. In order to fix it, do the following: Go to your SubVersion server Open the services console (Start->Run->Services.msc) Find the SubVersion service Restart it. Enjoy! Shay.
Posted by shayf | 1 comment(s)
תגים:,

IronRuby Tip: Ruby String and ClrString

When you use IronRuby to execute some C# code, for example, and the C# code returns a string, pay  attention that the string is not a Ruby string! The type of the object you receive is ClrString. ClrString is the equivalent of System.String in IronRuby, all the System.String methods will work on ClrString objects, but Ruby’s string methods will not (and vice versa). For example: clr_string = MyCSharpNameSpace :: MyClass . ReturnString() clr_string. IndexOf( "something" ) # This will...
Posted by shayf | 3 comment(s)
תגים:, ,

How to Debug and Run IronRuby Code From Visual Studio

This isn't a trivial thing to do until the IronRuby Visual Studio Integration component is out. So here are the steps in order to achieve that: 1. In Visual Studio, click on File-> Open -> Project/Solution 2. Select ir.exe from the [IronRuby code directory]\trunk\build\debug (or release, depends on how you've compiled the code) 3. Right click ir.exe in Solution Explorer and select Properties 4. In Command Arguments, with "-D [path to code file]" where [path to code file] will...
More Posts Next page »