C# 獲取屬性名的方法
更新時間:2013年03月01日 11:11:33 作者:
C# 獲取屬性名的方法實例,需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
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;
}
}
}
}
相關(guān)文章
C#實現(xiàn)將RTF轉(zhuǎn)為HTML的示例代碼
RTF文檔即富文本格式(Rich?Text?Format)的文檔。我們在處理文件時,遇到需要對文檔格式進行轉(zhuǎn)換時,可以將RTF轉(zhuǎn)為其他格式,如轉(zhuǎn)為DOCX/DOC、PDF或者HTML。本文將利用C#實現(xiàn)RTF轉(zhuǎn)HTML,需要的可以參考一下2022-04-04c#使用Socket發(fā)送HTTP/HTTPS請求的實現(xiàn)代碼
這篇文章主要介紹了c#使用Socket發(fā)送HTTP/HTTPS請求的實現(xiàn)代碼,需要的朋友可以參考下2017-09-09C#模擬http 發(fā)送post或get請求的簡單實例
下面小編就為大家?guī)硪黄狢#模擬http 發(fā)送post或get請求的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06使用checked語句防止數(shù)據(jù)溢出的解決方法
本篇文章是對用checked語句防止數(shù)據(jù)溢出的解決方法進行了詳細的分析介紹,需要的朋友參考下2013-05-05