LINQ で WMI その3
id:siokoshou:20071124 のクエリーを少しだけスッキリさせてみた。
Func<object, Dictionary<int, string>, string> map = ( o, d ) => d == null ? o.ToString() : d[ ToInt( o ) ]; var query = from ManagementObject mo in ( new ManagementClass( "Win32_CacheMemory" ) ).GetInstances() from PropertyData prop in mo.Properties join m in WmiWin32CacheMemoryMessages on prop.Name equals m.Key into mm from mes in mm.DefaultIfEmpty() select prop.Value == null ? new { prop.Name, Value = "null" } : !prop.IsArray ? new { prop.Name, Value = map( prop.Value, mes.Value ) } : new { prop.Name, Value = string.Join( ", ", ( from object o in prop.Value as Array select map( o, mes.Value ) ).ToArray() ) };
クエリー式の文法がよくわかりません!
あと、どう書いたら読みやすいのか、手探りで模索中。今のところ、慣れてないのでどう書いてもキモイw
匿名型のプロパティ名、「new { prop.Name, Value = "null" }」と書くと一つ目のプロパティ名は Name になるんでした。もう忘れてた(^^;