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
  • 相关阅读:
    POJ3624 01背包入门
    51Nod 1085 01背包
    linux配置安装tengine(centos6.5 )
    nginx列出目录
    Black and white painting
    Train Problem I
    快速排序的题
    数据结构实验之求二叉树后序遍历和层次遍历
    (转)最大子序列和问题 看着貌似不错
    数据结构实验之二叉树的建立与遍历
  • 原文地址:https://www.cnblogs.com/ChobitsSP/p/7452217.html
Copyright © 2011-2022 走看看