From 20f0dc40cdbe85ab7cfedd78a9bc883e4469e4ab Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 28 Jan 2018 13:32:33 +0200 Subject: DAL Observables are now also parameterized. --- .../ExtensionMethods/DependencyObjectExtensions.cs | 19 +++++++++++++++++++ .../ExtensionMethods/IParameterizedExtensions.cs | 22 +++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods') diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs index 565582318..3e7da4cfb 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs @@ -125,6 +125,25 @@ public static class DependencyObjectExtensions return binding; } + /// + /// Binds the specified dependency property to a another object property. + /// + /// The target dependency object. + /// The target dependency property. + /// The source object. + /// The source dependency property name. + /// Binding mode. + /// + public static Binding Bind(this DependencyObject target, DependencyProperty targetDP, Object source, String sourcePath, BindingMode mode = BindingMode.Default) + { + Binding binding = new Binding(); + binding.Mode = mode; + binding.Source = source; + binding.Path = new PropertyPath(sourcePath); + BindingOperations.SetBinding(target, targetDP, binding); + return binding; + } + /// /// Clears bindings from the specified dependency property. /// diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs index 7a7ae103d..7b8264cae 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs @@ -47,14 +47,17 @@ public static class IParameterizedExtensions { foreach (var prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { - var paramAtt = prop.GetCustomAttributes(typeof(ParameterItemAttribute), false).Cast().FirstOrDefault(); - var ignore = prop.GetCustomAttributes(typeof(ParameterIgnoreAttribute), false).Cast().FirstOrDefault(); - - if (ignore == null && !properties.Exists(x => x.Name == prop.Name)) + if (prop.PropertyType.IsPrimitive || prop.PropertyType == typeof(String) || prop.PropertyType == typeof(DateTime)) { - var item = instance.CreateParameterItem(prop, paramAtt, index++, mode); - ps.Add(item); - properties.Add(prop); + var paramAtt = prop.GetCustomAttributes(typeof(ParameterItemAttribute), false).Cast().FirstOrDefault(); + var ignore = prop.GetCustomAttributes(typeof(ParameterIgnoreAttribute), false).Cast().FirstOrDefault(); + + if (ignore == null && !properties.Exists(x => x.Name == prop.Name)) + { + var item = instance.CreateParameterItem(prop, paramAtt, index++, mode); + ps.Add(item); + properties.Add(prop); + } } } } @@ -77,10 +80,10 @@ public static class IParameterizedExtensions item.Name = propertyInfo.Name.ToTitle(); item.Index = index; item.Type = propertyInfo.PropertyType; - item.Value = attribute.Default; if (attribute != null) { + item.Value = attribute.Default; item.Minimum = attribute.Minimum; item.Maximum = attribute.Maximum; item.CustomEditorTypeName = attribute.CustomEditorTypeName; @@ -101,9 +104,10 @@ public static class IParameterizedExtensions } else if (mode == ParameterItemMode.Binding) { - item.Bind(ParameterItem.ValueProperty, instance as DependencyObject, propertyInfo.Name, System.Windows.Data.BindingMode.TwoWay); + item.Bind(ParameterItem.ValueProperty, instance, propertyInfo.Name, System.Windows.Data.BindingMode.TwoWay); } + return item; } -- cgit v1.3.1