article search result of 'GetProperties' : 1

  1. 2010.12.06 [c#] 익명타입의 (열거)배열 (71)

[c#] 익명타입의 (열거)배열

 

 

생각에 시작은 이러하다 .

 

 

예를 들어 AS3에 Tweener 의 일반적인 사용법을 보면

 

Tweener.to( targetObject , 1 , { x : 100 , y : targetObject.y + 100 , rotation : 100 , scale : 1.2 }) ;

Tweener.to( ColorMatrix , 2 , { r : 2.32 , g : 32.12 , b : –42.01 , a : 0.5 });

대부분이 요러한 모양이다 .

 

첫째 줄을 해석하면 ,

 

“targetObject 를 1초 동안 x좌표를 100으로 , y 좌표를 100만큼더 , 회전을 100도 , 스케일을 20% 키워라.”

 

가 되겠고 ,

 

“둘째 줄은 컬러매트릭스를 2초동안 , 빨강을 2.32 , 초록을 32.12 , 파랑을 –42.01 , 알파를 50% 만큼 해라 . “

 

이처럼 짧고도 가독성 있는 코드를 사용한다 .

 

이처럼 C# 에서 도 비교적 짧고 가독성 있는 트윈 클래스를 만들기 위해 , { , } 에 있는 속성들을 취합하여 열거하는 기능이

필수적으로 필요 하다.

C# 에서 이와 가장 사용성으로 비슷한 것은 익명 메서드 이고 이를 취합하여 적절히 이용하려 한다.

그러나 ..

익명타입들을 배열이나 컬렉션에 넣기 위해 Object 로 캐스팅 해버리면 익명 타입안에 속성에 접근을 할수 없다.

 

 

이것은 분명 동적성향을 많이 가지고 있는 AS3 의 Object 와 다른것이다.

 

하지만 불가능한것은 아니니 ,,

 

해답은 리플렉션을 이용하는것이다.

 

 

 

          //
          // 기본
            //

            
            //익명타입 생성
            var a = new { q1 = 123 , q2 = 4345};
            
            //타입추출
            Type t = a.GetType();

            //GetProperties는 PropertyInfo라는것의 배열 형태이다.
            PropertyInfo[] pi = t.GetProperties();

            //루프
            foreach (PropertyInfo p in pi)
            {
                //출력! 
                Console.WriteLine(p.Name + "   " +p.GetValue(a , null));
            }




          //
          // 응용
            //


            //오브젝트 배열 생성
            List<Object> list = new List<object>();

            //익명타입�� 추가 (Add)
            list.Add(new { a1 = 123, a2 = 234 });
            list.Add(new { b1 = 345, b2 = 567 });

            //list를 foreach 루프로 돌리고..
            foreach (Object o in list)
            {
                //타입을 뽑아낸다.
                Type ot = o.GetType();

                //ot 안에 GetProperties는 PropertyInfo라는것의 배열 형태이다.
                //역시 foreach 루프
                foreach (PropertyInfo p in ot.GetProperties())
                {
                    //출력 ~
                    Console.WriteLine("-> " +p.Name + "   " + p.GetValue(o , null));
                }
            }

 

 

이로서 익명타입을 열거 할 수 있게 되었다.
참고 :: http://stackoverflow.com/questions/1203522/how-to-access-property-of-anonymous-type-in-c

Yamecoder 야매코더_
C# 2010. 12. 6. 17:59

댓글을 달아 주세요

  1. 이전 댓글 더보기
  2. BlogIcon moncler outlet store 2013.11.23 20:10  수정/삭제  댓글쓰기

    법히Leicester Indication An additional Murphy,kors outlet online

    Ashton Murphy for action towards Buccaneers final period

    Ireland in europe worldwide Geordan Murphy isn't any lengthier the best "Murphy" from Leicester Tigers because youthful Lansdowne power back again Ashton Murphy offers authorized for that British membership.

    Which is not only within title that we now have commonalities bet방련

  3. BlogIcon wholesale jerseys cheap 2013.11.26 13:12  수정/삭제  댓글쓰기

    우하Dec eight, Boston celtics aside overtime, however, reduction seventy six; seventeen factors at the rear of the actual Bulls within the change of the watch case, the actual pressure tugging the actual appui. Here i will discuss the both of these video games Roundup:

    Boston celtics 94-76 individuals ninety five (OT)

    76ers (11-8) to prevent three-game dropping skills. Evan -- Turner obtained twent기크

  4. BlogIcon chanel handbags online 2014.08.31 03:43  수정/삭제  댓글쓰기

    습비Shoes Using up Demo inside Arizona

    Uncover: ZSubscribe to be able to ChannelsFollow the newest films from the favored exercise. area. The particular plaza,gucci outlet store, at present beneath contract with the City related to Phoenix arizona az, is really, depending on Jones,coach outlet store online, "Being borrowed using a $50, 000 present within the Make the most of Dyrdek/DC Shoes Skate P리있

  5. BlogIcon 平焊法兰 2014.08.31 11:06  수정/삭제  댓글쓰기

    로법 ,高压三通;








    24-210-840型琉璃瓦机
    ,压瓦机的安,920压瓦机;
    压型钢板型号 24-210-840 用途
    有效覆盖宽度(mm) 840
    展开宽度(mm) 1000 屋面板、墙面板
    波高(mm) 24
    板厚(mm) 0.3-0,无缝三通相.8











    ,弯头基础知;


    来源:가데

  6. BlogIcon moncler donna 2014.09.11 04:22  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  7. BlogIcon 匿名 2014.09.11 12:19  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  8. BlogIcon moncler sale womens 2014.09.29 18:52  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  9. BlogIcon 深圳眼镜批发 2014.11.12 00:51  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  10. BlogIcon moncler womens jacket ebay 2014.11.12 11:44  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  11. BlogIcon moncler online shop japan 2014.11.12 11:46  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  12. 匿名 2014.12.03 05:44  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  13. 匿名 2015.01.07 17:46  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  14. 匿名 2015.01.15 12:20  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  15. 匿名 2015.01.26 19:48  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  16. 匿名 2015.02.11 14:03  수정/삭제  댓글쓰기

    야관传奇世界服务端刀剑服务端十二之天服务端新天骄服务端卧龙吟服务端

    真封神服务端惊天动地服务端红月服务端魔力宝贝服务端飞飞务服务端

    劲舞团服务端热血江湖服务端倚天I服务端网页游戏服务端天堂2服务端


    热血江湖开sf一条龙服务-

    传世开私服版本一条龙服务-


    传奇广告代理-

    IDC服务器以及空间租用-


    客服咨询QQ(企鹅扣扣)1207542352

    Email:1207542352@qq.com

    更多商业版本免费开放下载




    起点数据图腾变身1.950已开十六区永恒皓月淘宝商城无特戒无



    起点数据独家1.90七彩刺影狂雷合击绝杀版传奇服务端



    起点数据1.995已开四区变身皓月特殊副本积分系统太极魔阵三



    起点数据1.96黄金丛林传奇庄园聚魔禁地天地使者黄金皓月版传



    起点数메고

  17. BlogIcon vetement burberry soldes 2015.03.27 21:10  수정/삭제  댓글쓰기

    우방il n'y a pas d'erreur de gentillesse et de grandes erreurs.Yan Ming est l'histoire de notre pays pour les experts financiers. la contrainte dans la Seconde Guerre echarpe burberry soldes mondiale a &eacute;tabli des pays socialistes, mon filleul est tr&egrave;s stricte, mais peut encore tomber, vers le QG d'accepter la tche imm&eacute;diate. voil&agrave; les ennuis. la gestion du poids corporel. a조우

  18. BlogIcon Burberry sac 2015.03.31 00:03  수정/삭제  댓글쓰기

    료지Il y a une possibilit&eacute;, c'est six r&eacute;ponses les plus int&eacute;ressantes. le nombre de personnes tu&eacute;es dans des attaques des militants islamiques dans un htel de la capitale Mogadiscio s'&eacute;l&egrave;ve &agrave; au moins 15.
    2015) pour obtenir le nombre de d&eacute;c&egrave;s urlthe court &agrave; partir de la base de l'attaque dans un htel de la capitale Mogadiscio a a드련

  19. plerfrort 2015.04.04 11:59  수정/삭제  댓글쓰기

    d detailing. The embroidery has four types of stitches, three of which are variations of the running stitch, and the fourth is the cross stitch. Tradi [url=http://www.woodlawnnaturecenter.org]Isabel Marant Sale[/url] ections and scrutiny where the authorities of intellectual properties wing verify whether the product possesses distinctive qualities. The GI is grant
    f embroidery and border patches, making them totally exclusive. Unnati Silks, has trendy designs, attractive patterns, in pleasing colours and co [url=http://www.cadomel.co.uk/hollister-t-shirts-uk]hollister t shirts uk[/url] 000 57744.
    And regardless how fast paced you happen to be, do send out your father a present and give us a cell phone call or specific your gratitude j

    ing of da campanha inverno 2014 Maria Valentina: Curtiu Namoradeira? ;**
    There is nothing wrong with being into a traditional styling taste There a [url=http://www.woodlawnnaturecenter.org]Isabel Marant 2015[/url] M.G.Road, Hyderabad-500003.AP,India. 040-64555251 or 97000 57744.
    Stages of tailoring custom dress shirts When you hear from someone of designing cus
    end setting leaders in this field. With their extensive range of rings, pendants, brooches and bracelets they have revolutionized jewelry online
    shopping for North Americans. These web stores provide freedom to those who are hard pressed for time in search of gifts for loved ones or for self a
    dornment, with fabulous deals and prices as they don鈥檛 have the same overhead costs as traditional brick and mortar stores. To feel like a king
    [url=http://www.cadomel.co.uk/hollister-joggers]hollister joggers[/url] a salwar suits and Sarees, at very reasonable prices. Unnati is one of the largest Indian ethnic online websites with over 300 varieties of trad
    The woven Tussar Silk Saree has a coarse texture, is li
    ght on the body, airy and has a comfortable feel about it. However as a delicate fabric, maintenance requires a little care and attention, with dry
    [url=http://www.cadomel.co.uk/hollister-uk]hollister uk[/url] t: UNNATI SILK PRINTS PVT. LTD, #3-4-360, Vajra Complex, General Bazar (Tobacco Bazar), M.G.Road, Hyderabad-500003.AP,India. 040-64555251 or 97000 5

    http://www.fengshuishopper.com/UserFiles/best-choice--hotel-best-Rus.html
    http://akcol.com/userfiles/kitesurfing-kiteboarding--kitesur.html
    http://www.isasensing.com/site/upload/Media/best-bmx-bikes--best-lease-deals-.html
    http://www.holaportugal.net/cidadefiles/Media/best-paid-jobs--kitesurfing-board.html
    http://www.binding.bg/userfiles/best-kite-surfing--kiteboard-b.html

  20. 匿名 2015.04.05 10:19  수정/삭제  댓글쓰기

    로기Black and military green. Each shoe has a cap of products 100% nylon with white leather on the tip, with white vulcanized sole. The following is a list detailing details log on to Nike Air Max 90.



    You could in a project file for the planning office is purpose Used MBT Women's Lami investment.Find ultimate solution for intelligent and affordable new and used office furniture.


    I was rece서마

  21. 匿名 2015.04.06 01:07  수정/삭제  댓글쓰기

    야알,Online Gifts Shops - Smart Shopping Destinations_56675.

    火车采集器html简单模板示范






    Long Distance Riding Tips For Beginners







    [标签:来源]








    Long distant riding on a motorcycle can be a great challenge for someone who has never done it before. This is written to help those who are considering this challenge, to be prepared before setting off on their travel. Here are ju없법

Powerd by Tistory, designed by criuce
rss