Poor man's generics in .NET 1.x#

I hadn't seen this little .NET 1.x trick before yet, so I thought I'd share it with you: in case you're really hurting from the lack of generics and you can't wait until sometime next year when VS2005 comes out, here you go... Very poor man's unflexible compile-time generics:

using T = MyItem; // It's magic!

public class PoorMansGenerics
{
    public static T[] CreateArray(int size)
    {
        return new T[size]; // Incredible! Just like real generics!
    }
}

Yeah I know it's lame and it does only 2% of what real generics do, but it can save you some typing and I thought it was pretty funny so whatever :-) For example, for a copy/paste ready solution of strongly typed collections: just replace the MyItem stuff below with whatever you want.

using T = MyItem;

/// <summary>A collection of <see cref="MyItem"/> objects.</summary>
public class MyItemCollection : CollectionBase
{
    /// <summary>
    /// Creates a new <see cref="MyItemCollection"/>
    /// </summary>
    public MyItemCollection()
    {
    }
    
    /// <summary>
    /// Adds the given item.
    /// </summary>
    /// <param name="item">The item to add.</param>
    /// <returns>The position in the list where the item was added.</returns>
    public int Add(T item)
    {
        return List.Add(item);
    }

    /// <summary>
    /// Adds the given items.
    /// </summary>
    /// <param name="items">The items to add.</param>
    public void AddRange(T[] items)
    {
        for (int i = 0; i < items.Length; i++)
        {
            List.Add(items[i]);
        }
    }

    /// <summary>
    /// Inserts a given item.
    /// </summary>
    /// <param name="index">The position where to insert the item.</param>
    /// <param name="item">The item to insert.</param>
    public void Insert(int index, T item)
    {
        List.Insert(index, item);
    }

    /// <summary>
    /// Removes a given item.
    /// </summary>
    /// <param name="item">The item to remove.</param>
    public void Remove(T item)
    {
        List.Remove(item);
    }

    /// <summary>
    /// Determines whether this collection contains the given item.
    /// </summary>
    /// <param name="item">The item to search.</param>
    /// <returns><c>true</c> if this collection contains the given item, <c>false</c> otherwise.</returns>
    public bool Contains(T item)
    {
        return List.Contains(item);
    }

    /// <summary>
    /// Gets the index of the given item in the collection.
    /// </summary>
    /// <param name="item">The item for which to retrieve the index.</param>
    /// <returns>The index of the given item in the collection.</returns>
    public int IndexOf(T item)
    {
        return List.IndexOf(item);
    }

    /// <summary>
    /// Copies the elements in this collection to the given array.
    /// </summary>
    /// <param name="array">The array to which to copy the items.</param>
    /// <param name="index">The index at which to start copying.</param>
    public void CopyTo(T[] array, int index)
    {
        List.CopyTo(array, index);
    }

    /// <summary>
    /// Gets or sets the item at a given index.
    /// </summary>
    public T this[int index]
    {
        get
        {
            return (T)List[index];
        }
        set
        {
            List[index] = value;
        }
    }
}

Blog | Programming | .NET | VS.NET | Samples
Monday, November 29, 2004 3:48:21 PM (Romance Standard Time, UTC+01:00) #    Comments [1]  | 

 

SmartPart for SharePoint v1.0 released#

Jan Tielens - SharePoint Connoisseur Extraordinaire - just released v1.0 of his SmartPart for SharePoint.

"SmartPart: A SharePoint Webpart that can host any ASP.NET user control. Create your webparts by using the VS.NET designer instead of coding everything by hand!"

If you're into Webpart development, you're going to wanna kiss him ;-) Way cool!

Wednesday, November 24, 2004 12:40:07 AM (Romance Standard Time, UTC+01:00) #    Comments [1]  | 

 

Guidelines - a hidden feature for the Visual Studio Editor#

