I am sure that there are a many people out there who still use VB6 when working with The Raiser’s Edge API but it is more and more common that you need to write .NET code and indeed want to write .NET code. There are several reasons for this but for me it is simply that the Visual Studio 2008 is a thousand time better than the VB6 development environment. I cringe every time I have to go back to a piece of old code or to the VBA environment. What really interests me is the choice of VB.NET or C# for development.
I started my working career developing CAD CAM software on UNIX and later Windows with C++. I then moved on to using Java in the telecoms industry and then with the RE API I used VB6 and VBA. It therefore seemed a natural progression to work with VB.NET. Recently I have been using C#. The client I am working with also develops code and they have been using C#. I thought it would be good to get my teeth into something a bit different (although at its inception C# was almost a clone of Java so the learning curve was not that steep).
There are a number of similarities between VB.NET and C# but they reside almost exclusively around the fact that they both share The .NET Framework. This makes translating code between the two relatively simple. It is the differences that make it obvious that RE API was built with VB in mind.
1. In C# you cannot use Fields like properties with implicit get and set. Instead you have to use the newly inferred get_Field and set_Field methods for each collection
2. You cannot implicitly convert the value of the field output into a string so for example the following is possible in VB.NET:
Dim name = constit.Fields(ERECORDSFields.RECORDS_fld_FIRST_NAME)
In C# you have to write:
string name = constit.get_Fields(ERECORDSFields.RECORDS_fld_FIRST_NAME).ToString();
and even that may fail. If there is no value i.e. it is null then the ToString method will fails. So you have to convert it instead.
string name = (string)constit.get_Fields(ERECORDSFields.RECORDS_fld_FIRST_NAME);
or my preference using the null coalescing operator
string name = (constit.get_Fields(ERECORDSFields.RECORDS_fld_FIRST_NAME) ?? "").ToString();
3. There is the added confusion that there are several forms of objects you can work with in C#: e.g. CRecord, CRecordClass and _CRecord. This is to do with the way COM works and when I did a project a while back with C++ and the API I was thoroughly haunted by it at first. I now realise that COM always abstracts the actual implementation with interfaces. As Blackbaud are doing the same thing with their classes you always get these multiple possibilities. Here CRecord is the interface, CRecordClass is the implementation (where you can also find all the other interfaces implemented too e.g. IBBMetaField, IBBTopObject, etc) and _CRecord is the COM interface to CRecord. In general I use the CRecord interface for a constituent but you have to instantiate it using the CRecordClass object. There is nothing to say that you cannot simply use the CRecordClass throughout (at least I don’t think that there is) but the CRecord interface mimics the functionality as it was originally intended.
4. I discovered today that there appear to be some gaping holes in the C# interpretation of the API. I am not sure why this is the case but the CFund interface does not implement the set_Fields and get_Fields methods so you are forced to use the CFundClass.
5. There are very many areas where you have to pass parameters by reference even though there seems no reason to do so. It is quite common for me at least to forget that ref keyword before the parameter and when it says that there is no matching overloaded method I regularly miss that issue.
Don’t get me wrong I really like using C#. There are some really good features. The client that I am working with now for example had built up a framework where they have objects that inherit from common RE top level objects. In order to instantiate them you have to supply the IBBSessionContext object. (nothing that VB.net could not do of course). They also implement the IDisposable interface and call the Closedown method and all cleanup methods there. This means that you can put these objects into a using clause. After this clause the objects will closedown without the need for extra code in the methods – Very neat.
All in all though VB.NET unsurprisingly so, just gels nicer with the REAPI although as always I would love to hear your comments otherwise. Have you found any issues with C# or any benefits to using it?