csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Generics with object creation needs some work

Open belav opened this issue 3 years ago • 1 comments

            var someGeneric____________________________________ = new DictionaryHelper<
                string,
                ModelState
            >()
            {
                Creator = () => new ModelStateDictionary(),
                Comparer = StringComparer.OrdinalIgnoreCase,
                SampleKeys = new string[] { "foo", "bar", "baz", "quux", "QUUX" },
                SampleValues = new ModelState[]
                {
                    new ModelState(),
                    new ModelState(),
                    new ModelState(),
                    new ModelState(),
                    new ModelState()
                },
                ThrowOnKeyNotFound = false
            };

belav avatar Oct 25 '21 22:10 belav

I think I'd rather have the generic types in new never broken on several lines -- or only as a last resort if someone writes a new expression that can't stand on a line by itself (!?!).

I'd write the example above as:

            var someGeneric____________________________________ = 
                new DictionaryHelper<string, ModelState>()
                {
                    Creator = () => new ModelStateDictionary(),
                    Comparer = StringComparer.OrdinalIgnoreCase,
                    SampleKeys = new string[] { "foo", "bar", "baz", "quux", "QUUX" },
                    SampleValues = new ModelState[]
                    {
                        new ModelState(),
                        new ModelState(),
                        new ModelState(),
                        new ModelState(),
                        new ModelState(),
                    },
                    ThrowOnKeyNotFound = false,
                };

jods4 avatar May 19 '22 13:05 jods4