/// <summary> /// Initializes a new instance of the <see cref="ReflectedInformation" /> class. /// </summary> /// <param name="activity">The activity.</param> /// <param name="reflectType">Type of the reflect.</param> private ReflectedInformation(Activity activity, ReflectedType reflectType) { this.parent = activity; // reflect over our activity and gather relevant pieces of the system so that the developer // doesn't need to worry about "zipping up" his model to the constructs necessary for the // runtime to function correctly foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(activity)) { if ((reflectType & ReflectedType.Argument) == ReflectedType.Argument && ActivityUtilities.TryGetArgumentDirectionAndType(propertyDescriptor.PropertyType, out var direction, out var argumentType)) { // We only do our magic for generic argument types. If the property is a non-generic // argument type then that means the type of the RuntimeArgument should be based on // the type of the argument bound to it. The activity author is responsible for dealing // with these dynamic typing cases. if (propertyDescriptor.PropertyType.IsGenericType) { var isRequired = this.GetIsArgumentRequired(propertyDescriptor); var overloadGroupNames = this.GetOverloadGroupNames(propertyDescriptor); var argument = new RuntimeArgument( propertyDescriptor.Name, argumentType, direction, isRequired, overloadGroupNames, propertyDescriptor, activity); this.Add(ref this.arguments, argument); } }
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); } }