I’m not sure I can come up with a good argument to ever use Safe Casting. Per my earlier post, I’m not able to convert the result of the following Predicate, List<MachineProduct>, to a MachineProductCollection even though MachineProductCollection inherits from List<MachineProduct>. // Code complies and the invalid Cast results in // machineProducts being set to [...]
The following code throws an InvalidCastException. public static MachineProductCollection MachineProductsForMachine( MachineProductCollection MachineProductList, int MachineID) { return (MachineProductCollection) MachineProductList.FindAll(c => c.MachineID == MachineID); } This surprises me since MachineProductCollection is merely a generic List of MachineProducts which is exactly FindAll() returns. Here’s the full MachineProductCollection source code: [Serializable] public partial classMachineProductCollection : List<MachineProduct> { public MachineProductCollection() [...]
Continue reading about InvalidCastException Though Same Base Class
There’s a lot of information (including sample routines) on how to serialize/deserialize objects in C#. Hunt down a couple of routines that accept generic types and add them to your personal utility class and reuse them forever. Be aware, however, that there’s an issue with serializing nullable types. Basically it can’t be done if an [...]
My favorite TSQL Function is COALESCE which returns the first non-null expression among its arguments. If all arguments are null, null is returned. Here are a couple of simple examples: declare @a varchar(25); set @a = null; declare @b varchar(25); set @b = null; declare @c varchar(25); set @c = ‘I am not null’; select [...]
You are familiar with System.IO.Path.Combine() method which combines two path strings and manages the trailing separator character (a.k.a. a backslash (“\”)), right? Here’s an example of what I am talking about: System.IO.Path.Combine(“C:\temp”, “subdir\file.txt”);// output = “c:\temp\subdir\file.txt” Are you bored yet? Okay, pop quiz. In my current project, I need to download a file and [...]
The following defect was logged yesterday: Each day at 4pm PST our users are denied seamless access into [third party website]. Though I am sure the author of the code may be of another opinion, aren’t these types of defects kind of fun? They are like brain-teasers which you want to solve without looking at [...]
After hours of discussions and documentation, we had a good understanding of the functional requirements. The ask was for a very complex, intelligent and “AJAXy” web application which would give financial advisors the ability to rebalance their clients’ portfolios based on a specified investment objective. Everyone was excited (especially me) until the final requirement was [...]
Continue reading about Undo Functionality with a Limited Stack
My current focus is on stabilizing about a dozen applications which I recently inherited. By “stabilizing” I mean I am in the process of cleaning up, documenting and fixing somebody else’s code. These applications have been in existence for years. They were first coded in Classic ASP, then rewritten in .NET 1.1 and finally ported over to [...]