diff HowTo/Mapping/MapValueAttribute2.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HowTo/Mapping/MapValueAttribute2.cs	Thu Mar 27 21:46:09 2014 +0400
@@ -0,0 +1,48 @@
+using System;
+
+using NUnit.Framework;
+
+using BLToolkit.Mapping;
+
+namespace HowTo.Mapping
+{
+	[TestFixture]
+	public class MapValue2
+	{
+		public enum Gender1
+		{
+			[/*[a]*/MapValue("F")/*[/a]*/] Female,
+			[/*[a]*/MapValue("M")/*[/a]*/] Male,
+			[/*[a]*/MapValue("U")/*[/a]*/] Unknown,
+			[/*[a]*/MapValue("O")/*[/a]*/] Other
+		}
+
+		[Test]
+		public void Test1()
+		{
+			object value = Map.EnumToValue(Gender1.Male);
+
+			Assert.AreEqual("M", value);
+		}
+
+		[/*[a]*/MapValue(Gender2.Female,  1)/*[/a]*/]
+		[/*[a]*/MapValue(Gender2.Male,    2)/*[/a]*/]
+		[/*[a]*/MapValue(Gender2.Unknown, 3)/*[/a]*/]
+		[/*[a]*/MapValue(Gender2.Other,   4)/*[/a]*/]
+		public enum Gender2
+		{
+			Female,
+			Male,
+			Unknown,
+			Other
+		}
+
+		[Test]
+		public void Test2()
+		{
+			Gender2 g = Map.ToEnum<Gender2>(2);
+
+			Assert.AreEqual(Gender2.Male, g);
+		}
+	}
+}