Пример #1
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            textField = ViewHelpers.GetView <UIKit.UITextField> (nativeView);

            if (textField == null)
            {
                throw new InvalidOperationException("Cannot convert " + nativeView + " to UITextField");
            }

            if (options.HasFlag(BindOptions.PreserveNativeProperties))
            {
                text        = textField.Text;
                placeholder = textField.Placeholder;
                enabled     = textField.Enabled;
            }
            else
            {
                textField.Text        = text;
                textField.Placeholder = placeholder;
                textField.Enabled     = enabled;
            }

            textField.ValueChanged += TextField_ValueChanged;
        }
Пример #2
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            switchControl = ViewHelpers.GetView <NSButton> (nativeView);
            switchControl.SetButtonType(NSButtonType.Switch);
            switchControl.AllowsMixedState = false;

            if (options.HasFlag(BindOptions.PreserveNativeProperties))
            {
                isChecked = switchControl.State == NSCellStateValue.On;
                enabled   = switchControl.Enabled;
            }
            else
            {
                switchControl.State   = isChecked ? NSCellStateValue.On : NSCellStateValue.Off;
                switchControl.Enabled = enabled;
            }

            switchControl.Activated += SwitchControl_Activated;
        }
Пример #3
0
 internal static VarDecl Bound(LocalSymbol loc, Expr initializer, BindOptions opt)
 {
     return(new VarDecl(null, null, null, null, AssignExpr.Bound(IdExpr.Bound(loc), initializer, opt))
     {
         Symbol = loc
     });
 }
Пример #4
0
        internal static TypeSymbol ConvertResult(ref Expr e1, ref Expr e2, BindOptions options)
        {
            var conv1 = Conversion(e1, e2.Datatype, options);
            var conv2 = Conversion(e2, e1.Datatype, options);

            if (!conv1.Exists && conv2.Exists)
            {
                Convert(ref e2, e1.Datatype, conv2);
                return(e1.Datatype);
            }
            if (conv1.Exists && !conv2.Exists)
            {
                Convert(ref e1, e2.Datatype, conv1);
                return(e2.Datatype);
            }
            if (conv1.Exists && conv2.Exists)
            {
                int cost1 = conv1.Cost;
                int cost2 = conv2.Cost;
                if (cost1 <= cost2 && e1.Datatype.NativeType != NativeType.Usual)
                {
                    Convert(ref e1, e2.Datatype, conv1);
                    return(e2.Datatype);
                }
                else
                {
                    Convert(ref e2, e1.Datatype, conv2);
                    return(e1.Datatype);
                }
            }
            Convert(ref e1, Compilation.Get(NativeType.Usual), options);
            Convert(ref e2, Compilation.Get(NativeType.Usual), options);
            return(Compilation.Get(NativeType.Usual));
        }
Пример #5
0
 public IEnumerable <IBinder> this[BindOptions option]
 {
     get
     {
         return(this.Items.Find(option));
     }
 }
Пример #6
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            editText = ViewHelpers.GetView <Android.Widget.EditText> (nativeView);

            if (options.HasFlag(BindOptions.PreserveNativeProperties))
            {
                text        = editText.Text;
                placeholder = editText.Hint;
                enabled     = editText.Enabled;
            }
            else
            {
                editText.Text    = text;
                editText.Hint    = placeholder;
                editText.Enabled = enabled;
            }

            editText.TextChanged += EditText_TextChanged;
        }
Пример #7
0
        protected IEnumerable <BindThumb> GetBindThumbs(BindOptions option)
        {
            switch (option)
            {
            case BindOptions.Input:
                return(InputThumbs);

            case BindOptions.Output:
                return(OutputThumbs);

            case BindOptions.Parameter:
                return(ParameterThumbs);

            case BindOptions.Return:
                return(ReturnThumbs);

            case BindOptions.Output | BindOptions.Return:
                return(OutputThumbs.Concat(ReturnThumbs));

            case BindOptions.Input | BindOptions.Parameter:
                return(InputThumbs.Concat(ParameterThumbs));
            }

            return(Enumerable.Empty <BindThumb>());
        }
