예제 #1
0
 protected MemberBuilder(IMemberBuilder parent, IMember member)
 {
     Parent     = parent;
     Member     = member;
     Assignment = new AssignmentFrame {
         Builder = this
     };
 }
예제 #2
0
        object AssignFrame(object instance, AssignmentFrame currentFrame)
        {
            object assignedValue;
            var    hasChildren = currentFrame.Children.Any();

            instance = currentFrame.Builder.Apply(instance, out assignedValue);

            object newValue = assignedValue;

            foreach (var childFrame in currentFrame.Children.Values)
            {
                newValue = AssignFrame(newValue, childFrame);
            }

            if (hasChildren && currentFrame.Builder.Value != newValue)
            {
                var oldValue = currentFrame.Builder.Value;
                currentFrame.Builder.TrySetValue(newValue);
                instance = currentFrame.Builder.Apply(instance, out assignedValue);
                currentFrame.Builder.TrySetValue(oldValue);
            }
            return(instance);
        }
예제 #3
0
        public virtual IPropertyBuilder GetProperty(string propertyPath)
        {
            if (PropertiesCache.ContainsKey(propertyPath))
            {
                return(PropertiesCache[propertyPath]);
            }

            lock (PropertiesCache)
            {
                var property = Member.FindPropertyByPath(propertyPath);

                if (property == null)
                {
                    return(PropertiesCache[propertyPath] = null);
                }

                var currentFrame = Assignment;
                foreach (var member in property.GetCallStack().OfType <IProperty>().Reverse())
                {
                    if (currentFrame.Children.ContainsKey(member))
                    {
                        currentFrame = currentFrame.Children[member];
                        continue;
                    }

                    currentFrame.Children.Add(member,
                                              currentFrame = new AssignmentFrame
                    {
                        Builder = member.CreateBuilder(currentFrame.Builder)
                    });
                }

                var lastProperty = (IPropertyBuilder)currentFrame.Builder;
                PropertiesCache[propertyPath] = lastProperty;
                return(lastProperty);
            }
        }