예제 #1
0
        public void PropertyBinderBindTest()
        {
            Source source = new Source
            {
                SourceProperty1 = 12345,
                SourceProperty2 = "Some string data"
            };

            PropertyBinder binder = new PropertyBinder
            {
                Source        = source,
                PropertyLinks = new PropertyLink[]
                {
                    new PropertyLink
                    {
                        Source = "SourceProperty1",
                        Target = "TargetProperty1"
                    },
                    new PropertyLink
                    {
                        Source = "SourceProperty2",
                        Target = "TargetProperty2"
                    }
                }
            };

            Target target = new Target();

            binder.Bind(target);

            Assert.AreEqual(source.SourceProperty1, target.TargetProperty1);
            Assert.AreEqual(source.SourceProperty2, target.TargetProperty2);
        }
예제 #2
0
            public IComparable Bind(PropertySelection selection)
            {
                string runtimeBinding = null;
                string propertyChain  = null;

                try
                {
                    runtimeBinding = data.bindingContainer.ContextBinding[selection.ContextKey];
                }
                catch (KeyNotFoundException e)
                {
                    throw new Exception("no runtime binding mapping for: " + selection.ContextKey, e);
                }

                try
                {
                    propertyChain = data.bindingContainer.ReferenceBinding[selection.ReferenceMeaning];
                }
                catch (KeyNotFoundException e)
                {
                    throw new Exception("no property chain binding mapping for: " + selection.ReferenceMeaning, e);
                }


                object         obj    = data.Contexts.Get(runtimeBinding);
                PropertyBinder binder = getPropertyBinder(propertyChain, runtimeBinding, obj);


                return(binder.Bind(obj));
            }
    private void OnEnable()
    {
        Binder    = new PropertyBinder(this);
        ViewModel = ScriptableObject.CreateInstance <VMIMGUIPanel_ViewModel1>();

        PropBindings();
        Binder.Bind(ViewModel);
    }
 public void test_bind_no_properties()
 {
   var registry = new EmptyServiceRegistry();
   var instance = new PropertyBinder(registry);
   var sample = new SampleClass();
   instance.Bind(sample);
   Assert(sample.instance == null);
 }
예제 #5
0
    public void test_bind_no_properties()
    {
        var registry = new EmptyServiceRegistry();
        var instance = new PropertyBinder(registry);
        var sample   = new SampleClass();

        instance.Bind(sample);
        Assert(sample.instance == null);
    }
 public void test_bind_property()
 {
   var registry = new FixedServiceRegistry();
   var impl = new ImplA();
   registry.Bound[typeof(IDepA)] = impl;
   var instance = new PropertyBinder(registry);
   var sample = new SampleClass();
   instance.Bind(sample);
   Assert(sample.instance == impl);
 }
예제 #7
0
 public IEnumerable <T> ParseExact <T>(MsExcel.Workbook workbook, Predicate <Row> predicate) where T : class
 {
     if (workbook != null)
     {
         var type           = typeof(T);
         var obj            = Activator.CreateInstance(type);
         var propertyBinder = new PropertyBinder();
         propertyBinder.Bind(obj, predicate);
         yield return(obj as T);
     }
 }
예제 #8
0
    public void test_bind_property()
    {
        var registry = new FixedServiceRegistry();
        var impl     = new ImplA();

        registry.Bound[typeof(IDepA)] = impl;
        var instance = new PropertyBinder(registry);
        var sample   = new SampleClass();

        instance.Bind(sample);
        Assert(sample.instance == impl);
    }
예제 #9
0
 /// <summary>
 /// 绑定的上下文发生改变时的响应方法
 /// 利用反射+=/-=OnValuePropertyChanged
 /// </summary>
 public virtual void OnBindingContextChanged(T oldValue, T newValue)
 {
     Binder.Unbind(oldValue);
     Binder.Bind(newValue);
 }
예제 #10
0
파일: BaseView.cs 프로젝트: junfff/mygame
 /// <summary>
 /// 绑定的上下文发生改变时的响应方法
 /// 利用反射+=/-=OnValuePropertyChanged
 /// </summary>
 public virtual void OnBindingContextChanged(T oldValue, T newValue)
 {
     Binder.Unbind(oldValue);
     Binder.Bind(newValue);
     //Debug.LogErrorFormat("OnBindingContextChanged is null? = {0}", newValue == null);
 }
예제 #11
0
 /// Bind an instance of T
 public void Bind <T>(T instance) where T : class
 {
     _binder.Bind(instance);
 }