.net 3.5の場合、弾丸を噛むだけで、最もクリーンなソリューションになります。
public struct Wave{
public X time;
public Y enable;
}
public static Wave GetWaveAnimation()
{
try
{
return (from element in configurations.Elements("Animation")
where element.Attribute("NAME").Value == "Wave"
select new Wave
{
time = element.Attribute("TIMING").Value,
enable = element.Attribute("ENABLED").Value
}).FirstOrDefault();
}
catch { return null; }
}
.net 4.0では、動的キーワードを使用できます(ただし、匿名型は内部であるため、アセンブリまたはフレンドアセンブリの外部からこのメソッドを呼び出すことはできません)。
public static dynamic GetWaveAnimation()
{
try
{
return (from element in configurations.Elements("Animation")
where element.Attribute("NAME").Value == "Wave"
select new
{
time = element.Attribute("TIMING").Value,
enable = element.Attribute("ENABLED").Value
}).FirstOrDefault();
}
catch { return null; }
}
または、タプルオプションがあります
public static Tuple<X,Y> GetWaveAnimation()
{
try
{
return (from element in configurations.Elements("Animation")
where element.Attribute("NAME").Value == "Wave"
select Tuple.Create(
element.Attribute("TIMING").Value,
element.Attribute("ENABLED").Value
)
}).FirstOrDefault();
}
catch { return null; }
}