国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# 獲取屬性名的方法

2020-01-24 03:34:56
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication
{
    class Program
    {
        class Test
        {
            public string PropertyJustForTest1 { get; set; }
            public Test PropertyJustForTest2 { get; set; }
        }
        static void Main(string[] args)
        {
            Test test = new Test();
            Console.WriteLine(GetPropertyNameHelper.GetPropertyName<object>(() => test.PropertyJustForTest1));
            Console.WriteLine(GetPropertyNameHelper.GetPropertyName<object>(() => test.PropertyJustForTest2));
        }
    }
    static class GetPropertyNameHelper
    {
        public static string GetPropertyName<T>(Expression<Func<T>> express)
        {
            var memberExpress = express.Body as MemberExpression;
            if (memberExpress != null)
            {
                return memberExpress.Member.Name;
            }
            else
            {
                return string.Empty;
            }
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临沭县| 达尔| 金阳县| 东安县| 平度市| 霍邱县| 襄樊市| 鸡东县| 灵武市| 商南县| 南皮县| 全椒县| 扶沟县| 吉木萨尔县| 平谷区| 蚌埠市| 夏邑县| 邵武市| 托克托县| 池州市| 吉木萨尔县| 台南市| 洛宁县| 阿拉尔市| 营口市| 汝城县| 黄平县| 新昌县| 崇州市| 宁海县| 秦安县| 深水埗区| 西乌珠穆沁旗| 贡山| 顺平县| 长治县| 徐州市| 彭山县| 开原市| 株洲市| 延边|