Exemplo n.º 1
0
        /// <summary>
        /// Checks if the type of value for the given feature is T.
        /// </summary>
        /// <typeparam name="T">Type of value for the feature key.</typeparam>
        /// <param name="key">The name of the feature.</param>
        /// <returns>True if type of value for the given feature is T, otherwise false.</returns>
        internal static bool Is <T>(string key)
        {
            Interop.SystemInfo.SystemInfoValueType valueType;
            Interop.SystemInfo.SystemInfoType      keyType = GetValueType(key, out valueType);
            if (keyType == Interop.SystemInfo.SystemInfoType.None)
            {
                return(false);
            }

            switch (valueType)
            {
            case Interop.SystemInfo.SystemInfoValueType.Bool:
                return(typeof(T) == typeof(bool));

            case Interop.SystemInfo.SystemInfoValueType.Double:
                return(typeof(T) == typeof(double));

            case Interop.SystemInfo.SystemInfoValueType.Int:
                return(typeof(T) == typeof(int));

            case Interop.SystemInfo.SystemInfoValueType.String:
                return(typeof(T) == typeof(string));
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the string value of the feature.
        /// </summary>
        /// <param name="key">The name of the feature.</param>
        /// <param name="value">The value of the given feature.</param>
        /// <returns>Returns true on success, otherwise false.</returns>
        /// <since_tizen> 3 </since_tizen>
        public static bool TryGetValue(string key, out string value)
        {
            Interop.SystemInfo.SystemInfoValueType valueType;
            Interop.SystemInfo.SystemInfoType      keyType = GetValueType(key, out valueType);

            InformationError err = InformationError.InvalidParameter;

            if (keyType == Interop.SystemInfo.SystemInfoType.platform)
            {
                err = Interop.SystemInfo.SystemInfoGetPlatformString(key, out value);
            }
            else if (keyType == Interop.SystemInfo.SystemInfoType.Custom)
            {
                err = Interop.SystemInfo.SystemInfoGetCustomString(key, out value);
            }
            else
            {
                value = string.Empty;
            }

            if (err != InformationError.None)
            {
                Log.Warn(InformationErrorFactory.LogTag, string.Format("Failed to get value for key: {0}. err = {1}", key, err));
                return(false);
            }

            return(true);
        }