Test setting cap value in wpf sample.

This commit is contained in:
soukoku
2014-11-14 22:52:07 -05:00
parent b4865c988e
commit c35e727cdb
4 changed files with 93 additions and 533 deletions

View File

@@ -1,4 +1,8 @@
using NTwain.Data;
using NTwain;
using NTwain.Data;
using System.Collections;
using System.Linq;
using System.Reflection;
namespace Tester.WPF
{
@@ -7,7 +11,57 @@ namespace Tester.WPF
/// </summary>
class CapVM
{
public CapabilityId Cap { get; set; }
DataSource _ds;
object _wrapper;
MethodInfo _getMethod;
MethodInfo _getCurrentMethod;
MethodInfo _setMethod;
public CapVM(DSVM ds, CapabilityId cap)
{
_ds = ds.DS;
Cap = cap;
Supports = ds.DS.CapQuerySupport(cap);
var capName = cap.ToString();
var wrapProperty = ds.DS.GetType().GetProperty(capName);
if (wrapProperty != null)
{
_wrapper = wrapProperty.GetGetMethod().Invoke(ds.DS, null);
var wrapperType = _wrapper.GetType();
_getMethod = wrapperType.GetMethod("Get");
_getCurrentMethod = wrapperType.GetMethod("GetCurrent");
_setMethod = wrapperType.GetMethods().FirstOrDefault(m => m.Name == "Set");
}
}
public IEnumerable Get()
{
if (_getMethod == null)
{
return _ds.CapGet(Cap);
}
return _getMethod.Invoke(_wrapper, null) as IEnumerable;
}
public object GetCurrent()
{
if (_getMethod == null)
{
return _ds.CapGetCurrent(Cap);
}
return _getCurrentMethod.Invoke(_wrapper, null);
}
public void Set(object value)
{
if (_setMethod != null && value != null)
{
_setMethod.Invoke(_wrapper, new object[] { value });
}
}
public object MyProperty { get; set; }
public CapabilityId Cap { get; private set; }
public string Name
{
@@ -21,11 +75,12 @@ namespace Tester.WPF
}
}
public QuerySupports Supports { get; set; }
public QuerySupports Supports { get; private set; }
public override string ToString()
{
return Name;
}
}
}