.Net 3.5 Compatibility

Nov 20, 2013 at 4:18 PM
Hi guys,

This is a really great set of tools! We're looking at this project as a potential replacement for some homegrown measures that we've been using for processing EDI files and generating acknowledgements. It looks like this should be pretty simple to back-port to .Net 3.5 (mostly writing overloads to mimic the defaults that are in use and a few other basic changes) but I was wondering if anyone has done this before and the degree of success / pain points you've encountered.
Coordinator
Nov 20, 2013 at 9:07 PM
There are only 2 things that will break that you will need to resolve.

There are a few usages of string.IsNullOrWhitespace and there is some code that was added so the loading of the specifications for the assembly is multi-threaded.

If you rewrite those to areas you should be able to get a version that compiles to .NET 3.5.
Nov 21, 2013 at 12:30 AM
The IsNullOrWhitespace was pretty easy to work around, just ran a regex replace.

string.IsNullOrWhiteSpace(([^)]*))
(String.IsNullOrEmpty($1) || $1.Trim().Length == 0)

The concurrency was trickier but in this context of use replacing the concurrent dictionary with a regular dictionary and using the existing synclock object works well since the only exposure of the ConcurrentDictionary can be emulated with a dictionary in a threadsafe way. I made the changes below to the appropriate section of SpecificationFinder.cs
        private static readonly Dictionary<string, TransactionSpecification> _specifications;

        static SpecificationFinder()
        {
            lock (syncObject)
                _specifications = new Dictionary<string, TransactionSpecification>();
        }

        internal static TransactionSpecification GetSpecification(string specKey)
        {
            lock (syncObject)
            {
                if (!_specifications.ContainsKey(specKey))
                {
                    Stream specStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(String.Format("OopFactory.X12.Specifications.Ansi-{0}Specification.xml", specKey));
                    _specifications.Add(specKey, TransactionSpecification.Deserialize(new StreamReader(specStream).ReadToEnd()));
                }
                return _specifications[specKey];
            }
        }
    }
Marked as answer by retroelectron on 11/20/2013 at 4:36 PM