c# INotifyPropertyChanged

來源:互聯網
上載者:User

標籤:vue   his   log   edit   app   pre   false   let   property   

<!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(/\n/)                        .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 INotifyPropertyChangedprotected 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 nameprotected 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

 

c# INotifyPropertyChanged

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.