Microsoft .NET - Tips and Tricks



Monday, February 25, 2008
Web Parts generator tool


Background
From the moment I started working with Web Parts and portal framework the thing that I missed the most was a designer that I could use to create and separate Web Part's design/layout from the "code behind". The way Web Parts are supposed to work is similar to Web Server Controls meaning that you have to add all the controls manually to Controls collection and you have to render them from your code "manually".


The idea
Some time ago I read a great article made by Michiel Van Otegem about skinned controls. Based on his idea and based on functionality of his SkinnedPart class I made BaseSkinnedWebPart which is a slightly improved Michiel's control. BaseSkinnedWebPart allows us to create Web Part's design/layout in an ASCX control and use it as separate file (skin) that defines the layout of Web Part and specifies all the controls of the Web Part.


Time saving solution
The thing that still bothered me a lot is that I had to write a lot of code just to assign all server controls from ASCX to member variables in Web Part, to validate if required controls are present in ASCX or not and similar common things. In a project I was involved in recently we had a Web Part with near 350 server controls so just to create initial Web Part class with all server controls from ASCX (skin) I had to type more than 1000 lines of code risking that I'll make a mistake and spending a valuable time.
In order to overcome that I got to idea of writing a generator tool that will generate the initial Web Part class with all the assignments, validations etc based on previously made ASCX control (skin for Web Part).


The tool
After some time I made the first version of the generator tool (called it swpgen.exe) and published it on codeplex. You can check the project’s home page here or first release’s page here
I also published an article on codeproject describing the details on how to use swpgen.exe generator tool. You can read it here

Labels: , , ,


posted by Popovic Sasa
+ Read comments 0 comments
 

Monday, February 04, 2008
Unit testing internal units/methods - Friend Assemblies

Why?
I was asked about this a few times although there are a number of articles on this subject. The thing is that people usually know about that posibility and how it should be implemented but have difficulties implementing it to the end (especially in case of strongly signed assemblies).

What is the problem?

You set the InternalsVisibleTo attribute on an aseembly level and then you are able to access the internal methods of the assembly from another assembly. But the catch is in the proper way InternalsVisibleTo attribute should be configured.
There were a few examples on web that were not completelly accurate and leaded to confusion. The thing is that number of articles said that PublicKeyToken should be set for strongly named assemblies but actually PublicKey should be set instead.

A very detailed spec with examples on this (and accurate) can be found here: Friend Assemblies (C# Programming Guide)

posted by Popovic Sasa
+ Read comments 0 comments
 

 

Links

Get the Levi9 RSS Feed
Levi9 Global Sourcing

Previous Posts

Web Parts generator tool
Unit testing internal units/methods - Friend Assem...
Signing a 3rd party DLL
Custom paging SPGridView control
Serving files from server
Configuring CruiseControl .Net to work with multip...
Sharing cookies between sub-domains

Archives

February 2007
March 2007
April 2007
January 2008
February 2008
Current Posts

Powered by Blogger
Levi9 Global Sourcing | Jan van Goyenkade 8 | 1075 HP Amsterdam | The Netherlands | +31(0)72 58 210 55 | info@levi9.com
Copyright © Levi 9 | Design by A36