Ejemplo n.º 1
0
 public void Unbind(Type service)
 {
     this.NotBeDisposed();
     Should.NotBeNull(service, "service");
     _injector.Unbind(service);
 }
Ejemplo n.º 2
0
        private static void Register([NotNull] IBindingMemberProvider memberProvider)
        {
            Should.NotBeNull(memberProvider, "memberProvider");
            RegisterMenuMembers(memberProvider);
            RegisterViewMembers(memberProvider);
#if !API8
            RegisterActionBarMembers(memberProvider);
            //Dialog
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Dialog, object>("Title",
                                                                                              (dialog, args) => dialog.SetTitle(args.NewValue.ToStringSafe())));
#endif
            //Activity
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Activity, string>("Title",
                                                                                                (activity, args) => activity.Title = args.NewValue, getDefaultValue: (activity, info) => activity.Title));
            //to suppress message about parent property.
            memberProvider.Register(AttachedBindingMember.CreateMember <Activity, object>(AttachedMemberConstants.Parent, (info, activity) => null, null));

            //CompoundButton
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <CompoundButton, bool>("Checked", (info, btn) => btn.Checked,
                                                                         (info, btn, value) => btn.Checked = value, "CheckedChange"));

            //RatingBar
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <RatingBar, float>("Rating", (info, btn) => btn.Rating,
                                                                     (info, btn, value) => btn.Rating = value, "RatingBarChange"));

            //AdapterView
            _rawAdapterMember = memberProvider.GetBindingMember(typeof(AdapterView), "RawAdapter", false, true);
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <AdapterView, int?>(AttachedMemberNames.DropDownItemTemplate,
                                                                            ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <AdapterView, int?>(AttachedMemberNames.DropDownItemTemplateSelector,
                                                                            ViewGroupTemplateChanged));
            memberProvider.Register(AdapterViewSelectedItemMember);
            memberProvider.Register(AdapterViewSelectedPositionMember);
            memberProvider.Register(ScrollToSelectedItemMember);

            //ViewGroup
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ViewGroup, IEnumerable>(AttachedMemberConstants.ItemsSource, ViewGroupItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ViewGroup, int?>(AttachedMemberConstants.ItemTemplate, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ViewGroup, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector, ViewGroupTemplateChanged));

            memberProvider.Register(ContentMember);
            memberProvider.Register(ContentTemplateIdMember);
            memberProvider.Register(ContentTemplateSelectorMember);
#if !API8
            memberProvider.Register(AddToBackStackMember);
