void AddGeneratedArgument(Type argumentType, ArgumentDirection direction, ActivityWithResult expression)
        {
            Argument argument = ActivityUtilities.CreateArgument(argumentType, direction);

            argument.Expression = expression;
            RuntimeArgument runtimeArgument = this.metadata.CurrentActivity.AddTempAutoGeneratedArgument(argumentType, direction);

            Argument.TryBind(argument, runtimeArgument, this.metadata.CurrentActivity);
        }
        private void CreateArgument(LocationReference sourceReference)
        {
            RuntimeArgument argument = new RuntimeArgument(NameGenerator.Next(), sourceReference.Type, ArgumentDirection.In);
            Argument        binding  = ActivityUtilities.CreateArgument(sourceReference.Type, ArgumentDirection.In);

            binding.Expression = ActivityUtilities.CreateLocationReferenceValue(sourceReference);
            this.Bind(binding, argument);
            this.activity.AddTempAutoGeneratedArgument(argument);
        }
Пример #3
0
 public static Argument Create(Type type, ArgumentDirection direction)
 {
     return(ActivityUtilities.CreateArgument(type, direction));
 }
Пример #4
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 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);
     }
 }