private static IBindingInfoBehaviorSyntax<TSource> WithBehaviorInternal<TSource>(this IBuilderSyntax syntax,
     IBindingBehavior behavior)
 {
     Should.NotBeNull(syntax, nameof(syntax));
     Should.NotBeNull(behavior, nameof(behavior));
     syntax.Builder.GetOrAddBehaviors().Add(behavior);
     return syntax.GetOrAddSyntaxBuilder<IBindingInfoBehaviorSyntax<TSource>, object, TSource>();
 }
 internal static Exception DuplicateBehavior(IBindingBehavior oldBehavior, IBindingBehavior newBehavior)
 {
     return
         (new InvalidOperationException(
              string.Format(
                  "The binding behavior with id '{0}' is already in the collection, old value '{1}', new value '{2}'",
                  oldBehavior.Id.ToString(), oldBehavior, newBehavior)));
 }
Beispiel #3
0
        private static IBindingInfoBehaviorSyntax WithBehaviorInternal(this IBuilderSyntax syntax,
                                                                       IBindingBehavior behavior)
        {
            Should.NotBeNull(syntax, "syntax");
            Should.NotBeNull(behavior, "behavior");
            IList <IBindingBehavior> behaviors = syntax.Builder.GetOrAddBehaviors();

            behaviors.Add(behavior);
            return(syntax.Builder.GetOrAddSyntaxBuilder());
        }
Beispiel #4
0
        protected virtual void AddBehaviors(IDataBinding binding, IDataContext context)
        {
            List <IBindingBehavior> behaviors = context.GetData(BindingBuilderConstants.Behaviors);

            if (behaviors == null || behaviors.Count == 0)
            {
                for (int index = 0; index < _defaultBehaviors.Count; index++)
                {
                    binding.Behaviors.Add(_defaultBehaviors[index].Clone());
                }
                return;
            }

            int count = behaviors.Count;

            for (int index = 0; index < _defaultBehaviors.Count; index++)
            {
                IBindingBehavior behavior    = _defaultBehaviors[index];
                bool             hasBehavior = false;
                for (int i = 0; i < count; i++)
                {
                    if (behaviors[i].Id == behavior.Id)
                    {
                        hasBehavior = true;
                        break;
                    }
                }
                if (!hasBehavior)
                {
                    behaviors.Add(behavior.Clone());
                }
            }
            behaviors.Sort(BehaviorComparer);
            for (int index = 0; index < behaviors.Count; index++)
            {
                binding.Behaviors.Add(behaviors[index]);
            }
        }
 private IList<Action<IDataContext>> GetBehaviorSetter(IBindingBehavior first, IBindingBehavior second = null)
 {
     if (ReadBoolValue())
         return new Action<IDataContext>[]
         {
             context =>
             {
                 IList<IBindingBehavior> behaviors = context.GetOrAddBehaviors();
                 if (first != null)
                     behaviors.Add(first.Clone());
                 if (second != null)
                     behaviors.Add(second.Clone());
             }
         };
     return null;
 }
 internal static Exception DuplicateBehavior(IBindingBehavior oldBehavior, IBindingBehavior newBehavior)
 {
     return new InvalidOperationException($"The binding behavior with id '{oldBehavior.Id}' is already in the collection, old value '{oldBehavior}', new value '{newBehavior}'");
 }
 public static IBindingInfoBehaviorSyntax <TSource> WithBehavior <TSource>(
     [NotNull] this IBindingBehaviorSyntax <TSource> syntax,
     [NotNull] IBindingBehavior behavior)
 {
     return(syntax.WithBehaviorInternal <TSource>(behavior));
 }
 /// <summary>
 ///     Occurs when behavior removed.
 /// </summary>
 protected virtual void OnBehaviorRemoved([NotNull] IBindingBehavior behavior)
 {
 }
Beispiel #9
0
 internal static Exception DuplicateBehavior(IBindingBehavior oldBehavior, IBindingBehavior newBehavior)
 {
     return(new InvalidOperationException($"The binding behavior with id '{oldBehavior.Id}' is already in the collection, old value '{oldBehavior}', new value '{newBehavior}'"));
 }
 internal static Exception DuplicateBehavior(IBindingBehavior oldBehavior, IBindingBehavior newBehavior)
 {
     return
         new InvalidOperationException(
             string.Format(
                 "The binding behavior with id '{0}' is already in the collection, old value '{1}', new value '{2}'",
                 oldBehavior.Id.ToString(), oldBehavior, newBehavior));
 }
Beispiel #11
0
 public static IBindingInfoBehaviorSyntax WithBehavior([NotNull] this IBindingBehaviorSyntax syntax,
                                                       [NotNull] IBindingBehavior behavior)
 {
     return(syntax.WithBehaviorInternal(behavior));
 }