Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make interface Prism.Interactivity.InteractionRequest.IInteractionRequestAware generic. #405

Closed
baterja opened this issue Jan 18, 2016 · 5 comments

Comments

@baterja
Copy link

baterja commented Jan 18, 2016

I propose making IInteractionRequestAware interface generic for convenience with binding to xaml. Now I have something like:

public abstract class BasePopupWindowViewModel<T> : IInteractionRequestAware
        where T : INotification  {

        protected T Confirmation;

        public Action FinishInteraction { get; set; }

        public INotification Notification
        {
            get { return Confirmation; }
            set { Confirmation = (T)value; }
        }
    }

to handle with custom confirmation popups. Bindings looks like:

<TextBox Text="{Binding Notification.SomePropertyExistingInMyCustomConfirmation}" />

but xaml cannot resolve property in desing-time, because only INotification properties are visible. I want to write code like:

public abstract class BasePopupWindowViewModel<T> : IInteractionRequestAware<T>
        where T : INotification  {
        public Action FinishInteraction { get; set; }

        public T Notification { get; set; }
    }

and make my custom properties visible for binding.

Only change needed is from this:

public interface IInteractionRequestAware
    {
        /// <summary>
        /// The <see cref="INotification"/> passed when the interaction request was raised.
        /// </summary>
        INotification Notification { get; set; }

        /// <summary>
        /// An <see cref="Action"/> that can be invoked to finish the interaction.
        /// </summary>
        Action FinishInteraction { get; set; }
    }

to this:

public interface IInteractionRequestAware<T> where T : INotification
    {
        /// <summary>
        /// Type implementing <see cref="INotification"/> passed when the interaction request was raised.
        /// </summary>
        T Notification { get; set; }

        /// <summary>
        /// An <see cref="Action"/> that can be invoked to finish the interaction.
        /// </summary>
        Action FinishInteraction { get; set; }
    }

and then fix all (2-3) usages of interface.

I cloned source and did it, it doesn't make any test failed.

What do You think about that?

@YounesCheikh
Copy link

+1
I like it in this way, instead of casting the notification each time.

@brianlagunas
Copy link
Member

Well, we can't change the interface definition because it would break every single Prism app out there for no real benefit. It's a good API suggestion, but it needs to be done so that it will not break anyone. Think about it a let me know if you come up with anything.

@baterja
Copy link
Author

baterja commented Jan 18, 2016

I don't think it is possible because of interface limitations in language. It will be easier to explicitly implement interface:

public abstract class BasePopupWindowViewModel : IInteractionRequestAware {
        public Action FinishInteraction { get; set; }

        public INotificationImplementer IInteractionRequestAware.Notification { get; set; }
}

but it is forbidden by language.

Maybe the other day, when some really good-but-breaking changes accumulate there will be new version of Prism incompatible with previous?

Or maybe enabling implementing interface member as I wrote will be easier and more valuable for C# developers? I will check later.

@baterja
Copy link
Author

baterja commented Jan 23, 2016

So I've checked C# 7 work list of features and something I wrote one comment earlier might be possible in the future (Covariant return types: Proposal #357).

For now I have a workaround (not clean, but working nice with bindings):

public abstract class BasePopupWindowViewModel<T> : IInteractionRequestAware 
    where T : INotification {
    private T _customConfirmation;

    public T CustomConfirmation {
        get { return _customConfirmation; }
        set { _customConfirmation = value; }
    }

    public Action FinishInteraction { get; set; }

    public INotification Notification {
        get { return _customConfirmation; }
        set { _customConfirmation = (T)value; }
    }
}

@lock
Copy link

lock bot commented Feb 1, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants