{"id":8179,"date":"2016-09-21T22:59:06","date_gmt":"2016-09-21T04:59:06","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/?p=8179"},"modified":"2016-09-21T23:26:33","modified_gmt":"2016-09-21T14:26:33","slug":"%e3%82%a2%e3%83%aa%e3%82%b9%e3%81%af%e7%84%a1%e9%99%90%e3%81%ab%e3%83%97%e3%83%a9%e3%83%80%e3%81%8b%e3%82%89%e7%8c%ab%e3%82%92%e5%8f%96%e3%82%8a%e5%87%ba%e3%81%99","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/8179","title":{"rendered":"\u30a2\u30ea\u30b9\u306f\u7121\u9650\u306b\u30d7\u30e9\u30c0\u304b\u3089\u732b\u3092\u53d6\u308a\u51fa\u3059"},"content":{"rendered":"<p>\u30a2\u30ea\u30b9\u306f\u30d7\u30e9\u30c0\u304c\u304a\u597d\u304d | Moonmile Solutions Blog<br \/>\n<a href=\"http:\/\/www.moonmile.net\/blog\/article\/alice-plada\">http:\/\/www.moonmile.net\/blog\/article\/alice-plada<\/a><\/p>\n<p>\u30a2\u30ea\u30d7\u30e9\u30b7\u30ea\u30fc\u30ba\u306e\u7b2c24\u5f3e\u3081\u306f\u3001\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u306e\u8a71&#8230;\u3068\u3044\u3046\u304b\u3001\u3068\u3042\u308b\u6797\u6a8e\u306a\u56fd\u3067\u306f for \u304c\u306a\u304f\u306a\u3063\u3066 for in \u3060\u3051\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3082\u306e\u3060\u304b\u3089\u3001\u3044\u3084\u3044\u3084\u3001\u914d\u5217\u3068\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u304c\u3054\u3063\u3061\u3083\u306b\u306a\u3063\u3066\u306a\u3044\u304b\uff1f\u3068\u601d\u3063\u3066\u4f5c\u308d\u3046\u3068\u601d\u3063\u305f\u306e\u3060\u3051\u3069\u3001\u6a2a\u9053\u306b\u9038\u308c\u3066\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3068\u3044\u3046\u8a33\u3002<\/p>\n<p>\u6700\u8fd1\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u8a00\u8a9e\u3067\u306f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u5168\u3066\u306e\u8981\u7d20\u306b\u5bfe\u3057\u3066\u4f55\u304b\u3084\u308b\u3068\u304d\u306f\u3001foreach \u3092\u4f7f\u3046\u8a33\u3067\u3059\u304c\uff08\u6797\u6a8e\u306e\u56fd\u3067\u306f for in \u3067\u3059\u306d\uff09\u3001\u3053\u308c\u306f\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u4e2d\u8eab\u306e\u3059\u3079\u3066\u306e\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3044\u3046\u3060\u3051\u3067\u3001\u7279\u306b\u9806\u5e8f\u306f\u6c7a\u307e\u3063\u3066\u3044\u307e\u305b\u3093\u3002\u307e\u3042\u3001\u5b9f\u88c5\u4e0a\u306f\u6700\u521d\u306e\u8981\u7d20\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3093\u3060\u3051\u3069\u3001Javascript \u306e\u3088\u3046\u306b\u5b9f\u306f\u3068\u3073\u3068\u3073\u3060\u3063\u305f\u308a\u3001\u305d\u3082\u305d\u3082\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3068\u914d\u5217\u306e\u9055\u3044\u3063\u3066\u305d\u3046\u3044\u3046\u300c\u9806\u5e8f\u6027\u300d\u306e\u3068\u3053\u308d\u306b\u3042\u308a\u307e\u3059\u3002\u9806\u5e8f\u304c\u4fdd\u8a3c\u3055\u308c\u3066\u3044\u306a\u3044\u3063\u3066\u3053\u3068\u3067\u3059\u306d\u3002\u9806\u5e8f\u304c\u4fdd\u8a3c\u3055\u308c\u306a\u3044\u3063\u3066\u3053\u3068\u306f\u3001\u9006\u9806\u3063\u3066\u306e\u3082\u306a\u3044\u308f\u3051\u3067\u3001\u3059\u3079\u3066\u306e\u8981\u7d20\u306b1\u56de\u305a\u3064\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3063\u3066\u3060\u3051\u3067\u3059\u3002\u5b9f\u969b\u306e\u3068\u3053\u308d\u306f\u3001\u5404\u30d7\u30ed\u30b0\u30e9\u30e0\u8a00\u8a9e\u306e\u30b9\u30da\u30c3\u30af\u306b\u3088\u308b\u306e\u3060\u308d\u3046\u3051\u3069\u3001\u914d\u5217\u3068\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u9055\u3044\u3063\u3066\u306e\u306f\u305d\u3046\u3044\u3046\u3068\u3053\u308d\u306b\u3042\u308b\u3002<br \/>\n\u306a\u306e\u3067\u3001\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092 foreach \u3067\u63a2\u7d22\u3057\u305f\u3068\u304d\u306b\u3001\u3072\u3068\u3064\u524d\u306e\u8981\u7d20\u3068\u3042\u308f\u305b\u3066\u4f55\u304b\u3059\u308b\uff08\u305f\u3068\u3048\u3070\u30d5\u30a3\u30dc\u30ca\u30c3\u30c1\u95a2\u6570\uff09\u3068\u3044\u3046\u3088\u3046\u306a\u4ed6\u306e\u8981\u7d20\u3092\u30a2\u30af\u30bb\u30b9\u3057\u3066\u9806\u5e8f\u304c\u554f\u984c\u306b\u306a\u308b\u5834\u5408\u306f\u3001\u518d\u5e30\u95a2\u6570\u3092\u4f7f\u3063\u305f\u308a\u3059\u308b\u306e\u3060\u304c\u3001\u307e\u3042\u3001\u305d\u308c\u306e\u4f8b\u3063\u307d\u3044\u3082\u306e\u3092\u793a\u3057\u3066\u304a\u3053\u3046\u3002<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u306b\u3001Bag \u30af\u30e9\u30b9\u3068 Cat \u30af\u30e9\u30b9\u3092\u4f5c\u3063\u3066\u307f\u308b\u3002\u9784\u306e\u4e2d\u306b\u306f\u732b\u304b\u9784\u3092\u5165\u308c\u3089\u308c\u308b\u3002\u9784\u306e\u4e2d\u306b\u306f\u9784\u304c\u5165\u308b\u306e\u3067\u3001\u5b9f\u306f\u7121\u9650\u306b\u9784\u304c\u5165\u308b\u3068\u3044\u4e0d\u601d\u8b70\u306a Bag \u30af\u30e9\u30b9\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u3044\u3084\u3001\u3053\u308c\u306f DOM \u3068\u4e00\u7dd2\u3067 XNode \u304c\u305d\u308c\u306e\u4ed5\u7d44\u307f\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u4e00\u822c\u7684\u306a\u30c4\u30ea\u30fc\u69cb\u9020\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nclass IObject { }\r\nclass Cat : IObject\r\n{\r\n    public string Name { get; set; }\r\n    public Cat( string name ) {\r\n        Name = name;\r\n    }\r\n}\r\nclass Bag : IObject\r\n{\r\n    public List&lt;IObject&gt; Items { get; set; }\r\n    public Bag () {\r\n        this.Items = new List&lt;IObject&gt;();\r\n    }\r\n    public Bag Add( params IObject&#x5B;] items )\r\n    {\r\n        foreach ( var it in items ) { this.Items.Add(it); }\r\n        return this;\r\n    }\r\n    \/\/ \u732b\u3060\u3051\u53d6\u308a\u51fa\u3059\r\n    public IEnumerable&lt;Cat&gt; GetCats()\r\n    {\r\n        foreach (var it in this.Items)\r\n        {\r\n            if (it is Cat)\r\n            {\r\n                yield return it as Cat;\r\n            }\r\n            if (it is Bag)\r\n            {\r\n                foreach (var ii in (it as Bag).GetCats())\r\n                {\r\n                    yield return ii;\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>Bag \u30af\u30e9\u30b9\u306b\u306f\u3001\u732b\u3060\u3051\u3092\u53d6\u308a\u3060\u3059\u305f\u3081\u306e GetCats \u30e1\u30bd\u30c3\u30c9\u304c\u3042\u3063\u3066\u3001\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u3066\u3042\u308b\u3002yield return \u3092\u4f7f\u3063\u3066\u3001\u5165\u308c\u5b50\u306b\u306a\u3063\u305f Bag \u306e\u4e2d\u3082\u63a2\u7d22\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u3002<br \/>\nAdd \u30e1\u30bd\u30c3\u30c9\u306f\u3001\u5b50\u8981\u7d20\uff08Bag \u304b Cat\uff09\u3092\u8ffd\u52a0\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3042\u3063\u3066\u3001\u3053\u308c\u306f XElement \u3068\u540c\u3058\u4ed5\u7d44\u307f\u306b\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<h2>\u732b\u306e\u307f\u53d6\u308a\u51fa\u3059<\/h2>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nBag prada = new Bag().Add(\r\n    new Cat(&quot;mike&quot;),\r\n    new Bag().Add( \r\n        new Cat(&quot;hop&quot;),\r\n        new Cat(&quot;step&quot;),\r\n        new Cat(&quot;jump&quot;)),\r\n    new Cat(&quot;kuro&quot;),\r\n    new Cat(&quot;shiro&quot;)\r\n    );\r\n\/\/ \u732b\u306e\u307f\u53d6\u308a\u51fa\u3059\r\nforeach ( var it in prada.GetCats() )\r\n{\r\n    Console.WriteLine(&quot;cat: &quot; + it.Name);\r\n}\r\n<\/pre>\n<p>prada \u306e\u9784\u306b\u3001\u732b\u3068\u9784\u3092\u5165\u308c\u308b\u3093\u3060\u3051\u3069\u3001\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068 GetCats \u30e1\u30bd\u30c3\u30c9\u3067\u7dba\u9e97\u306b\u732b\u3060\u3051\u3092\u53d6\u308a\u51fa\u305b\u308b\u3002<\/p>\n<p><a href=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2016\/09\/dworkblogimage20160921_01org.jpg\"><img decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2016\/09\/dworkblogimage20160921_01thum.jpg\" border=\"0\" \/><\/a><\/p>\n<p>\u3053\u308c\u3067\u30a2\u30ea\u30b9\u306f\u6e80\u8db3\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u7d50\u679c\u3092\u898b\u308b\u3068\u308f\u304b\u308b\u3093\u3067\u3059\u304c\u3001\u9784\u306e\u4e2d\u8eab\u3092\u53d6\u308a\u51fa\u3059\u9806\u756a\u306f\u5b9f\u88c5\u4f9d\u5b58\u306a\u306e\u3067\u3001\u3069\u3046\u3044\u3046\u9806\u756a\u3067\u732b\u304c\u51fa\u3066\u304f\u308b\u306e\u304b\u306f\u5206\u304b\u308a\u307e\u305b\u3093\u3002\u3051\u308c\u3069\u3082\u3001\u3072\u3068\u3064\u306e\u8981\u7d20\u30921\u56de\u305a\u3064\u30a2\u30af\u30bb\u30b9\u3057\u3066\u53d6\u308a\u51fa\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u7121\u9650\u306b\u732b\u3092\u53d6\u308a\u51fa\u3059<\/h2>\n<p>\u3055\u3066\u3001Bag \u30af\u30e9\u30b9\u3092\u898b\u308b\u3068\u3001Bag \u30af\u30e9\u30b9\u81ea\u8eab\u3092\u5165\u308c\u5b50\u306b\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u5b9f\u306f\u81ea\u5206\u81ea\u8eab\u3092\u8981\u7d20\u306b\u52a0\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u305d\u3046\u3001\u5faa\u74b0\u53c2\u7167\u3068\u3044\u3046\u3084\u3064\u3060\u3002<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ \u7121\u9650\u30d0\u30c3\u30af\u3092\u4f5c\u308b\r\nBag infbag = new Bag().Add(new Cat(&quot;Cheshire&quot;));\r\ninfbag.Add(infbag);\r\n\/\/ \u7121\u9650\u306b\u732b\u3092\u53d6\u308a\u51fa\u305b\u308b\r\nforeach (var it in infbag.GetCats())\r\n{\r\n    Console.WriteLine(&quot;cat: &quot; + it.Name);\r\n}\r\n<\/pre>\n<p>\u30d0\u30c3\u30b0 infbag \u3092\u4f5c\u3063\u3066\u3001\u81ea\u5206\u306e\u9784\u306b\u8ffd\u52a0\u3059\u308b\u3068\u3044\u3046\u7121\u9650\u30d0\u30c3\u30b0\u3092\u5b8c\u6210\u3055\u305b\u308b\u3002\u3067\u3082\u3063\u3066\u3001\u3053\u308c\u3082 GetCats \u30e1\u30bd\u30c3\u30c9\u3067\u53d6\u308a\u51fa\u3059\u3068\u3069\u3046\u306a\u308b\u304b\uff1f\u30a2\u30ea\u30b9\u306f\u3001\u7121\u9650\u306b\u30c1\u30a7\u30b7\u30e3\u732b\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3060\u308d\u3046\u304b\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2016\/09\/20160921_02.jpg\" alt=\"20160921_02\" width=\"659\" height=\"482\" class=\"alignnone size-full wp-image-8185\" srcset=\"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2016\/09\/20160921_02.jpg 659w, http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2016\/09\/20160921_02-300x219.jpg 300w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/p>\n<p>\u4e00\u898b\u3001\u7121\u9650\u306b\u53d6\u308a\u51fa\u305b\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u3051\u3069\u3001GetCats \u30e1\u30bd\u30c3\u30c9\u5185\u3067\u5165\u308c\u5b50\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3089\u30b9\u30bf\u30c3\u30af\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u306b\u306a\u3063\u3061\u3083\u3093\u3067\u3059\u3088\u306d\uff5e\u3001\u3061\u3083\u3093\u3061\u3083\u3093\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n<p>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u3053\u3061\u3089<br \/>\n<a href=\"https:\/\/1drv.ms\/u\/s!AmXmBbuizQkXgf0CI2eEOEnAdsI-_w\">https:\/\/1drv.ms\/u\/s!AmXmBbuizQkXgf0CI2eEOEnAdsI-_w<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30a2\u30ea\u30b9\u306f\u30d7\u30e9\u30c0\u304c\u304a\u597d\u304d | Moonmile Solutions Blog http:\/\/www.moonmile.net\/blog\/article\/alice-plada \u30a2\u30ea\u30d7\u30e9\u30b7\u30ea\u30fc\u30ba\u306e\u7b2c24\u5f3e\u3081\u306f\u3001\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u306e &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/8179\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":3060,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,23],"tags":[],"class_list":["post-8179","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","category-csharp"],"jetpack_featured_media_url":"http:\/\/www.moonmile.net\/blog\/wp-content\/uploads\/2011\/12\/title-alice.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/8179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=8179"}],"version-history":[{"count":5,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/8179\/revisions"}],"predecessor-version":[{"id":8186,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/8179\/revisions\/8186"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media\/3060"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=8179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=8179"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=8179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}