Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Sep 4, 2012

C#/.Net Generic constraints

Hi

Despite having no doubt about the usefulness of type constraints in C# generics (this is a key feature to help avoiding bugs when writing generic code in C#) I always had  the impression that it should be able to express more constraints than what the C# language / compiler exposes.

Well, some
 time ago this blog entry called my attention on my RSS reader and motivated me to go and scan the .Net specification (more specifically § II.10.1.7 in the CLI Metadata Definition and Semantics document which can be downloaded from here) and to my surprise I found out that in addition to the valid C# generic constraints CLI also support constraining a generic argument to delegates, arrays and even enums! That is nice.

Next question is: does the C# compiler abides by these rules when consuming assemblies?


To answer this question I wrote a small class library (
in C#) that exposes some generic types and manually (ildasm/ilasm) added each of these constraints. After that I created one application (C#) that uses this library and confirmed that C# compiler does respect these constraints (at least in VS 2010 which uses CSC 4.0.30319.1). Bellow you can see the result of trying to use these generic types with incompatible types:
Generic parameter 'E' was constrained to enums
Generic parameter 'E' was constrained to enums

Generic parameter 'A' was constrained to arrays. 
You can download the sample application from here.

The bottom line:  Generic constrains in .Net  are more useful than what you may be lead to believe ;)

As always, don't be shy! Let me know what you think.

Hope you find this useful.

Aug 15, 2012

Windows 8 / Visual Studio 2012

Hi

Getting back to the subject I am more comfortable with, MS just released Windows 8 / VS 2012 (for MSDN and Technet subscribers). Off course I am downloading both right now but this is the first time, since Windows 95 launch, that I am not going to install the new MS OS as soon as it gets released. 


To be honest I am not even considering installing it (on my main dev machine) in the next 6 ~ 12 months! Contrast that to what I've been doing in the past 
(I've used Vista / Windows 7 RC!) and you can see how "excited" I am about it (maybe I install it on a virtual machine so I can experiment with it). Anyway, sooner or later I'll end up formatting my dev machine and the question is: am I going to give Windows 8 a try? Or shall I take a more drastic approach and install Ubuntu? This bring me to the second MS release.. VS 2012.

One of the main reasons I'm procrastinating migrating to a Linux OS is that I really enjoy developing using .Net (yeah, I do know Mono; the problem is: the bulk of .Net development is still concentrated on MS platform. Also, 
IMHO, *nix lacks a good .Net IDE).

Of course my friends (at least the ones in the software development field) knows that that is not completely  true: I also enjoy MS technology in general (COM+ pops up as one example).


What do you think? Should I dive into Windows 8?


BTW: Visual Studio download finished! This one for sure I'll get installed in the next few days ;)

Happy codding!

Mar 23, 2009

Db4o with Visual Studio 10 / .Net Framework 4

Hi.

When Microsoft announced they would make available VS 2010 CTP I got curious about how easy (or hard) it would be to compile / run Db4o and also how OMN would behave in this early CTP (would it just work, without even require a recompilation? If not, how easy/hard it would be to make it work if possible at all, etc).


Well, yesterday I managed to download the CTP; after extracting the files (24 Gb!!) I just took OMN 2008 installation and give it a try. It was really amazing. The only change I've applied was to update the file %ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\Addins\OMAddin.addin in order to change the target VS (OMN 2008 will set it to 9.0 but VS 2010 is 10.0). 


After this change I just fired up VS and OMN addin was there, working with no issues (as far as I tested :)) as you can see in the screen shot bellow. Cool.



Next step was to load Db4o 2008 solution file; VS 2010 asked whenever I'd like to convert the solution/project files to the newer version; I just consent to that and when it finished converting I just run Db4o Tests. 

This time some tests failed due to missing jars (I didn't run a full build) required to run Java/.Net compatibility tests; besides that expected failure,  only one test failed (I just disabled it for now).


My next steps will be:

  1. Try to understand / fix the falling test.
     
  2. Prepare the environment to at least run the target "build-before-checkin"  defined in build.xml (and uncomment any test commented out to make the tests pass).

  3. Reason whenever it makes sense to use some of C# 4.0 / .Net Framework 4.0 new features (for instance dynamic types) and how Db4o handle them.
Since these will require more time to investigate / test I'll leave them for a forthcoming post.

Adriano

Nov 5, 2008

Are you a C# developer?

If so, you should go and grab a copy (for free) of CodeRush Xpress for Visual Studio!

(I already own a copy of another addin, but I'll give it a try anyway :)

Adriano