예제 #1
0
        internal RuntimeArgument(string name, Type argumentType, ArgumentDirection direction, bool isRequired, List <string> overloadGroups, Argument argument)
            : this(name, argumentType, direction, isRequired, overloadGroups)
        {
            Fx.Assert(argument != null, "This ctor is only for arguments discovered via reflection in an IDictionary and therefore cannot be null.");

            // Bind straightway since we're not dealing with a property and empty binding isn't an issue.
            Argument.Bind(argument, this);
        }
        internal sealed override void OnInternalCacheMetadata(bool createEmptyBindings)
        {
            this.OnInternalCacheMetadataExceptResult(createEmptyBindings);
            bool flag = false;
            IList <RuntimeArgument> runtimeArguments = base.RuntimeArguments;
            int count = 0;

            if (runtimeArguments != null)
            {
                count = runtimeArguments.Count;
                for (int i = 0; i < count; i++)
                {
                    RuntimeArgument argument = runtimeArguments[i];
                    if (argument.Name == "Result")
                    {
                        flag = true;
                        if ((argument.Type != typeof(TResult)) || (argument.Direction != ArgumentDirection.Out))
                        {
                            base.AddTempValidationError(new ValidationError(System.Activities.SR.ResultArgumentHasRequiredTypeAndDirection(typeof(TResult), argument.Direction, argument.Type)));
                        }
                        else if (!this.IsBoundArgumentCorrect(argument, createEmptyBindings))
                        {
                            base.AddTempValidationError(new ValidationError(System.Activities.SR.ResultArgumentMustBeBoundToResultProperty));
                        }
                        else
                        {
                            base.ResultRuntimeArgument = argument;
                        }
                        break;
                    }
                }
            }
            if (!flag)
            {
                base.ResultRuntimeArgument = new RuntimeArgument("Result", typeof(TResult), ArgumentDirection.Out);
                if ((this.Result == null) && createEmptyBindings)
                {
                    this.Result = new OutArgument <TResult>();
                }
                Argument.Bind(this.Result, base.ResultRuntimeArgument);
                base.AddArgument(base.ResultRuntimeArgument, createEmptyBindings);
            }
        }
예제 #3
0
        internal void SetupBinding(Activity owningElement, bool createEmptyBinding)
        {
            if (this.bindingProperty != null)
            {
                Argument argument = (Argument)this.bindingProperty.GetValue(this.bindingPropertyOwner);

                if (argument == null)
                {
                    Fx.Assert(this.bindingProperty.PropertyType.IsGenericType, "We only support arguments that are generic types in our reflection walk.");

                    argument = (Argument)Activator.CreateInstance(this.bindingProperty.PropertyType);
                    argument.WasDesignTimeNull = true;

                    if (createEmptyBinding && !this.bindingProperty.IsReadOnly)
                    {
                        this.bindingProperty.SetValue(this.bindingPropertyOwner, argument);
                    }
                }

                Argument.Bind(argument, this);
            }
            else if (!this.IsBound)
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(owningElement);

                PropertyDescriptor targetProperty = null;

                for (int i = 0; i < properties.Count; i++)
                {
                    PropertyDescriptor property = properties[i];

                    // We only support auto-setting the property
                    // for generic types.  Otherwise we have no
                    // guarantee that the argument returned by the
                    // property still matches the runtime argument's
                    // type.
                    if (property.Name == this.Name && property.PropertyType.IsGenericType)
                    {
                        if (ActivityUtilities.TryGetArgumentDirectionAndType(property.PropertyType, out ArgumentDirection direction, out Type argumentType))
                        {
                            if (this.Type == argumentType && this.Direction == direction)
                            {
                                targetProperty = property;
                                break;
                            }
                        }
                    }
                }

                Argument argument = null;

                if (targetProperty != null)
                {
                    argument = (Argument)targetProperty.GetValue(owningElement);
                }

                if (argument == null)
                {
                    if (targetProperty != null)
                    {
                        if (targetProperty.PropertyType.IsGenericType)
                        {
                            argument = (Argument)Activator.CreateInstance(targetProperty.PropertyType);
                        }
                        else
                        {
                            argument = ActivityUtilities.CreateArgument(this.Type, this.Direction);
                        }
                    }
                    else
                    {
                        argument = ActivityUtilities.CreateArgument(this.Type, this.Direction);
                    }

                    argument.WasDesignTimeNull = true;

                    if (targetProperty != null && createEmptyBinding && !targetProperty.IsReadOnly)
                    {
                        targetProperty.SetValue(owningElement, argument);
                    }
                }

                Argument.Bind(argument, this);
            }

            Fx.Assert(this.IsBound, "We should always be bound when exiting this method.");
        }
 internal RuntimeArgument(string name, Type argumentType, ArgumentDirection direction, bool isRequired, List <string> overloadGroups, Argument argument) : this(name, argumentType, direction, isRequired, overloadGroups)
 {
     Argument.Bind(argument, this);
 }
 internal void SetupBinding(Activity owningElement, bool createEmptyBinding)
 {
     if (this.bindingProperty != null)
     {
         Argument argument = (Argument)this.bindingProperty.GetValue(this.bindingPropertyOwner);
         if (argument == null)
         {
             argument = (Argument)Activator.CreateInstance(this.bindingProperty.PropertyType);
             argument.WasDesignTimeNull = true;
             if (createEmptyBinding && !this.bindingProperty.IsReadOnly)
             {
                 this.bindingProperty.SetValue(this.bindingPropertyOwner, argument);
             }
         }
         Argument.Bind(argument, this);
     }
     else if (!this.IsBound)
     {
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(owningElement);
         PropertyDescriptor           descriptor = null;
         for (int i = 0; i < properties.Count; i++)
         {
             ArgumentDirection direction;
             Type type;
             PropertyDescriptor descriptor2 = properties[i];
             if ((((descriptor2.Name == base.Name) && descriptor2.PropertyType.IsGenericType) && (ActivityUtilities.TryGetArgumentDirectionAndType(descriptor2.PropertyType, out direction, out type) && (base.Type == type))) && (this.Direction == direction))
             {
                 descriptor = descriptor2;
                 break;
             }
         }
         Argument argument2 = null;
         if (descriptor != null)
         {
             argument2 = (Argument)descriptor.GetValue(owningElement);
         }
         if (argument2 == null)
         {
             if (descriptor != null)
             {
                 if (descriptor.PropertyType.IsGenericType)
                 {
                     argument2 = (Argument)Activator.CreateInstance(descriptor.PropertyType);
                 }
                 else
                 {
                     argument2 = ActivityUtilities.CreateArgument(base.Type, this.Direction);
                 }
             }
             else
             {
                 argument2 = ActivityUtilities.CreateArgument(base.Type, this.Direction);
             }
             argument2.WasDesignTimeNull = true;
             if (((descriptor != null) && createEmptyBinding) && !descriptor.IsReadOnly)
             {
                 descriptor.SetValue(owningElement, argument2);
             }
         }
         Argument.Bind(argument2, this);
     }
 }