using System.Collections; using System.Linq; namespace Developpez.Dotnet { internal static class CompatibilityHelper { public static class Enum { public static IEnumerable GetValues(System.Type type) { #if SILVERLIGHT var fields = type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); return fields.Where(f => f.IsLiteral).Select(f => f.GetValue(null)).ToArray(); #else return System.Enum.GetValues(type); #endif } } public class RegexOptions { #if SILVERLIGHT public const System.Text.RegularExpressions.RegexOptions Compiled = System.Text.RegularExpressions.RegexOptions.None; #else public const System.Text.RegularExpressions.RegexOptions Compiled = System.Text.RegularExpressions.RegexOptions.Compiled; #endif } public class Math { public static int DivRem(int a, int b, out int result) { #if SILVERLIGHT int c = a / b; result = a - (b * c); return c; #else return System.Math.DivRem(a, b, out result); #endif } public static long DivRem(long a, long b, out long result) { #if SILVERLIGHT long c = a / b; result = a - (b * c); return c; #else return System.Math.DivRem(a, b, out result); #endif } public static double Truncate(double value) { #if SILVERLIGHT return value < 0 ? System.Math.Ceiling(value) : System.Math.Floor(value); #else return System.Math.Truncate(value); #endif } public static decimal Truncate(decimal value) { #if SILVERLIGHT return decimal.Truncate(value); #else return System.Math.Truncate(value); #endif } } } }