Reading Code

Tiny C# clean-up improves understanding of the code

I’m starting to collect small fragments from everyday life to understand and increase understanding and readability of code I’m coming across. First piece in this category is gone which I came across while contributing to one of the open source modules. Original fragment: { IEnumerable btypes = GetBlockTypes(); List blockproperties = new List(); int x = 0; foreach (BlockType type in btypes) { x = 0; foreach (PropertyDefinition def in type.PropertyDefinitions) { x++; blockproperties.Add(new TypePropertyResultItem { TypeName = x == 1 ? type.Name : “”, PropertyName = def.Name, Description = def.TranslateDescription(), DisplayName = def.TranslateDisplayName() }); } } return blockproperties; } Modified…

Keep reading