public static void SetPropertyReference(object instance, string targetProperty, string sourceProperty)
        {
            Fx.Assert(instance != null, "instance should not be null.");
            Fx.Assert(!string.IsNullOrEmpty(targetProperty), "targetProperty should not be null or empty.");

            ActivityPropertyReference entry = null;
            IList<ActivityPropertyReference> references = ActivityBuilder.GetPropertyReferences(instance);

            Fx.Assert(references != null, "references should not be null");

            foreach (ActivityPropertyReference reference in references)
            {
                if (StringComparer.Ordinal.Equals(reference.TargetProperty, targetProperty))
                {
                    entry = reference;
                    break;
                }
            }

            if (string.IsNullOrEmpty(sourceProperty))
            {
                if (entry != null)
                {
                    references.Remove(entry);
                }
            }
            else
            {
                if (entry != null)
                {
                    entry.SourceProperty = sourceProperty;
                }
                else
                {
                    entry = new ActivityPropertyReference();
                    entry.TargetProperty = targetProperty;
                    entry.SourceProperty = sourceProperty;
                    references.Add(entry);
                }
            }
        }
        public static void SetPropertyReference(object instance, string targetProperty, string sourceProperty)
        {
            Fx.Assert(instance != null, "instance should not be null.");
            Fx.Assert(!string.IsNullOrEmpty(targetProperty), "targetProperty should not be null or empty.");

            ActivityPropertyReference         entry      = null;
            IList <ActivityPropertyReference> references = ActivityBuilder.GetPropertyReferences(instance);

            Fx.Assert(references != null, "references should not be null");

            foreach (ActivityPropertyReference reference in references)
            {
                if (StringComparer.Ordinal.Equals(reference.TargetProperty, targetProperty))
                {
                    entry = reference;
                    break;
                }
            }

            if (string.IsNullOrEmpty(sourceProperty))
            {
                if (entry != null)
                {
                    references.Remove(entry);
                }
            }
            else
            {
                if (entry != null)
                {
                    entry.SourceProperty = sourceProperty;
                }
                else
                {
                    entry = new ActivityPropertyReference();
                    entry.TargetProperty = targetProperty;
                    entry.SourceProperty = sourceProperty;
                    references.Add(entry);
                }
            }
        }
 protected internal override void Complete()
 {
     if (this.targetProperty == null)
     {
         // can't transform to <Foo.></Foo.>, dump original nodes <ActivityBuilder.PropertyReference(s) .../>
         this.parent.HasUntransformedChildren = true;
         this.parent.UntransformedNodesWriter.WriteStartObject(Writer.activityPropertyReferenceXamlType);
         XamlServices.Transform(this.propertyReferenceNodes.Reader, this.parent.UntransformedNodesWriter, false);
     }
     else
     {
         ActivityPropertyReference propertyReference = new ActivityPropertyReference
         {
             SourceProperty = this.sourceProperty,
             TargetProperty = this.targetProperty
         };
         parent.Parent.AddPropertyReference(propertyReference);
     }
 }
 internal void AddPropertyReference(ActivityPropertyReference propertyReference)
 {
     ObjectFrame currentFrame = this.objectStack.Peek();
     Fx.Assert(currentFrame.Type != null, "Should only create PropertyReferencesNode inside a StartObject");
     if (currentFrame.PropertyReferences == null)
     {
         currentFrame.PropertyReferences = new List<ActivityPropertyReference>();
     }
     currentFrame.PropertyReferences.Add(propertyReference);
 }