vendredi 30 septembre 2016

Tool to Automatically Wrap C# classes? [on hold]

Say I have:

public class SelectedEvent
{
    private bool m_isSelected;
    public ProxSafeEventType Event { get; set; }
    public string Text => Event.ToLocalizedString();

    public bool IsSelected
    {
        get
        {
            return m_isSelected;
        }
        set
        {
            if (m_isSelected != value)
            {
                m_isSelected = value;
                OnPropertyChanged(nameof(IsSelected));
            }
        }
    }

    public SelectedEvent(ProxSafeEventType evt, bool selected)
    {
        Event = evt;
        IsSelected = selected;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged(string name)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }
}

I am looking for something that can generate something like:

    public class SelectedEventWrap
    {
        private SelectedEvent _impl;
        public virtual ProxSafeEventType Event { get { return _impl.Event} set { _impl.Event = value; } }
        public virtual string Text => _impl.Text;

        public SelectedEventWrap(SelectedEvent impl)
        {
            _impl = impl;
        }

        public virtual bool IsSelected
        {
            get
            {
                return _impl.IsSelected;
            }
            set
            {
                _imple.IsSelected = value;
            }
        }

        public virtual SelectedEvent(ProxSafeEventType evt, bool selected)
        {
            _impl.SelectedEvent(evt, selected);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string name)
        {
            _impl.OnPropertyChanged(name);
        }
}

The idea is, given a class, wrap all public members, methods, properties, etc and make everything virtual.

This makes the class very easy to mock.

Is there a tool that can generate this sort of thing?

Aucun commentaire:

Enregistrer un commentaire