Compsoft Flexible Specialists

Compsoft plc

PBA Project Weblog Compsoft Website News Archive Privacy Policy Contact Us  

Friday, August 18, 2006

Progress Meeting 18/08/06

Present

PBA: Project Team

Compsoft: Robin Churcher, Neil Bostrom, Henry Carter

Outstanding Actions from previous meeting (11th Aug)
  • The Searching facilities in DNN are not good although they may be improved in the latest released version (version 4.3.4). This needs investigation.
  • Other suggestions regarding searching include use of Google or Windows Indexing Service.
  • The LOGIN option to the content management side was discussed and it was decided that it should only be visible under certain circumstances. PBA will discuss these circumstances and notify Compsoft
Actions
  • HJC will be focussing on styling for the coming week.
  • Visibility of login control was discussed. After some debate, it was settled (a neat solution - but not one I'm going to make public!).
  • New menu system almost complete. 90% was demonstrated.
  • After some initial investigation is seems that DNN does not support any appropriate site map controls. Alternatives will be investigated
  • Compsoft will update the test system on Wednesdays (@ 17:00). This will be a regular occurrence.
  • 'Contact us' form currently has an issue with the JavaScript. HJC to look at fixing the JavaScript.
  • Time to be spent at next meeting showing the editing features to allow Leon to start the training guide.
Next progress meeting: 25th August 2006.

Tuesday, August 15, 2006

Generics: awesome (until you use enums)

Right, first up I think I should make it very clear that Generics in .NET 2.0 rock seriously hard. However, I feel in the intrests of developer awareness I should post this slight problem I found while writing a generic method a few days ago.

Basically, I was trying to write a method which could be called to get module settings from a database. I thought it would be a good idea to have one method that just picked up the setting. In this case, it was always coming from XML and so was a string when initially returned. It then returned it to me in the correct format.

Here's what I came up with initially:
Public Shared Function GetTabModuleSetting(Of T)(ByVal settings As Hashtable, ByVal key As String, ByVal DefaultValue As T) As T
Dim o As Object = settings(key)
Dim retValue As T = DefaultValue
If o IsNot Nothing Then
Try
retValue = Convert.ChangeType(o, GetType(T))
Catch ex As Exception
retValue = DefaultValue
End Try
End If
Return retValue
End Function
Pretty simple and works so long as the representation of the setting is convertable however enums return as their numeric values which is then in turn held in a string when returned to my function which will therefore not happily convert to a return type of Enum.

The way I got round this is shown below:
Try
' If we are trying to return an enum then we have to work differently
If GetType(T).IsSubclassOf(GetType([Enum])) Then
retValue = Convert.ChangeType([Enum].Parse(GetType(T), [Enum].GetName(GetType(T), CType(o, Integer))), GetType(T))
Else
retValue = Convert.ChangeType(o, GetType(T))
End If
Catch ex As Exception
retValue = DefaultValue
End Try
This basically parses the enum correctly having initially converted the string representation of the numeric value into an integer. Not a pretty work around but a necessary one in order to make the function truely generic so as to include Enums in it's repertoire.