private static bool TryGetGuidKey(IReadOnlyKeyValueCollection parameters, out GuidKey key)
        {
            if (parameters.TryGet("Type", out string type) && parameters.TryGet("Guid", out Guid guid))
            {
                key = GuidKey.Create(guid, type);
                return(true);
            }

            key = null;
            return(false);
        }
        private static bool TryGetInt64Key(IReadOnlyKeyValueCollection parameters, out Int64Key key)
        {
            if (parameters.TryGet("Type", out string type) && parameters.TryGet("ID", out long id))
            {
                key = Int64Key.Create(id, type);
                return(true);
            }

            key = null;
            return(false);
        }
        private static bool TryGetStringKey(IReadOnlyKeyValueCollection parameters, out StringKey key)
        {
            if (parameters.TryGet("Type", out string type) && parameters.TryGet("Identifier", out string identifier))
            {
                key = StringKey.Create(identifier, type);
                return(true);
            }

            key = null;
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Reads the value of <paramref name="key"/> in <paramref name="collection"/>.
        /// If value is found and can be converted to <typeparamref name="T"/>, returns it.
        /// Otherwise returns <paramref name="defaultValue"/> (if provided) or throws <see cref="InvalidOperationException"/>.
        /// </summary>
        /// <param name="collection">Collection of key-value pairs.</param>
        /// <param name="key">Requested key.</param>
        /// <param name="defaultValue">Optional default value if is not found or not convertible.</param>
        /// <returns>Value of <paramref name="key"/> in <paramref name="collection"/>.</returns>
        public static T Get <T>(this IReadOnlyKeyValueCollection collection, string key, T defaultValue)
        {
            Ensure.NotNull(collection, "collection");

            T value;

            if (collection.TryGet(key, out value))
            {
                return(value);
            }

            return(defaultValue);
        }
コード例 #5
0
        /// <summary>
        /// Reads the value of <paramref name="key"/> in <paramref name="collection"/>.
        /// If value is found and can be converted to <typeparamref name="T"/>, returns it.
        /// Otherwise throws <see cref="InvalidOperationException"/>.
        /// </summary>
        /// <param name="collection">Collection of key-value pairs.</param>
        /// <param name="key">Requested key.</param>
        /// <param name="defaultValue">Optional default value if is not found or not convertible.</param>
        /// <returns>Value of <paramref name="key"/> in <paramref name="collection"/>.</returns>
        public static T Get <T>(this IReadOnlyKeyValueCollection collection, string key)
        {
            Ensure.NotNull(collection, "collection");

            T value;

            if (collection.TryGet(key, out value))
            {
                return(value);
            }

            throw Ensure.Exception.InvalidOperation("Collection doesn't contain value of type '{0}' with key '{1}'.", typeof(T), key);
        }
コード例 #6
0
        /// <summary>
        /// Returns <c>true</c> if <paramref name="collection"/> contains <paramref name="key"/>.
        /// </summary>
        /// <param name="collection">Collection of key-value pairs.</param>
        /// <param name="key">Requested key.</param>
        /// <returns><c>true</c> if <paramref name="collection"/> contains <paramref name="key"/>; otherwise <c>false</c>.</returns>
        public static bool Has(this IReadOnlyKeyValueCollection collection, string key)
        {
            Ensure.NotNull(collection, "collection");
            Ensure.NotNull(key, "key");

            if (collection.Keys.Contains(key))
            {
                return(true);
            }

            object value;

            return(collection.TryGet(key, out value));
        }
コード例 #7
0
 public void Load(IReadOnlyKeyValueCollection storage, object output)
 {
     // TODO: Not TryGet, UserKey is required!
     if (output is UserEvent payload)
     {
         if (storage.TryGet(Name.UserKey, out IKey userKey))
         {
             payload.UserKey = userKey;
         }
         else
         {
             payload.UserKey = StringKey.Empty("User");
         }
     }
 }
            public bool TryGet <T>(string key, out T value)
            {
                Ensure.NotNullOrEmpty(key, "key");

                if (keyType != null && key == "Type")
                {
                    value = (T)(object)keyType;
                    return(true);
                }

                if (prefix != null)
                {
                    key = prefix + key;
                }

                return(inner.TryGet(key, out value));
            }
コード例 #9
0
        public bool TryGet <T>(string key, out T value)
        {
            Ensure.NotNull(key, "key");

            object sourceValue;

            if (TryGetValue(key, out sourceValue) && sourceValue != null)
            {
                return(ConvertTo(sourceValue, out value));
            }

            if (parentCollection != null)
            {
                if (parentCollection.TryGet <T>(key, out value))
                {
                    return(true);
                }
            }

            return(TryGetDefault(key, out value));
        }
コード例 #10
0
 public static bool TryGetIsAutoFocus(this IReadOnlyKeyValueCollection metadata, out bool value)
 {
     return(metadata.TryGet("IsAutoFocus", out value));
 }
コード例 #11
0
 public static bool TryGetLabel(this IReadOnlyKeyValueCollection metadata, out string value)
 {
     return(metadata.TryGet("Label", out value));
 }
コード例 #12
0
 public static bool TryGetGridRowSpan(this IReadOnlyKeyValueCollection metadata, out int value)
 {
     Ensure.NotNull(metadata, "metadata");
     return(metadata.TryGet("Grid.RowSpan", out value));
 }