From: Jean-Philippe Bruyère Date: Thu, 25 Mar 2021 11:42:10 +0000 (+0100) Subject: add a static Parse method in ObservableList, use semicolumn as separator X-Git-Tag: v0.9.5-beta~54 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=e8abbc812544aee80bbefa30b89d2c9bcaae2805;p=jp%2Fcrow.git add a static Parse method in ObservableList, use semicolumn as separator --- diff --git a/Crow/src/IML/Node.cs b/Crow/src/IML/Node.cs index d984c8a8..811cfd6d 100644 --- a/Crow/src/IML/Node.cs +++ b/Crow/src/IML/Node.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2020 Jean-Philippe Bruyère +// Copyright (c) 2013-2021 Jean-Philippe Bruyère // // 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); } } diff --git a/Crow/src/ObservableList.cs b/Crow/src/ObservableList.cs index e87226cd..6d7b71c7 100644 --- a/Crow/src/ObservableList.cs +++ b/Crow/src/ObservableList.cs @@ -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 Parse (string str) { + ObservableList tmp = new ObservableList(); + 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; + } } }