Copy one object to another Object

May 15, 2009 13:43 by bryan

I was in need to copying one concreate object to another concreate object, but I needed the flexability that when a new property is added the method would not need to be changed, also I needed the ability for the method to take in any types.

So the first take was to generate a method that uses reflections to go over the obecjts properts and set the returning object properties.  That was quite simple, then to make the method more flexable I used generics to help with my method, to allow for any types to be used.

One thing to note is that you require the try catch, in case the GetValue or SetValue fails, such as if the object is null.

This is what I ended up with.

Here is the VB.NET method

Here is the C#

 


PDB, what and why?

May 14, 2009 13:17 by bryan

If you are like me when you are developing you create a Debug version of your application and in turn .NET provides you with .PDB files for debugging, that is as far as I know, want to know more about it then take a look at John Robbins' Blog on PDB files: what every developer must know


Returning all data from a DataSet Row

May 14, 2009 12:17 by bryan

If you are like me and you are using DataSets and you need to transfer a table rows collection in to a predefined interface then here is your answer

Here is its usage


Visual Basic auto compiler

March 10, 2009 10:12 by bryan

Working hard with VB.Net, hard work, as I find C# much cleaner, but VB.NET does have the advantage of be able to edit code while debugging.  And it compiles while you are working, but I have found that with 64 projects in my solution that the automatic compiler sometimes, quite a lot of the times hogs the machines resources, it would be nice to be able to turn the auto compiler off.


How to determine is a Plugin implements an interface

February 13, 2009 12:41 by bryan

The problem is you have a number of PlugIns in your application, however how do you know which plugins have implemented an interface for a task you need to perform?

Following on from my last article, Plugin Model, I will create a new interface, implement that interface and then find the Plugin that implments that interface.

First lets create a simple Interface

Next implement the interface to a plugin controller class

You can see it here as HelloWorld()

Okay now we need to find which plugins inplement that interface

As you can see above we go over the collection of plugins and check to see if the plugs has a TypeOf IInterface1, if it does then the plugin supports that interface. 

So we can now convert the plugin in to the Interface type and use its interfaces.

I then took this a little further and implemented a Generic method that gets a list of support objects that support a given interface


Plugin Model

February 13, 2009 12:01 by bryan

I've been working with a Plugin model for a few weeks now and I thought it was time I should document the model.

Task is to build an application that you can plugin models via the .config file, and provide a level of configuration for each plugin via the .config file.

This example is for the purposes of example and you should perform more checks to perform validation to ensure that the application is more rebust.  Oh, and you can now do all of this using IoC containers, which I may cover another day.  But I have found serious issues with IoC containers and VB.NET, as VB.NET does not support implicit interface implementation whereas C# does, but that is another issue for another day.

First lets create the interfaces that will be required for a Plugin to work

The PlugInName and Version are just so we can hold general information about the Plugins.

The Initialise method will be called to start the plugin up and when you are finished you must call the Finalise method.

I have included InstalledPlugInElement, which will hold all the configuration information for the plugin that can be stored in the .config file.

Lets have a quick look at the InstalledPlugInElement class

Here are hold the assembly name and a configuration parameter for to enable the Cache for the plugin

Next we need to handle the .config file and the section where the plugs are to be configured, this will be held in the InstalledPlugInSectionHandler, this inherits the ConfigurationSection, as seen below

Okay that's it for now with what we need for the plugins, next we need to be able to load the plugins, with the help of a PlugInLoader

Okay this is quite a lot of code for one method.

What we are going to do in this method is get a list of plugins that are supplied in the .config file, and when we create a new instance of the plugin we'll pass in the Installed plugin Elements that are in the .config file.

The section of the .config that holds the plugin information is "plug_ins", and we get a list of said plugins from the .config file.

You will also require InstalledPlugInCollection, which you'll find in the source at the bottom of this article.

The PlugIn

Of now lets create our PlugIn, generate a new project and add a controller class

 

Of course this controller class implments the IPlugIn interface we created earlier.

We set the Plugin Name and Version number.

What you will also see is we can set the Cache Enabled, which is pulled in from the .config file

Now we can load the plugins in to a collection of plugins

 

That's it for plugins, in another article I will go over how the determine if a plugin implements an interface that you may wish to use.

PlugInExample.zip (42.28 kb)


Caching from a non Web applications

February 6, 2009 08:30 by bryan

Okay you are developing a WinForm application and you are looking at performance, one area is Caching of information, but wait a minute I've been using caching in my web applications for sometime, but how do you do it from a WinForm application as you don't have a host to store your cache.

Would you know it you can use the web cache too, just you have to take a few extra steps to retain your cache, either in memory or in temporary files.

You can use the HttpRequest to store the System.Web.Cache objects in your application, and this works well.

I also came across any Blog, providing another method to Caching, however I have a little concern over this method of caching in files as you are likely to get file locking.

Using System.Web.Caching From The Console Or Windows Forms

I've written my own simple VB.NET application to show it working and just holding the Cache in memory for the life of the application.

WinFormCache.zip (17.73 kb)

Of course you could run a Windows Service which holds all the Cache information, this way it will be available to all your WinForm applications should you require it.


Entity Framework Issues

February 4, 2009 08:59 by bryan

I've come across two issues with the Entity Framework, one that effects any language and one just for VB.NET

It's quite simple, the Entity Framework generates edmx files, however that Inherits Global.System.Data.Objects.DataClasses.EntityObject, which means when you create your Partial class you can not Inherit from your own base class.

The second issue is related to VB.NET, as if you are intending to use Dependence Injection or IoC you need to have an Interface defined and to implement an Interface in VB.NET you must add Implements after each Property and Method, which you can not do as the framework generates it's own code.

I've attached both C# and VB.NET examples, none of which compile

Entity Framework Issues.zip (42.58 kb)