Exemplo n.º 1
0
		public void SetGetRuntimeValue ()
		{
			object obj;
			string st = string.Empty;
			ClassProvider cp = new ClassProvider ();
			ActivityBind ab = new ActivityBind ("ClassProvider", "Name");

			obj = ab.GetRuntimeValue (cp, st.GetType ());
			Assert.AreEqual ("Hello", obj.ToString (), "C1#1");
			ab.SetRuntimeValue (cp, "Bye");

			obj = ab.GetRuntimeValue (cp, st.GetType ());
			Assert.AreEqual ("Bye", obj.ToString (), "C1#2");		
		}
        protected override object GetBoundValue(ActivityBind bind, Type targetType)
        {
            if (bind == null)
                throw new ArgumentNullException("bind");
            if (targetType == null)
                throw new ArgumentNullException("targetType");

            object returnVal = bind;
            Activity activity = this.ParentDependencyObject as Activity;
            if (activity != null)
                returnVal = bind.GetRuntimeValue(activity, targetType);
            return returnVal;
        }
 protected override object GetBoundValue(ActivityBind bind, Type targetType)
 {
     if (bind == null)
     {
         throw new ArgumentNullException("bind");
     }
     if (targetType == null)
     {
         throw new ArgumentNullException("targetType");
     }
     object runtimeValue = bind;
     Activity parentDependencyObject = base.ParentDependencyObject as Activity;
     if (parentDependencyObject != null)
     {
         runtimeValue = bind.GetRuntimeValue(parentDependencyObject, targetType);
     }
     return runtimeValue;
 }
        protected virtual object GetBoundValue(ActivityBind bind, Type targetType)
        {
            if (bind == null)
            {
                throw new ArgumentNullException("bind");
            }
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }
            object   runtimeValue = bind;
            Activity activity     = this.ResolveOwnerActivity();

            if (activity != null)
            {
                runtimeValue = bind.GetRuntimeValue(activity, targetType);
            }
            return(runtimeValue);
        }
Exemplo n.º 5
0
        protected virtual object GetBoundValue(ActivityBind bind, Type targetType)
        {
            Activity activity = GetActivityByClassName((Activity)this, bind.Name);

            return(bind.GetRuntimeValue(activity, targetType));
        }
Exemplo n.º 6
0
		public void GetRuntimeValueNull ()
		{
			string st = string.Empty;
			ActivityBind ab = new ActivityBind ("ClassProvider", "Name");
			object obj = ab.GetRuntimeValue (null, st.GetType ());
		}
        internal static object ResolveActivityPath(Activity refActivity, string path)
        {
            PathWalker walker;

            if (refActivity == null)
            {
                throw new ArgumentNullException("refActivity");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Length == 0)
            {
                throw new ArgumentException(SR.GetString("Error_EmptyPathValue"), "path");
            }
            object value = refActivity;
            BindRecursionContext recursionContext = new BindRecursionContext();

            if (new PathWalker {
                MemberFound = (EventHandler <PathMemberInfoEventArgs>) Delegate.Combine(walker.MemberFound, delegate(object sender, PathMemberInfoEventArgs eventArgs) {
                    if (value == null)
                    {
                        eventArgs.Action = PathWalkAction.Cancel;
                    }
                    else
                    {
                        switch (eventArgs.MemberKind)
                        {
                        case PathMemberKind.Field:
                            try
                            {
                                value = (eventArgs.MemberInfo as FieldInfo).GetValue(value);
                            }
                            catch (Exception exception)
                            {
                                value = null;
                                eventArgs.Action = PathWalkAction.Cancel;
                                if (!refActivity.DesignMode)
                                {
                                    TargetInvocationException exception2 = exception as TargetInvocationException;
                                    throw (exception2 != null) ? exception2.InnerException : exception;
                                }
                            }
                            break;

                        case PathMemberKind.Event:
                            {
                                EventInfo memberInfo = eventArgs.MemberInfo as EventInfo;
                                DependencyProperty dependencyProperty = DependencyProperty.FromName(memberInfo.Name, value.GetType());
                                if ((dependencyProperty != null) && (value is DependencyObject))
                                {
                                    if ((value as DependencyObject).IsBindingSet(dependencyProperty))
                                    {
                                        value = (value as DependencyObject).GetBinding(dependencyProperty);
                                    }
                                    else
                                    {
                                        value = (value as DependencyObject).GetHandler(dependencyProperty);
                                    }
                                }
                                break;
                            }

                        case PathMemberKind.Property:
                            if ((eventArgs.MemberInfo as PropertyInfo).CanRead)
                            {
                                DependencyProperty property2 = DependencyProperty.FromName(eventArgs.MemberInfo.Name, value.GetType());
                                if (((property2 != null) && (value is DependencyObject)) && (value as DependencyObject).IsBindingSet(property2))
                                {
                                    value = (value as DependencyObject).GetBinding(property2);
                                }
                                else
                                {
                                    try
                                    {
                                        value = (eventArgs.MemberInfo as PropertyInfo).GetValue(value, null);
                                    }
                                    catch (Exception exception3)
                                    {
                                        value = null;
                                        eventArgs.Action = PathWalkAction.Cancel;
                                        if (!refActivity.DesignMode)
                                        {
                                            TargetInvocationException exception4 = exception3 as TargetInvocationException;
                                            throw (exception4 != null) ? exception4.InnerException : exception3;
                                        }
                                    }
                                }
                                break;
                            }
                            eventArgs.Action = PathWalkAction.Cancel;
                            return;

                        case PathMemberKind.IndexedProperty:
                        case PathMemberKind.Index:
                            try
                            {
                                value = (eventArgs.MemberInfo as PropertyInfo).GetValue(value, BindingFlags.GetProperty, null, eventArgs.IndexParameters, CultureInfo.InvariantCulture);
                            }
                            catch (Exception exception5)
                            {
                                value = null;
                                eventArgs.Action = PathWalkAction.Cancel;
                                if (!refActivity.DesignMode)
                                {
                                    TargetInvocationException exception6 = exception5 as TargetInvocationException;
                                    throw (exception6 != null) ? exception6.InnerException : exception5;
                                }
                            }
                            break;
                        }
                        if (((value is ActivityBind) && !eventArgs.LastMemberInThePath) && (GetMemberType(eventArgs.MemberInfo) != typeof(ActivityBind)))
                        {
                            while (value is ActivityBind)
                            {
                                ActivityBind bind = value as ActivityBind;
                                if (recursionContext.Contains(refActivity, bind))
                                {
                                    throw new InvalidOperationException(SR.GetString("Bind_ActivityDataSourceRecursionDetected"));
                                }
                                recursionContext.Add(refActivity, bind);
                                value = bind.GetRuntimeValue(refActivity);
                            }
                        }
                    }
                })
            }.TryWalkPropertyPath(refActivity.GetType(), path))
            {
                return(value);
            }
            return(null);
        }