zoukankan      html  css  js  c++  java
  • c# INotifyPropertyChanged

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <div id="app">
            <textarea v-model="input"></textarea>
            <button @click="submit">submit</button>
            <div contenteditable="true">
                <pre v-for="item in items">
                    protected {{ item.type }} _{{ item.name }};
                    public {{ item.type }} {{ item.name }}
                    {
                        get { return this._{{ item.name }}; }
                        set
                        {
                            SetField(ref this._{{ item.name }}, value);
                        }
                    }
                </pre>
            </div>
        </div>
    
        <script src="http://cdn.bootcss.com/vue/2.1.6/vue.min.js"></script>
    
        <script>
            new Vue({
                el: '#app',
                data() {
                    return {
                        items: [],
                        input: null,
                    }
                },
                methods: {
                    submit() {
                        let lines = this.input
                            .split(/
    /)
                            .map(t => t.trim().split(' '))
                            .filter(t => t.length > 6)
    
                        this.items = []
    
                        lines.forEach(arr => {
                            this.items.push({
                                name: arr[2],
                                type: arr[1],
                            })
                        })
                    }
                }
            })
        </script>
    </body>
    </html>

    #region INotifyPropertyChanged
    
    protected void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
            handler(this, e);
    }
    
    public event PropertyChangedEventHandler PropertyChanged;
    
    protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        //C# 6 null-safe operator. No need to check for event listeners
        //If there are no listeners, this will be a noop
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
    
    // C# 5 - CallMemberName means we don't need to pass the property's name
    protected bool SetField<T>(ref T field, T value,
    [CallerMemberName] string propertyName = null)
    {
        if (EqualityComparer<T>.Default.Equals(field, value))
            return false;
        field = value;
        OnPropertyChanged(propertyName);
        return true;
    }
    
    #endregion
  • 相关阅读:
    awk如何替换一个字符串的第n个字符?
    开启停止wifi热点bat脚本
    启停无线网卡bat脚本
    批量查找ip地址归属地脚本
    测试域名ping延迟脚本
    多线程FTP下载日志脚本
    社交网站好友储存设计和实现(PHP+MySQL)
    Python强化训练笔记(二)——元组元素的命名
    Python强化训练笔记(一)——在列表,字典,集合中筛选数据
    Android Studio安装配置
  • 原文地址:https://www.cnblogs.com/ChobitsSP/p/7452217.html
Copyright © 2011-2022 走看看