@@ -2,3 +2,97 @@ ServiceStack.Text.EnumMemberSerializer
22======================================
33
44Extension for ServiceStack.Text to allow using EnumMember attributes to serialize and deserialize enumerations.
5+
6+ Example
7+ ======================================
8+ #Example Configuration
9+
10+ Configure Explicit Enumerations
11+ ``` c#
12+ new EnumSerializerConfigurator ()
13+ .WithEnumTypes (new Type [] { typeof (ReturnPolicy ) })
14+ .Configure ();
15+ ```
16+
17+ Configure all enumerations in the ExampleCode namespce for all assemblies in my current app domain:
18+ ``` c#
19+ new EnumSerializerConfigurator ()
20+ .WithAssemblies (AppDomain .CurrentDomain .GetAssemblies ())
21+ .WithNamespaceFilter (ns => ns .StartsWith (" ExampleCode" ))
22+ .Configure ();
23+ ```
24+
25+ #Example Enumeration:
26+ ``` c#
27+ using System .Runtime .Serialization ;
28+
29+ namespace ExampleCode
30+ {
31+ public enum ReturnPolicy
32+ {
33+ NotSet = 0 ,
34+ [EnumMember (Value = @" 90 Days w/Receipt" )]
35+ _90DayswReceipt = 1 ,
36+ [EnumMember (Value = @" 15% Restocking Fee" )]
37+ _15RestockingFee = 2 ,
38+ [EnumMember (Value = @" Exchange Only" )]
39+ ExchangeOnly = 3 ,
40+ [EnumMember (Value = @" As-Is" )]
41+ AsIs = 4 ,
42+ ...
43+ }
44+ }
45+ ```
46+
47+ #Example Dto
48+ ``` c#
49+ namespace ExampleCode
50+ {
51+ public class ProductInfo
52+ {
53+ public string ProductName { get ; set ; }
54+ public ReturnPolicy ReturnPolicy { get ; set ; }
55+ ...
56+ }
57+ }
58+ ```
59+
60+ #Url Examples
61+
62+ These will search for all product returnable within 90 days with receipt (all of these will work):
63+ ```
64+ http://myhost/products?returnpolicy=90%20Days%20w%2FReceipt
65+ http://myhost/products?returnpolicy=90%20DaYS%20w%2FReceIPt
66+ http://myhost/products?returnpolicy=_90DayswReceipt
67+ http://myhost/products?returnpolicy=1
68+ ```
69+
70+ #Example Response
71+
72+ With ServiceStack.Text.EnumMemberSerializer you get this:
73+ ``` JSON
74+ [
75+ {
76+ "ProductName" : " Hammer" ,
77+ "ReturnPolicy" : " 90 Days w/Receipt"
78+ },
79+ {
80+ "ProductName" : " Chisel" ,
81+ "ReturnPolicy" : " 90 Days w/Receipt"
82+ }
83+ ]
84+ ```
85+
86+ Without ServiceStack.Text.EnumMemberSerializer
87+ ``` JSON
88+ [
89+ {
90+ "ProductName" : " Hammer" ,
91+ "ReturnPolicy" : " _90DayswReceipt"
92+ },
93+ {
94+ "ProductName" : " Chisel" ,
95+ "ReturnPolicy" : " _90DayswReceipt"
96+ }
97+ ]
98+ ```
0 commit comments