Пример #8
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            textField = ViewHelpers.GetView <NSTextField> (nativeView);

            if (options.HasFlag(BindOptions.PreserveNativeProperties))
            {
                text        = textField.StringValue;
                placeholder = textField.PlaceholderString;
                enabled     = textField.Enabled;
            }
            else
            {
                textField.StringValue       = text;
                textField.PlaceholderString = placeholder;
                textField.Enabled           = enabled;
            }

            textField.Changed += TextField_Changed;
        }
Пример #9
0
        public void BindToNative(object native, BindOptions options = BindOptions.None)
        {
            UnbindFromNative();

            if (View == null)
            {
                return;
            }

            View.BindToNative(native, options);

            controller = native as UIViewController;
            if (controller != null)
            {
                var toolItems = tools.Select(x => CreateToolItem(x)).ToArray();
                controller.NavigationItem.RightBarButtonItems = toolItems;

                if (AddButton != null)
                {
                    controller.NavigationItem.LeftBarButtonItem = CreateAddItem(AddButton);
                }
                else
                {
                    controller.NavigationItem.LeftBarButtonItem = null;
                }

                controller.Title = Title ?? "";
            }
        }
Пример #10
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            switchControl = ViewHelpers.GetView <UISwitch> (nativeView);

            if (switchControl == null)
            {
                throw new InvalidOperationException("Cannot convert " + nativeView + " to UISwitch");
            }

            if (options.HasFlag(BindOptions.PreserveNativeProperties))
            {
                isChecked = switchControl.On;
                enabled   = switchControl.Enabled;
            }
            else
            {
                switchControl.On      = isChecked;
                switchControl.Enabled = enabled;
            }

            switchControl.ValueChanged += SwitchControl_ValueChanged;
        }
Пример #11
0
        static void Main(string[] args)
        {
            var bindAssembly = new BindAssembly();

            var binder = new BindOptions <GenericHolder <int>, IIntegerHolder>()
                         .MapProperty
                         (
                targetMethodExpression: e => e.Value,
                interfaceMethodExpression: e => e.Integer
                         )
                         .Build(bindAssembly);

            var myGenericHolder = new GenericHolder <int>();

            var integerHolder = binder.NewBind(myGenericHolder);

            myGenericHolder.Value = 5;
            WriteValues();

            integerHolder.Integer = 8;
            WriteValues();

            Console.ReadLine();

            void WriteValues()
            {
                Console.WriteLine($"Generic Holder: {myGenericHolder.Value}");
                Console.WriteLine($"Integer Holder: {integerHolder.Integer}");
            }
        }
Пример #12
0
        internal static UnaryExpr Bound(Expr expr, UnaryOperatorKind kind, BindOptions options)
        {
            var e = new UnaryExpr(expr, expr.Token);

            e.Symbol   = Binder.BindUnaryOperation(e, kind, options);
            e.Datatype = e.Symbol.Type();
            return(e);
        }
Пример #13
0
        public void ClearBinder(BindOptions option)
        {
            foreach (IBinder binder in this.Items.Find(option).ToArray())
            {
                binder.ReleaseAll();

                this.Items.Remove(binder);
            }
        }
Пример #14
0
        private bool IsValidCombinedOption(BindOptions option)
        {
            int value = (int)option;

            // 5: Input | Output
            // 10: Parameter | Return

            return(value != 5 && value != 10);
        }
Пример #15
0
 internal static new InitExpr Bound(Expr Left, Expr Right, BindOptions options)
 {
     Left.RequireInitAccess();
     Right.RequireGetAccess();
     Binder.Convert(ref Right, Left.Datatype, options);
     return(new InitExpr(Left, Left.Token, Right)
     {
         Symbol = Left.Symbol, Datatype = Left.Datatype
     });
 }
Пример #16
0
 public static Bind <TType, TInterface> Build <TType, TInterface>
 (
     this BindOptions <TType, TInterface> bindOptions,
     BindAssembly bindAssembly
 )
 => new Bind <TType, TInterface>
 (
     bindSpecifications: bindOptions.AsSpecifications(),
     bindAssembly: bindAssembly
 );
Пример #17
0
        public PBinder(IBinderHost host, BindOptions bindOption)
        {
            // Unique ID
            this.Guid = Guid.NewGuid();

            this.Host       = host;
            this.BindOption = bindOption;

            this.Items = new BinderCollection(this);
        }
