亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

擴展屬性應用

系統 1982 0

字段去除空格

代碼

       [AttributeUsage(AttributeTargets.Property,Inherited=
      
        false
      
      ,AllowMultiple=
      
        false
      
      )]
      
public class TrimAttribute:Attribute
{ private readonly Type type;
public TrimAttribute(Type type)
{
this .type = type;
}
public Type Type
{
get { return this .type; }
}
}
public static class TrimAttributeExtension
{
public static void Trim( this Object obj)
{
Type t = obj.GetType();
foreach ( var prop in t.GetProperties())
{
foreach ( var attr in prop.GetCustomAttributes( typeof (TrimAttribute), true ))
{
TrimAttribute tsa = (TrimAttribute)attr;
if (prop.GetValue(obj, null )!= null &&(tsa.Type== typeof ( string )))
{
prop.SetValue(obj,GetPropertyValue(obj,prop.Name).ToString().Trim(), null );
}
}
}
}
private static object GetPropertyValue( object instance, string PropertName)
{
return instance.GetType().InvokeMember(PropertName,System.Reflection.BindingFlags.GetProperty, null ,instance, new Object[]{});
}
}

使用

      
        public
      
      
        class
      
       SomeClass
      
{ [Trim( typeof ( string ))]
string Name { get ; set ; }
}


查詢語法

      
        public
      
      
        class
      
       SelectClass
      
{
public void Method1()
{
int [] fool= new int [ 100 ];
for ( int num = 0 ; num < fool.Length; num++)
{
fool[num] = num * num;
}
foreach ( int i in fool)
{
Console.WriteLine(i.ToString());
}
}
public void Method1Select()
{
int [] fool = ( from n in Enumerable.Range( 0 , 100 ) select n * n).ToArray();
fool.ForAll((n) => Console.WriteLine(n));
}
public IEnumerable<Tuple< int , int >> ProduceIndices()
{
for ( int x = 0 ; x < 100 ; x++)
for ( int y = 0 ; y < 100 ; y++)
if (x + y < 100 )
yield return Tuple.Create(x,y);
}
public IEnumerable<Tuple< int , int >> ProduceIndicesSelect()
{
return from x in Enumerable.Range( 0 , 100 )
from y in Enumerable.Range( 0 , 100 )
where x + y < 100
select Tuple.Create(x,y);
}
}

public static class Extensions
{
public static void ForAll<T>( this IEnumerable<T> sequence, Action<T> action)
{
foreach (T item in sequence)
{
action(item);
}
}
}



擴展屬性應用


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 2021国产精品自产拍在线 | 久久中文字幕2021精品 | www.午夜色| 奇米888影视 | 欧美中文字幕视频 | 国产一级在线观看www色 | 亚洲国产欧美精品一区二区三区 | 91精品国产免费网站 | 久久777国产线看是看精品 | 国产国语高清在线视频二区 | 国产精品伦视频观看免费 | 妖精视频一区二区三区 | 久草国产视频 | 男人的天堂久久精品激情 | 国产一区二区三区不卡免费观看 | 婷婷色在线播放 | 国产成人久久久精品一区二区三区 | 手机看片国产欧美日韩高清 | 9i9精品国产免费久久 | 国内在线播放 | 色视频网 | 离线枕边人在线观看 | 天天操夜夜嗨 | 色拍拍噜噜噜aⅴ在线观看 色拍拍欧美视频在线看 | 国产欧美精品一区二区三区-老狼 | 夜夜爱夜夜爽夜夜做夜夜欢 | 亚洲一区在线视频 | 午夜精品久久影院蜜桃 | 亚洲狠狠色丁香婷婷综合 | 国产在线麻豆精品 | 日本一级大黄毛片免费基地 | 一区二区亚洲视频 | 国产精品久久久久影视不卡 | 丝袜亚洲精品中文字幕一区 | 日韩欧美h | 黄色的网站在线观看 | 天天视频国产免费入口 | 性欧美视频| 国产乱人免费视频 | 亚洲久久久久 | 一区二区三区四区五区 |