Sara Ford (young, cool, smart, goodlooking techie - damn I'm in the wrong country) just revealed a hidden registry setting to enable guidelines in Visual Studio (via Scott Swigart).

Guidelines are just vertical lines that run along a certain column in your text editor. This will of course prove a major productivity gain for COBOL.NET programmers since they're finally able to visually show lines along columns 8 and 12 :-)

Blog | Programming | .NET | VS.NET
Wednesday, November 24, 2004 12:31:15 AM (Romance Standard Time, UTC+01:00) #    Comments [0]  | 

 

InfoPathHelper: add offline support to InfoPath!#

If you heard Yves and me talk about InfoPath and SharePoint on the TechNet session a while ago, you'll remember my promise that I'd get my InfoPath helper class I showed there out on the web sometime. Well, I finally got around to building it as v1.0 and wrapping it up nicely so here goes... A big thanks to Ned Friend from Microsoft for the original idea I based this on!

InfoPathHelper is a small reusable .NET library you can use to add offline support to InfoPath forms. That's right, you're finally able to make InfoPath a real smart client that is offline capable of submitting forms and querying data sources, without any extra security requirements whatsoever.

For the end user, the form will appear to continue working when the machine is offline or when the target you're submitting your form to is unavailable (a Web Service, a Sharepoint site, ...). The next time the machine goes online, any pending requests will be submitted. The same goes for querying data sources (files on a network share, Web Services, ...): if they're not available, the data will be taken from the local cache until the next time it can be refreshed.

For a developer using the InfoPath 2003 Toolkit for Visual Studio .NET, it boils down to inheriting from the CachingInfoPathForm base class, changing your submittal options to use form code, deleting the messy generated boilerplate code (you get cleaner properties and events for free in stead) and calling a few methods depending on your needs. The following example shows how to enable offline support for a form that has a submit data adapter named "WebServiceSubmit" and a data object named "Countries".

public class MyCachingForm : CachingInfoPathForm
{
    [InfoPathEventHandler(EventType=InfoPathEventType.OnSubmitRequest)]
    public void OnSubmitRequest(DocReturnEvent e)
    {
        // Attempt to submit the request and return a value to indicate if it worked.
        e.ReturnStatus = ProcessSubmitRequest( "WebServiceSubmit" );
    }

    [InfoPathEventHandler(EventType=InfoPathEventType.OnLoad)]
    public void OnLoad(DocReturnEvent e)
    {
        // Attempt to submit any cached requests and query a data object.
        SubmitCachedRequests( "WebServiceSubmit" );
        QueryDataObject( "Countries" );
    }
}

If you're wondering where the cached data is stored without needing any extra security requirements: welcome to the magical world of Isolated Storage :-)

Although I'm labelling it v1.0, I know there will still be some issues with it. I know of one particular problem I haven't been able to solve (but I suspect it's an InfoPath problem actually): if you populate a drop down list with data from a Web Service and cache that, a COM exception is shown when populating it from the cache saying "This DOM cannot be loaded twice". Any help solving this would be greatly appreciated :-)

Anyway, you're free to use this (as the enclosed license states, usual disclaimers apply) but it would be nice if you'd let me know if you're using it somewhere or if you're trying it out and think it's crap. All feedback is welcome! If there's enough interest in this little project, I might even write an article of some sort to explain the workings and usage a little more in depth than the current documentation file.

Enough talk, here's the goodies:

The JelleDruyts.InfoPathHelper 1.0 library and documentation (123,15 KB)
The JelleDruyts.InfoPathHelper 1.0 library, source code and documentation (218,74 KB)

Monday, November 22, 2004 10:07:41 PM (Romance Standard Time, UTC+01:00) #    Comments [8]  | 

 

Sharepoint Services on Webhost4Life#

Great news if you're hosting a website with Webhost4Life: you can enable Windows Sharepoint Services for free (or as we say in Dutch: "gratisch ende voor niks")! Now I've been wanting to set up Sharepoint Services for a while but my own little server doesn't run Windows 2003 yet so that was impossible - needless to say this free service is way cool. So thanks a lot for the tip, Jan!

Technical plug: if you want to enable it, just issue a ticket through the (renewed) support site with the domain or subdomain on which you want to have your Sharepoint installed and they'll put it up for you. Their support is really good, by the way: I logged a few tickets and got actual responses in only a few hours (and not the "we got your request and we'll try to reply sometime before the Vulcans land on Machu Picchu" type of response (Vulcans aren't real, people, get over it)). As soon as I gave them a subdomain, Sharepoint was up and running in a few minutes.

Now I've seen Sharepoint Services in action before of course, but I haven't really done much with it myself yet. If you haven't either: I urge you to give it a spin, it's really impressive! A little overwhelming at first, maybe, but once you get the hang of it, it's quite something! Some scenarios I have in mind...

I've been looking for a way to have certain documents always available online, while still being able to edit them easily. Uploading some Word files to a Document Library does the trick quickly and easily. And you get checkin/checkout functionality and file versioning for free! Too bad you can't edit plain text document directly, though; you'd think if they get integration with Word right, it shouldn't be too hard to put up a simple text box, right?

I've also been postponing writing yet another little app to manage my contacts centrally, and I'm glad I did: importing a table from my crappy little Access database into a nifty Sharepoint List was easy as taking candy from a baby (well, a baby without teeth anyway).

And if you want to put an aggregated feed on your portal somewhere, it's also pretty easy: just use the XML Web Part to take the RSS source in and apply an XSL transform to have it render (e.g. an RSS 2.0 XSL). Cool? I think so!

Anyway, that's just a few of the things in there of course, I'm sure I'll get surprised more and more as I use the product.

Sunday, November 21, 2004 1:26:20 PM (Romance Standard Time, UTC+01:00) #    Comments [4]  | 

 

GMail provides POP access#

Now that's what I call good news: GMail is introducing POP access to its service. I just enabled it and it's all working great! So no more whining, I now officially declare GMail the best free email service in the known part of this world.

Extra treat if you live in Belgium and you're using Skynet as your ISP: it uses an encrypted SMTP connection (not on port 25). Why is that nice? Glad you asked!

In case you haven't noticed, Skynet has blocked port 25 recently so you're forced to use their SMTP server. Now that wouldn't be all bad if it would, well, work. Unfortunately, it has a tendency to suck big time: the last few weeks it has been impossible to get a mail delivered to any Yahoo address. At first it just bounced back but I guess that was too straight-forward: now it just disappears completely without a trace. I've called it in with support but they say there's a problem relaying to the Yahoo servers and that there's no solution. That's right: they're saying not a single Skynet user can send email to a Yahoo address through their SMTP server. And they're not allowing other SMTP servers. Their proposed solution is to create a free account like Yahoo or Hotmail and send through there. Thanks for the great idea guys but I'll be using the GMail SMTP server from now on, thanks very much.

Sunday, November 21, 2004 1:19:55 PM (Romance Standard Time, UTC+01:00) #    Comments [0]  | 

 

New Design!#

Okay so the last time I redesigned this site wasn't that long ago yet but I guess all the graphics and fancy XP-like stuff was a little over the top... If you can actually see your page being rendered before your eyes then there's either something wrong with your site or the server is really slow. In my case I'd assume it was a little bit of both actually ;-)

So anyway: I decided to create a new design, much simpler and easier on the eyes this time. Or at least, so I hope. So please tell me what you think!

(If you're reading this through an aggregator of some kind: don't. Just for once, don't. Open that browser thingy once again if you haven't uninstalled it yet and actually surf to my blog. It'll bring back that special ninetees feeling!)

Monday, November 1, 2004 10:32:01 PM (Romance Standard Time, UTC+01:00) #    Comments [13]  | 

 

All content © 2014, Jelle Druyts
On this page
Top Picks
Statistics
Total Posts: 351
This Year: 0
This Month: 0
This Week: 0
Comments: 530
Archives
Sitemap
Disclaimer
This is my personal website, not my boss', not my mother's, and certainly not the pope's. My personal opinions may be irrelevant, inaccurate, boring or even plain wrong, I'm sorry if that makes you feel uncomfortable. But then again, you don't have to read them, I just hope you'll find something interesting here now and then. I'll certainly do my best. But if you don't like it, go read the pope's blog. I'm sure it's fascinating.

Powered by:
newtelligence dasBlog 2.3.12105.0

Sign In