Пример #18
0
        internal static IifExpr Bound(Expr cond, Expr t, Expr f, BindOptions opt)
        {
            cond.RequireGetAccess();
            t.RequireGetAccess();
            f.RequireGetAccess();
            Binder.Convert(ref cond, Compilation.Get(NativeType.Boolean), Binder.Conversion(cond, Compilation.Get(NativeType.Boolean), opt));
            var r = new IifExpr(cond, t, f, cond.Token);

            r.Datatype = Binder.ConvertResult(ref r.True, ref r.False, opt);
            return(r);
        }
Пример #19
0
 /// <inheritdoc/>
 public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
 {
     UnbindFromNative();
     tcontroller = nativeView as UITableViewController;
     if (tcontroller == null)
     {
         throw new Exception("Cannot bind FormView to " + nativeView);
     }
     tcontroller.Title = root.Text;
     WithTV(SetDelegates);
 }
Пример #20
0
        /// <summary>
        /// Creates the native object for the given cross-platform <see cref="IView"/>.
        /// </summary>
        /// <returns>The bound native object.</returns>
        /// <param name="view">View.</param>
        /// <param name="context">Android context in which to run the newly created view.</param>
        /// <param name="options">Overrides to the default behavior of BindToNative.</param>
        public static object CreateBoundNative(this IView view, Context context, BindOptions options = BindOptions.None)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            var n = view.CreateNative(context);

            view.BindToNative(n, options);
            return(n);
        }
Пример #21
0
        private bool IsCirculating(IBinder targetBinder)
        {
            BindOptions option = BindOptions.Output;

            if (targetBinder.BindOption == BindOptions.Parameter || targetBinder.BindOption == BindOptions.Return)
            {
                return(false);
            }

            return(BinderHelper.FindHostNodes(this.Host as PBinderHost, option)
                   .Contains(targetBinder.Host));
        }
Пример #22
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            this.nativeView = ViewHelpers.GetView <NativeView> (nativeView);

            SetStackConstraints();
        }
Пример #23
0
        private void SetNodeOpacity(BindOptions option, double opacity)
        {
            this.Opacity = opacity;

            foreach (var node in BinderHelper.FindHostNodes(this.Model, option))
            {
                var element = node.GetView <FrameworkElement>();

                if (element != null)
                {
                    element.Opacity = opacity;
                }
            }
        }
Пример #24
0
        public IEnumerable <IBinder> GetConnectableBinders(IBinder binder)
        {
            BindOptions pairOption = binder.GetPairOption();

            foreach (IBinder item in this[pairOption])
            {
                if (!EnsureCanBind(item, binder))
                {
                    continue;
                }

                yield return(item);
            }
        }
Пример #25
0
        /// <summary>
        /// Creates the preferred native view and binds the given <see cref="IView"/> to it.
        /// </summary>
        /// <returns>The bound native view.</returns>
        /// <param name="view">View.</param>
        /// <param name="context">Android context in which to run the newly created view.</param>
        /// <param name="options">Overrides to the default behavior of BindToNative.</param>
        public static View CreateBoundNativeView(this IView view, Context context, BindOptions options = BindOptions.None)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            var n          = view.CreateBoundNative(context, options);
            var nativeView = n as View;

            if (nativeView == null)
            {
                throw new InvalidOperationException("Cannot bind " + view + " to a native view");
            }
            return(nativeView);
        }
Пример #26
0
        protected T GetBinderModel <T>(BindOptions option, int index)
            where T : IBinder
        {
            if (this.Model != null)
            {
                IBinder binder = this.Model[option].Skip(index).FirstOrDefault();

                if (binder is T tBinder)
                {
                    return(tBinder);
                }
            }

            return(default(T));
        }
Пример #27
0
            public void Binds()
            {
                var instance = new Gluee();

                var glue = new BindOptions <Gluee, IGlue>()
                           .MapMethod(e => e.NeedsGlueing(), e => e.GlueMe())
                           .Build(new BindAssembly())

                           .NewBind(instance);

                glue.GlueMe();

                instance.MethodCalled
                .Should()
                .BeTrue();
            }
