Visual Studio Intellisense support for parameters in JavaScript

From the perspective of a .NET developer JavaScript lacks of intellisense. Of course, Visual Studio is capable of showing intellisense for defined objects and their members, but when it comes to parameters we face the untyped world. Last year I did a project with a few developers who had to leave their beloved C# world and enter the JavaScript area. Their motivation declined from day to day. So I thought of how to provide them with what they were missing like water in the desert. My approach is based on the facade pattern. It allows to instanciate objects of a type with an instance of the same type, to acts as a wrapper to restore intellisense a JSON object, to be able to load data from a server request into a domain object Here is the code: function Person(data) { /// <summary>Instantiates a new instance of a Person. /// <para> 1. An JSON object containing data.</para> /// <para> 2. A Person object.</para> /// </summary> /// <param name="data" type="object"> /// An object. /// <para>containing data to initialize a person.</para> /// <para>- or -</para> /// <para>of type Person beeing returned by the facade /// to activate intellisense.</para> /// </param> var args, arg, member, lcMember, memberValue; this.firstName = ''; this.lastName = ''; this.fullName = function () { /// <summary> /// Returns the full name of the person. /// </summary> return this.firstName + ' ' + this.lastName; }; //#region Facade pattern to keep intellisense alive... if (arguments !== null || arguments.length === 1) { args = arguments; arg = args[0]; if (arg instanceof Person) { return arg; } else if (arg instanceof Object) { for (member in arg) { lcMember = member.substring(0,1).toLowerCase() + member.substring(1); if (this.hasOwnProperty(lcMember)) { memberValue = arg[lcMember]; if (arg.hasOwnProperty(lcMember)) { memberValue = arg[lcMember]; } else if (arg.hasOwnProperty(member)) { memberValue = arg[member]; } if (typeof(memberValue) === 'string' && memberValue.indexOf('/Date(') === 0) { memberValue = new Date( parseInt( memberValue.substr(6))); } this[lcMember] = memberValue; } } } } //#endregion return this; } The only thing I don’t like about is the fact that I need to name the type when comparing by instanceOf… Wrapped in an Visual Studio snippet eases up the pain… And here is an example of the usage: $(document).ready( function () { // After an object is instantiated intellisense works... var person = new Person({ firstName: 'daniel', lastName: 'fisher' }); // ... but when passed as a parameter it gets lost ... printFullName(person); }); function printFullName(person) { // ... using the facade pattern we let intellisense // know what *type* it is. var thePerson = new Person(person); console.log(thePerson.fullName()); } I hope this helps!

More comfort reading values from lines in CSV-files

