]> O.S.I.I.S - jp/crow.git/commitdiff
add a static Parse method in ObservableList<T>, use semicolumn as separator
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 25 Mar 2021 11:42:10 +0000 (12:42 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 25 Mar 2021 11:42:10 +0000 (12:42 +0100)
Crow/src/IML/Node.cs
Crow/src/ObservableList.cs

index d984c8a8cdc7357ac72da19704721745569934e1..811cfd6d4dc5ee74ed99f0055f4caf9364539232 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+// Copyright (c) 2013-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
@@ -66,23 +66,11 @@ namespace Crow.IML
                }
 #endregion
 
-               public bool HasTemplate {
-                       get { return typeof (TemplatedControl).IsAssignableFrom (CrowType);}
-               }
-               public bool IsTemplatedGroup {
-                       get { return typeof (TemplatedGroup).IsAssignableFrom (CrowType);}
-               }
-               public bool HasDataSourceType {
-                       get { return DataSourceType != null; }
-               }
+               public bool HasTemplate => typeof (TemplatedControl).IsAssignableFrom (CrowType);               
+               public bool IsTemplatedGroup => typeof (TemplatedGroup).IsAssignableFrom (CrowType);
+               public bool HasDataSourceType => DataSourceType != null;
 
-               public static implicit operator string (Node sn)
-               {
-                       return sn.ToString ();
-               }
-               public override string ToString ()
-               {
-                       return string.Format ("{0}.{1}", CrowType.FullName, Index);
-               }
+               public static implicit operator string (Node sn) => sn.ToString ();
+               public override string ToString () => string.Format ("{0}.{1}", CrowType.FullName, Index);
        }
 }
index e87226cdf5036ba81f1f9591b53c24f78d5e2662..6d7b71c751704f018d1a7f4a25ba5f694d96c7a9 100644 (file)
@@ -1,4 +1,5 @@
-// Copyright (c) 2013-2019  Bruyère Jean-Philippe jp_bruyere@hotmail.com
+using System.Reflection;
+// Copyright (c) 2013-2019  Bruyère Jean-Philippe jp_bruyere@hotmail.com
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
@@ -95,6 +96,21 @@ namespace Crow
                public void RaiseEditAt (int index) {
                        ListEdit.Raise (this, new ListChangedEventArg (index, this[index]));
                }
+
+
+               public static ObservableList<T> Parse (string str) {
+                       ObservableList<T> tmp = new ObservableList<T>();
+                       Type t = typeof(T);
+                       MethodInfo miParse = t.GetMethod ("Parse", BindingFlags.Static | BindingFlags.Public,
+                                                       Type.DefaultBinder, new Type [] {typeof (string)}, null);
+                       if (miParse == null)
+                               throw new Exception ("no Parse method found for: " + t.FullName);
+                       if (!string.IsNullOrEmpty (str)) {
+                               foreach (string s in str.Split(';'))
+                                       tmp.Add((T)miParse.Invoke (null, new object[] {s}));                            
+                       }
+                       return tmp;
+               }
        }
 }