Пример #28
0
        internal static PduBase CreateBindPdu(
            uint sequenceNumber,
            BindType bindType,
            string systemId,
            string password,
            BindOptions options)
        {
            switch (bindType)
            {
                case BindType.Transmitter:
                    return new BindTransmitter(
                        sequenceNumber,
                        systemId,
                        password,
                        options.SystemType,
                        options.InterfaceVersion,
                        options.Ton,
                        options.Npi,
                        options.AddressRange);

                case BindType.Receiver:
                    return new BindReceiver(
                        sequenceNumber,
                        systemId,
                        password,
                        options.SystemType,
                        options.InterfaceVersion,
                        options.Ton,
                        options.Npi,
                        options.AddressRange);

                case BindType.Transceiver:
                    return new BindTransceiver(
                        sequenceNumber,
                        systemId,
                        password,
                        options.SystemType,
                        options.InterfaceVersion,
                        options.Ton,
                        options.Npi,
                        options.AddressRange);

                default:
                    return null;
            }
        }
Пример #29
0
        public virtual bool CanBind(IBinder targetBinder)
        {
            BindOptions option = (this.BindOption | targetBinder.BindOption);

            if (IsValidCombinedOption(option))
            {
                return(false);
            }

            if (IsCirculating(targetBinder))
            {
                return(false);
            }

            return(IsSingle ?
                   Items.Count == 0 :
                   !this.Items.Contains(targetBinder));
        }
Пример #30
0
        /// <summary>
        /// Creates an <see cref="XMLGenName"/> instance from a <see cref="QName"/>.
        /// </summary>
        /// <returns>The created <see cref="XMLGenName"/> instance.</returns>
        /// <param name="qname">A <see cref="QName"/> instance.</param>
        /// <param name="bindOptions">The binding options used in the lookup for which a generalized
        /// name must be created. The following flags are used here:
        /// <see cref="BindOptions.ATTRIBUTE"/> and <see cref="BindOptions.RUNTIME_NAME"/>.</param>
        public static XMLGenName fromQName(QName qname, BindOptions bindOptions)
        {
            bool   isAttr = (bindOptions & BindOptions.ATTRIBUTE) != 0;
            string?uri    = qname.ns.uri;
            string?localName;

            if ((bindOptions & BindOptions.RUNTIME_NAME) != 0)
            {
                localName = ASString.AS_convertString(qname.localName);
            }
            else
            {
                localName = qname.localName;
            }

            if (localName == null || localName.Length == 0)
            {
                return(new XMLGenName(uri: uri, localName: localName, isAttr: isAttr));
            }

            char firstChar = localName[0];

            if (qname.ns.isPublic && (uint)(firstChar - '0') <= 9)
            {
                NumberFormatHelper.parseArrayIndex(localName, allowLeadingZeroes: false, out uint arrindex);
                if ((int)arrindex >= 0)
                {
                    return(new XMLGenName(index: (int)arrindex, isIndex: true, isAttr: isAttr));
                }
            }

            if (firstChar == '@' && (bindOptions & BindOptions.ATTRIBUTE) == 0)
            {
                isAttr    = true;
                localName = localName.Substring(1);
            }

            if (localName.Length == 1 && localName[0] == '*')
            {
                localName = null;
            }

            return(new XMLGenName(uri: uri, localName: localName, isAttr: isAttr));
        }
Пример #31
0
        /// <inheritdoc/>
        public void BindToNative(object nativeView, BindOptions options = BindOptions.None)
        {
            if (nativeView == null)
            {
                throw new ArgumentNullException("nativeView");
            }

            UnbindFromNative();

            label = ViewHelpers.GetView <UILabel> (nativeView);

            if (options.HasFlag(BindOptions.PreserveNativeProperties))
            {
                text = label.Text;
            }
            else
            {
                label.Text = text;
            }
        }
Пример #32
0
        internal Task<BindResult> Bind(BindType type, string systemId, string password, BindOptions options)
        {
            EnsureOpen();

            var sequence = GetNextSequenceNumber();
            var pdu = BindHelper.CreateBindPdu(sequence, type, systemId, password, options);
            var task = _taskRegistry.Register<BindResult>(sequence);

            _pduSender.Enqueue(pdu);
            return task.GetTask<BindResult>();
        }