diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-04-28 12:20:39 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-04-28 12:20:39 +0200 |
| commit | 3437ccff71997d7cf535cded844df518ba8415f5 (patch) | |
| tree | 8c9013947c7503ecaa58726648136063eb5f0679 /CrowIDE/src/MembersView.cs | |
| parent | 6e0a061c471d5e26c4c05f168f353c4057c2f97d (diff) | |
add CrowIDE in progress to master
Diffstat (limited to 'CrowIDE/src/MembersView.cs')
| -rw-r--r-- | CrowIDE/src/MembersView.cs | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/CrowIDE/src/MembersView.cs b/CrowIDE/src/MembersView.cs new file mode 100644 index 00000000..18f1a709 --- /dev/null +++ b/CrowIDE/src/MembersView.cs @@ -0,0 +1,118 @@ +// +// MembersView.cs +// +// Author: +// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +using System; +using Crow; +using System.Xml.Serialization; +using System.ComponentModel; +using System.Reflection; +using System.Collections.Generic; + +namespace CrowIDE +{ + public class PropertyContainer : IValueChange + { + #region IValueChange implementation + public event EventHandler<ValueChangeEventArgs> ValueChanged; + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } + #endregion + + PropertyInfo pi; + object instance; + + public string Name { get { return pi.Name; }} + public object Value { + get { return pi.GetValue(instance); } + set { + try { + if (!pi.PropertyType.IsAssignableFrom(value.GetType()) && pi.PropertyType != typeof(string)){ + if (pi.PropertyType.IsEnum) { + pi.SetValue (instance, value); + } else { + MethodInfo me = pi.PropertyType.GetMethod + ("Parse", BindingFlags.Static | BindingFlags.Public, + System.Type.DefaultBinder, new Type [] {typeof (string)},null); + pi.SetValue (instance, me.Invoke (null, new object[] { value }), null); + } + }else + pi.SetValue(instance, value); + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine ("Error setting property:"+ ex.ToString()); + } + NotifyValueChanged ("Value", value); + } + } + public string Type { get { return pi.PropertyType.IsEnum ? + "System.Enum" + : pi.PropertyType.FullName; }} + public string[] Choices { + get { + return Enum.GetNames (pi.PropertyType); + } + } + + public PropertyContainer(PropertyInfo prop, object _instance){ + pi = prop; + instance = _instance; + } + + } + public class MembersView : ListBox + { + object instance; + + [XmlAttributeAttribute][DefaultValue(null)] + public virtual object Instance { + get { return instance; } + set { + if (instance == value) + return; + instance = value; + NotifyValueChanged ("Instance", instance); + + if (instance == null) { + Data = null; + return; + } + + MemberInfo[] members = instance.GetType ().GetMembers (BindingFlags.Public | BindingFlags.Instance); + + List<PropertyContainer> props = new List<PropertyContainer> (); + foreach (MemberInfo m in members) { + if (m.MemberType == MemberTypes.Property) { + PropertyInfo pi = m as PropertyInfo; + if (!pi.CanWrite) + continue; + if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null) + continue; + props.Add (new PropertyContainer (pi, instance)); + } + } + Data = props.ToArray (); + } + } + public MembersView () : base() + { + } + } +} |