Hello all,
you may or may not have noticed, that I finished a new major version of myTO in the last days. Now I want to share (or at least name) some of the technologies I’ve used for this new release.
LINQ (“SQL-like operations on object collections”):
I’d like to start with the most important one, called “LINQ”. LINQ helped me replacing the horrible dataset intermediate layer I was using to serialize data. By introduction of LINQ, I was able to execute queries against collection of objects, which – at least partly – replaced the features a dataset provided without the flaws. “…Microsoft LINQ defines a set of method names…These can, for example, be used to project and filter data in arrays, enumerable classes, XML (XLINQ), relational database, and third party data sources”
If you wonder how you can dynamically (during application runtime) create LINQ query-statements, describing several conditions which shall be linked by an OR operation, have a look at this:
But another maybe easier way of achieving this is the usage of lambda methods within the query itself. This is one example:
.Where(x => {
var result = true;
if (Object1.Property1 == specialValue)
result = false;
...
return result;
})
Now let’s imagine you implemented an object which provides some kind of parent-child relationship. In this case what you want is an implementation for IEnumerable or sth. similar.
One effective method for having this IEnumerable interface implemented can be found here:
http://www.claassen.net/geek/blog/2007/11/searching-tree-of-objects-with-linq.html
CLONING OBJECTS:
From time to time you’ll need to clone/duplicate an object. Well, you can obviously do that by the implementation of the IClonable interface. Nevertheless, you have to do this for each object and adapt the implementation each time you change the class of this object. A better and way faster cloning method is to use IL (intermediate language), as described in this post:
http://whizzodev.blogspot.com/2008/03/object-cloning-using-il-in-c.html
On the same page you can also find how to deep-clone (means cloning the references not as references, but as a clone of the referenced object) object(s):
http://whizzodev.blogspot.com/2008/06/object-deep-cloning-using-il-in-c.html
DATA BINDING:
The standard mechanism of windows forms data binding (>1Mio. hits on google, maybe start with this one: http://www.akadia.com/services/dotnet_databinding.html) is good enough most of the time. Nevertheless, there’s one flaw – whenever one of your object implements a collection interface (IEnumerable,…), data binding treats the object as list of objects. This means you can easily bind the object to a datagridview, which will then show a row per object, but you cannot bind it anymore the object’s properties to simple controls like texboxes and stuff.
My workaround for this problem was not to implement the IEnumerable interface explicitly. Rather than that, I enhanced the class by a new method “AsEnumerable()”, which allowed my to use LINQ statements as well as standard data binding.
public IEnumerable<INode> AsEnumerable(){
yield return this;
foreach (Node child in Children)
foreach (var node in child.AsEnumerable())
yield return node;
}
DATA CONTRACTS (“Transfer objects by disk/network/…”)
As I’ve replaced datasets, I had to cope with the problem of storing objects to disk. Even tough there are several methods available (if interested, google for .NET XML serialization or SOAP), the latest one seems to be very promising. In MSN data contracts are described like this:
“A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts. A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged.”
Read more about data contracts on MSN.
If you wonder whether you can also store cyclically referenced objects – yes, you can. Here’s a nice article about that:
DataContracts and object references – Service Station, by Aaron Skonnard – Pluralsight Blogs
DRAG’N’DROP:
As one of the key features I wanted drag’n’drop to work (from Outlook to myTO, and later on from other applications, too). Here are a few links to articles about drag’n’drop, including a bug report for Mozilla Thunderbird to support drag’n’drop. J
Drag’n'Drop von Windows Mail (Vista, 7) – coding-board
Bug 227305 – Support drag-drop single message to desktop / file-system window (e.g. Explorer)
These are some of the technologies and techniques I’ve used during the development. If you like any of these, or you maybe have questions regarding them, I’ll try to help…
Happy coding.
Regards,
Daniel


