aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/ExtensionMethods
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-01-28 13:32:33 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-01-28 13:32:33 +0200
commit20f0dc40cdbe85ab7cfedd78a9bc883e4469e4ab (patch)
tree7356c7beb47bfa4725980af29edc9f43b878d2c4 /Software/Visual_Studio/Tango.Core/ExtensionMethods
parent08b6ea6e300ff8236594dd4f303387ef1366e49e (diff)
downloadTango-20f0dc40cdbe85ab7cfedd78a9bc883e4469e4ab.tar.gz
Tango-20f0dc40cdbe85ab7cfedd78a9bc883e4469e4ab.zip
DAL Observables are now also parameterized.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods')
-rw-r--r--Software/Visual_Studio/Tango.Core/ExtensionMethods/DependencyObjectExtensions.cs19
-rw-r--r--Software/Visual_Studio/Tango.Core/ExtensionMethods/IParameterizedExtensions.cs22
2 files changed, 32 insertions, 9 deletions
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
@@ -126,6 +126,25 @@ public static class DependencyObjectExtensions
}
/// <summary>
+ /// Binds the specified dependency property to a another object property.
+ /// </summary>
+ /// <param name="target">The target dependency object.</param>
+ /// <param name="targetDP">The target dependency property.</param>
+ /// <param name="source">The source object.</param>
+ /// <param name="sourcePath">The source dependency property name.</param>
+ /// <param name="mode">Binding mode.</param>
+ /// <returns></returns>
+ 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;
+ }
+
+ /// <summary>
/// Clears bindings from the specified dependency property.
/// </summary>
/// <param name="target">The target dependency object.</param>
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<ParameterItemAttribute>().FirstOrDefault();
- var ignore = prop.GetCustomAttributes(typeof(ParameterIgnoreAttribute), false).Cast<ParameterIgnoreAttribute>().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<ParameterItemAttribute>().FirstOrDefault();
+ var ignore = prop.GetCustomAttributes(typeof(ParameterIgnoreAttribute), false).Cast<ParameterIgnoreAttribute>().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;
}