1 #region MIT license
2 //
3 // MIT license
4 //
5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 // THE SOFTWARE.
24 //
25 #endregion
26 
27 using System.Collections;
28 using System.Linq;
29 using DbLinq.Util;
30 
31 namespace DbLinq.Schema.Dbml.Adapter
32 {
33     /// <summary>
34     /// Wraps a CSV string to an array
35     /// </summary>
36 #if !MONO_STRICT
37     public
38 #endif
39     class CsvArrayAdapter : ArrayAdapter<string>
40     {
CsvArrayAdapter(object o, string fieldName)41         public CsvArrayAdapter(object o, string fieldName)
42             : base(o, fieldName)
43         {
44         }
45 
46         /// <summary>
47         /// The value here comes from a CSV string, ie "A,B,C"
48         /// So we split around the commas and trim
49         /// </summary>
50         /// <returns></returns>
GetValue()51         protected override IEnumerable GetValue()
52         {
53             var values = MemberInfo.GetMemberValue(Owner) as string;
54             if (values == null)
55                 return new string[0];
56             var splitValues = values.Split(',');
57             var trimmedSplitValues = from v in splitValues select v.Trim();
58             return trimmedSplitValues;
59         }
60 
61         /// <summary>
62         /// The value type is an array of string
63         /// </summary>
64         /// <returns></returns>
GetValueType()65         protected override System.Type GetValueType()
66         {
67             return typeof(string[]);
68         }
69 
70         /// <summary>
71         /// To set a unique value, we just join the parts
72         /// </summary>
73         /// <param name="value"></param>
SetValue(IEnumerable value)74         protected override void SetValue(IEnumerable value)
75         {
76             var values = value.Cast<string>().ToArray();
77             var joinedValues = string.Join(",", values);
78             MemberInfo.SetMemberValue(Owner, joinedValues);
79         }
80     }
81 }
82