Exemplo n.º 1
0
        /// <summary>
        /// Returns feature set with everything true, all features enabled
        /// </summary>
        /// <returns></returns>
        public static FeatureSet GetExperimental()
        {
            FeatureSet answer = new FeatureSet();

            var type       = answer.GetType();
            var properties = type.GetRuntimeProperties();

            // Set all properties to true
            foreach (var p in properties.Where(i => i.PropertyType == typeof(bool)))
            {
                p.SetValue(answer, true);
            }

            return(answer);
        }
Exemplo n.º 2
0
        public static FeatureSet Get(DeviceFamily deviceFamily, int buildNumber)
        {
            if (buildNumber == int.MaxValue)
            {
                return(GetExperimental());
            }

            FeatureSet answer = new FeatureSet();

            var type       = answer.GetType();
            var properties = type.GetRuntimeProperties();

            // Look through all boolean properties
            foreach (var p in properties.Where(i => i.PropertyType == typeof(bool)))
            {
                var supportedIn = p.GetCustomAttributes <SupportedInAttribute>().Where(i => i.GetType() == typeof(SupportedInAttribute)).FirstOrDefault();

                // If we're in a build where that exists
                if (supportedIn != null && buildNumber >= supportedIn.MinVersion.Build)
                {
                    p.SetValue(answer, true);
                }

                // If it's device-family specific
                switch (deviceFamily)
                {
                case DeviceFamily.Mobile:
                    var mobileSupportedIn = p.GetCustomAttribute <MobileSupportedInAttribute>();
                    if (mobileSupportedIn != null && buildNumber >= mobileSupportedIn.MinVersion.Build)
                    {
                        p.SetValue(answer, true);
                    }
                    break;

                case DeviceFamily.Desktop:
                    var desktopSupportedIn = p.GetCustomAttribute <DesktopSupportedInAttribute>();
                    if (desktopSupportedIn != null && buildNumber >= desktopSupportedIn.MinVersion.Build)
                    {
                        p.SetValue(answer, true);
                    }
                    break;
                }
            }

            return(answer);
        }