国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
            }
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍林郭勒市| 阳高县| 温宿县| 温州市| 宣化县| 河南省| 抚宁县| 张家港市| 柳河县| 江山市| 黄冈市| 买车| 天气| 凤山县| 青冈县| 承德县| 永春县| 琼中| 仁寿县| 安顺市| 鱼台县| 珠海市| 隆尧县| 沈丘县| 青铜峡市| 仙桃市| 绥德县| 临安市| 公主岭市| 安多县| 遵义县| 乐陵市| 唐海县| 太保市| 城市| 嘉禾县| 府谷县| 富蕴县| 鄂伦春自治旗| 惠水县| 沙田区|