Today I had to read values from multiple CVS-files. I wanted to build a testable and reusable solution instead of the ugly sequential spaghetti that easily happens. So here is a sample of a line: 1 var lineReadFromCsv = 2 "42;Daniel;Fisher;1980-03-25;{79704C0D-1A4F-4DDD-80F6-CA79E81BF7CD}"; To increase the readability I created enumerations that point to the index of the position of the values in each line that I wanted to read: 1 public enum DataFormatField 2 { 3 Id = 0, 4 GivenName = 1, 5 Surname = 2, 6 DateOfBirth = 3, 7 UniqueId = 4, 8 } I created a class called ParserParameter that contains enums that 1 public class ParserParameter 2 { 3 prop Enum FirstName { get; set; } 4 //... 5 } 6 Last but not least an extension class the provides a generic method TryGetValueOrDefault<T>(). It takes an enum member as parameter. It can convert int, long, float, decimal, double, guid, datetime as well as string and can easily be extended. 1 int id; 2 if (fields.TryGetValueOrDefault( 3 DataFormatField.Id, 4 out id)) 5 { 6 Console.WriteLine(id); 7 } 8 9 string givenName; 10 if (fields.TryGetValueOrDefault( 11 DataFormatField.GivenName, 12 out givenName)) 13 { 14 Console.WriteLine(givenName); 15 } 16 The complete code can be downloaded at forkcan.

Ultimate Guide to speed up Visual Studio

I believe that better tools lead to better results. That’s why I care about my tools performance a lot! Recently I had a conversation with Peter Kirchner and Kay Giza on how to speed up Visual Studio. Specifically by configuring you Anti-Virus software. But beside that there are loads of things that you can do. So I decided to share the tweaks on environment: Visual Studio 2008 Options Disable “Animate environment tools”… Disable “Track Changes”… Disable “Cider” – the WPF designer in VS 2008 … Visual Studio 2010 Disable the WPF designer in VS 2010… Disable “Track Active Item in Solution Explorer”… Start with empty environment/disable start page… Disable “Enable rich client visual experience”… Enable “Only build startup projects and dependencies on Run”… Disable intellitrace… Anti-Virus Exclude the GAC and Visual Studio related directories from you virus scanner… Exclude the devenv.exe from your virus scanner… Windows Search Ensure your projects directory is not indexed… 64 Bit support Patch the devenv.exe to support 2+ GB memory… Force Visual Studio to NOT swap data into the paging file: http://visualstudiogallery.msdn.microsoft.com/de-de/2cfd12ae-f070-4182-9211-23d11aeecc35   Windows XP? And if you are not running Windows 7 yet: http://support.microsoft.com/kb/981741 Misc Finally: The less Add-Ins, Visualizers, Snippets, Templates etc. you have installed the faster will be Visual Studio. On the other side are these things really helpful and increase your productivity. So you got to find a way in the middle…

Re: How to change the default browser in Visual Studio programmatically

I’d really like to thank Scott Hanselman for digging into the nitty gritty details of how to change the Visual Studio Default Browser. But… let me cite one of the comments: “Should adding browser options to Visual Studio be <sarcasm>this easy</sarcasm>?” I hope we all agree on: Go fix this! As I have not found my way to powershell (yet) and I want to have VS Integration (as Scott finalizes his post) too: Here comes the macro version…Sub SetInternetExplorerAsDefaultBrowser() Dim FilePath As String = _ Path.Combine( _ Environment.GetFolderPath( _ Environment.SpecialFolder.UserProfile), _ "AppData\Local\Microsoft\VisualStudio\10.0\browsers.xml") Dim xml As String = "<?xml version=""1.0""?>" & vbCrLf & _ "<BrowserInfo>" & _ "<Browser>" & _ "<Name>Internet Explorer</Name>" & _ "<Path>""C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE""</Path>" & _ "<Resolution>3</Resolution>" & _ "<IsDefault>True</IsDefault>" & _ "<DDE><Service>IExplore</Service>" & _ "<TopicOpenURL>WWW_OpenURL</TopicOpenURL>" & _ "<ItemOpenURL>""%s"",,0xffffffff,3,,,,</ItemOpenURL>" & _ "<TopicActivate>WWW_Activate</TopicActivate>" & _ "<ItemActivate>0xffffffff,0</ItemActivate>" & _ "</DDE>" & _ "</Browser>" & _ "</BrowserInfo>" If (File.Exists(FilePath)) Then File.Delete(FilePath) End If Using sw As New StreamWriter(FilePath) sw.Write(xml) End Using Dim ConfigFile As New FileInfo(FilePath) Using key As RegistryKey = _ Registry.CurrentUser.OpenSubKey( _ "Software\" & _ "Microsoft\" & _ "VisualStudio\" & _ "10.0\" & _ "WebBrowser\" & _ "ConfigTimestamp", _ True) key.SetValue( _ "LastConfigurationTimestamp", _ DateTime.Now.ToUniversalTime().ToFileTime(), _ RegistryValueKind.QWord) key.SetValue( _ "CacheFileDateLastMod", _ ConfigFile.LastWriteTimeUtc.ToFileTime(), _ RegistryValueKind.QWord) key.SetValue( _ "CacheFileSizeBytes", _ ConfigFile.Length, _ RegistryValueKind.DWord) End Using End Sub

NRW Conf 09

Auch in diesem Jahr veranstaltet der Just Community e.V. wieder das größte Developer und IT-Pro Community Event. Unter dem Motto „Check-In zum Wissensvorsprung“ holen wir am 28.08.2009 zahlreiche nationale und internationale Speaker nach Wuppertal. Neben den Vorträgen haben Sie natürlich auch dieses Jahr wieder viel Zeit für das Networking mit anderen ITlern aus Nah und Fern. Alle Informationen, wie die Agenda und eine Übersicht über die Speaker gibt es unter http://www.nrwconf.de/. Wir freuen uns, Ihnen auch dieses Jahr sowohl bekannte Gesichter, als auch neue Speaker vorstellen zu dürfen. Die Veranstaltung wurde in diesem Jahr möglich durch unsere Sponsoren: Hewlett Packard, devcoach, Microsoft Deutschland, Brockhaus AG, Itemis AG, sepago GmbH, MT AG, sowie weiteren Unternehmen. Eine weitere Neuerung in diesem Jahr ist der Workshop Day, der am Vortag der eigentlichen Konferenz – sprich am 27.08.2009 – in den Räumlichkeiten unseres Sponsoren Ontaris GmbH stattfindet. Der Developer-Workshop befasst sich mit der Microsoft Web Platform und behandelt die Themen Rich Internet Applications mit Silverlight 3.0 und Web 2.0 Applikationen mit ASP.NET AJAX und JQuery. Die Workshops haben eine begrenzte Teilnehmerzahl (je acht) um den Lernerfolg zu garantieren. Also schnell einchecken…

netug-niederrhein.de User Group Meeting

  The user group met today at netzkern, a company in Wuppertal specialized in .net development and SiteCore - thanks the venue and drinks! Thanks to Matthias for the pic! This time we had "Sliverlight 2 in the real world" as a topic presented by Florian Kruesch. He presented new visual features as well as use cases and projects he's working on. Because he didn't touch the non-visual stuff like Isolated Storage he invited me to show something that I've build with the bits: The "Silverlight Cache" for javascript - most commonly used to cache json returned by web services. A lovely way to reduce traffic :-)