internal static CodeTypeDeclaration GenerateEnum(CodeTypeDeclaration typeDeclaration, string proposedName, string description, IEnumerable <string> enumValues, IEnumerable <string> enumDescriptions) { // Add the comments to the values if possible, or create empty ones. IEnumerable <KeyValuePair <string, string> > enumEntries = DecoratorUtil.GetEnumerablePairs( enumValues, enumDescriptions); return(GenerateEnum(typeDeclaration, proposedName, description, enumEntries)); }
public void GetEnumerablePairsTest() { string[] keys = new[] { "a", "b", "c" }; string[] values = new[] { "1", "2", "3" }; string[] invalidSized = new[] { "1", "2", "3", "x", "y" }; // Test parameter validation. Assert.Throws <ArgumentNullException>( () => DecoratorUtil.GetEnumerablePairs((string[])null, values).First()); Assert.DoesNotThrow(() => DecoratorUtil.GetEnumerablePairs(keys, (string[])null).First()); Assert.Throws <ArgumentException>(() => DecoratorUtil.GetEnumerablePairs(keys, invalidSized).First()); Assert.Throws <ArgumentException>(() => DecoratorUtil.GetEnumerablePairs(invalidSized, values).First()); // Test simple operation. IEnumerable <KeyValuePair <string, string> > joined = DecoratorUtil.GetEnumerablePairs(keys, values); Assert.AreEqual(3, joined.Count()); foreach (KeyValuePair <string, string> pair in joined) { Assert.AreEqual(pair.Key[0] - 'a', pair.Value[0] - '1'); } }