#endif

            //TabHost
            memberProvider.Register(TabHostSelectedItemMember);
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, IEnumerable>(AttachedMemberConstants.ItemsSource, TabHostItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, int?>(AttachedMemberConstants.ItemTemplate, TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector,
                                                                                         TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, int?>(AttachedMemberConstants.ContentTemplate, TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, IDataTemplateSelector>(AttachedMemberConstants.ContentTemplateSelector,
                                                                                         TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <TabHost.TabSpec, string>("Title",
                                                                                                       (spec, args) => spec.SetIndicator(args.NewValue)));


            //DatePicker
            var selectedDateMember = AttachedBindingMember.CreateMember <DatePicker, DateTime>("SelectedDate",
                                                                                               (info, picker) => picker.DateTime, (info, picker, value) => picker.DateTime = value,
                                                                                               ObserveSelectedDate, SelectedDateMemberAttached);
            memberProvider.Register(selectedDateMember);
            memberProvider.Register("DateTime", selectedDateMember);

            //TimePicker
            var selectedTimeMember = AttachedBindingMember.CreateMember <TimePicker, TimeSpan>("SelectedTime", GetTimePickerValue, SetTimePickerValue, ObserveTimePickerValue);
            memberProvider.Register(selectedTimeMember);
            memberProvider.Register("Value", selectedTimeMember);

            //ImageView
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <ImageView, object>("ImageSource",
                                                                                                 (view, args) =>
            {
                if (args.NewValue == null)
                {
                    view.SetImageBitmap(null);
                    return;
                }
                var bitmap = args.NewValue as Bitmap;
                if (bitmap != null)
                {
                    view.SetImageBitmap(bitmap);
                    return;
                }
                var drawable = args.NewValue as Drawable;
                if (drawable != null)
                {
                    view.SetImageDrawable(drawable);
                    return;
                }
                var uri = args.NewValue as Android.Net.Uri;
                if (uri != null)
                {
                    view.SetImageURI(uri);
                    return;
                }
                view.SetImageResource((int)args.NewValue);
            }));
        }
Ejemplo n.º 3
0
 internal static IEnumerable <Type> GetInterfaces([NotNull] this Type type)
 {
     Should.NotBeNull(type, "type");
     return(type.GetTypeInfo().ImplementedInterfaces);
 }
        private static void Register([NotNull] IBindingMemberProvider memberProvider)
        {
            Should.NotBeNull(memberProvider, "memberProvider");

            //Object
            memberProvider.Register(AttachedBindingMember.CreateMember <object, object>(AttachedMemberConstants.ItemsSource,
                                                                                        GetObjectItemsSource, SetObjectItemsSource, ObserveObjectItemsSource));

            memberProvider.Register(CollectionViewManagerMember);
            memberProvider.Register(ContentViewManagerMember);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplate));

            //Control
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Control, object>(AttachedMemberConstants.FindByNameMethod, FindByNameControlMember));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Control, bool>(AttachedMemberConstants.Focused, (info, control) => control.Focused, null, "LostFocus"));

            //Registering parent member as attached to avoid use the BindingExtensions.AttachedParentMember property.
            var parentMember = memberProvider.GetBindingMember(typeof(Control), AttachedMemberConstants.Parent, true, false);

            if (parentMember != null)
            {
                memberProvider.Register(typeof(Control), parentMember, true);
            }

            memberProvider.Register(ContentMember);
            memberProvider.Register(ContentTemplateMember);

            //DateTimePicker
            memberProvider.Register(AttachedBindingMember.CreateMember <DateTimePicker, DateTime>("Value",
                                                                                                  (info, picker) => picker.Value,
                                                                                                  (info, picker, value) =>
            {
                if (value < picker.MinDate)
                {
                    picker.Value = picker.MinDate;
                }
                else if (value > picker.MaxDate)
                {
                    picker.Value = picker.MaxDate;
                }
                else
                {
                    picker.Value = value;
                }
            }, "ValueChanged"));

            //ToolStripItem
            memberProvider.Register(AttachedBindingMember.CreateMember <ToolStripItem, object>(AttachedMemberConstants.Parent,
                                                                                               GetParentToolStripItem, null, ObserveParentMemberToolStripItem));
            memberProvider.Register(AttachedBindingMember.CreateMember <ToolStripItem, object>(AttachedMemberConstants.FindByNameMethod,
                                                                                               FindByNameMemberToolStripItem));

            //TabControl
            memberProvider.Register(AttachedBindingMember.CreateMember <TabControl, object>(AttachedMemberConstants.SelectedItem,
                                                                                            GetSelectedItemTabControl, SetSelectedItemTabControl, "Selected"));

            //ComboBox
            memberProvider.Register(
                AttachedBindingMember.CreateMember <ComboBox, object>(AttachedMemberConstants.ItemsSource,
                                                                      (info, box) => box.DataSource,
                                                                      (info, box, value) => box.DataSource = value, "DataSourceChanged"));
            memberProvider.Register(
                AttachedBindingMember.CreateMember <ComboBox, object>(AttachedMemberConstants.SelectedItem,
                                                                      (info, box) => box.SelectedItem, (info, box, value) => box.SelectedItem = value,
                                                                      "SelectedIndexChanged"));

            //DataGridView
            memberProvider.Register(
                AttachedBindingMember.CreateMember <DataGridView, object>(AttachedMemberConstants.ItemsSource,
                                                                          (info, view) => view.DataSource, (info, view, value) =>
            {
                view.DataSource = value;
                view.Refresh();
            }, "DataSourceChanged"));
            memberProvider.Register(
                AttachedBindingMember.CreateMember <DataGridView, object>(AttachedMemberConstants.SelectedItem,
                                                                          GetSelectedItemDataGridView, SetSelectedItemDataGridView, "CurrentCellChanged"));
        }
Ejemplo n.º 5
0
 internal static bool IsDefined(this Type type, Type attributeType, bool inherit)
 {
     Should.NotBeNull(type, "type");
     return(type.GetTypeInfo().IsDefined(attributeType, inherit));
 }
Ejemplo n.º 6
0
 internal static bool IsAssignableFrom([NotNull] this Type typeFrom, [NotNull] Type typeTo)
 {
     Should.NotBeNull(typeFrom, "typeFrom");
     Should.NotBeNull(typeTo, "typeTo");
     return(typeFrom.GetTypeInfo().IsAssignableFrom(typeTo.GetTypeInfo()));
 }
Ejemplo n.º 7
0
 public static MethodInfo GetMethodEx([NotNull] this Type type, string name, Type[] types)
 {
     Should.NotBeNull(type, "type");
     return(type.GetRuntimeMethod(name, types));
 }
Ejemplo n.º 8
0
 internal static AssemblyName GetAssemblyName(this Assembly assembly)
 {
     Should.NotBeNull(assembly, "assembly");
     return(new AssemblyName(assembly.FullName));
 }
Ejemplo n.º 9
0
 public static MethodInfo[] GetMethodsEx([NotNull] this Type type, MemberFlags flags = MemberFlags.Public | MemberFlags.Static | MemberFlags.Instance)
 {
     Should.NotBeNull(type, "type");
     return(type.GetMethods(flags.ToBindingFlags()));
 }
Ejemplo n.º 10
0
 public static FieldInfo GetFieldEx([NotNull] this Type type, string name, MemberFlags flags = MemberFlags.Public | MemberFlags.Static | MemberFlags.Instance)
 {
     Should.NotBeNull(type, "type");
     return(type.GetField(name, flags.ToBindingFlags()));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets an object that represents the method represented by the specified delegate.
 /// </summary>
 /// <returns>
 /// An object that represents the method.
 /// </returns>
 /// <param name="del">The delegate to examine.</param>
 public static MethodInfo GetMethodInfo([NotNull] this Delegate del)
 {
     Should.NotBeNull(del, "del");
     return(del.Method);
 }