8

Readability first I've tried to condense everything to one line, but am unsure if this is the most efficient way of approaching this problem. Your primary goal when writing code is readability and maintainability and not squeezing everything into single lines. Can you read this? return exception != null ? string.Format("{0}: {1}\n{2}", msgCount, ...


7

Your method is meant to handle ExpandoObjects explicitly, so it would be better named ConvertExpandoObjectToDictonary, and would probably be less confusing if it actually took an ExpandoObject as the parameter: Dictionary<string, object> ConvertExpandoObjectToDictonary(ExpandoObject expandoObject); This is what the public API should look like; you ...


6

Bug Your code does not handle value == null everywhere. object value = property.GetValue(obj, null); Type valueType = value.GetType(); // <- can throw the infamous NRE Review Use a clear method name RenderProperties. int tabs = 0 does not allow flexibility for rendering indents. Use string indent = "\t" instead. this T obj is fine, but I would ...


6

You should have a guard clause against someone passing in null PropertyInfo has a PropertyType and you should use that instead of Type valueType = value.GetType(); as if value is null you will get a null reference error where PropertyType will give you the type of the property. You will need to fix this line as well if value is null. Again you will ...


5

The root of the problem lies in this line: dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ where you decided to parse *.json files into an ExpandoObject and not directly into a Dictionary or some other strong type. I bet you are using Json.Net for the job and there are countless possibilities to deserialize JSON in ...


4

Note that some messages from exceptions expand to more lines (e.g. ArgumentNullException), so consider to replace new line characters while formatting the message so each exception message is written neatly in one line: exception.Message.Replace(Environment.NewLine, " ") My version would look something like: public static string GetMessageTree(this ...


4

Review If the purpose is to output each of the descendant inner exceptions, you are missing all except the first inner exception in case of an AggregateException. And this is a common exception. Don't use \n as new line unless you specifically need to comply to this style of new line. Prefer Environment.NewLine. I am not convinced of the exception != null ->...


4

Inconsistent definition of ExpandoObject. It's IDictionary<string, object> here: if (p.Value is IDictionary<string, object> dict) { return ConvertDynamicToDictonary(dict); // <- possibly already visited? } and ExpandoObject here: if (list.Any(o => o is ExpandoObject)) { // .. } I would opt to use IDictionary<string, object>...


2

A few minor stylistic bits that may increase its utility: since you take in an IDictionary, return an IDictionary. make it static as it accesses no instance data or methods. since it's now static, make it an extension method. validate the parameter passed in. Also: since it's a single return statement, make it an expression body. Further: yeah, the .Any(...


2

As you have already noticed, this can be viewed as a case of mutual recursion. To demonstrate this I give the following mutually recursive definitions: (defn sort-parts [work] (lazy-seq (sp-loop work))) (defn sp-loop [[part & parts]] (if-let [[pivot & xs] (seq part)] (sp-loop ;or recur for tco (let [smaller? #(< % pivot)] (...


2

We are far from from beta-reduction here. The "reduction" can only be understood using explicit instruction flow semantics. No. You have chosen to interpret loop and recur in this way, but that is not how Clojure understands them. recur is simply a flag for a tail-recursive call, functional as you like. loop is a gloss on defining and applying a ...


2

There is a slight difference in the order of evaluation, in that the book's solution recurses before calling consp, whereas your solution recurses after calling consp. Either way, the recursion happens before concatenation, because the innermost expressions in (append (apply #'list-of elt) (uncompress (cdr lst))) and (cons elt (uncompress (cdr lst))))))) ...


Only top voted, non community-wiki answers of a minimum length are eligible