示例#1
0
        /// <summary>
        /// Deserializes Json into a Key instance.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="objectType"></param>
        /// <param name="existingValue"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            // TODO: null checks?

            Key key = new Key((string)reader.Value);

            return key;
        }
示例#2
0
        /// <summary>
        /// Creates a new KeyScope containing the scope of the provided key.
        /// </summary>
        /// <throws>DataAccessException when key has no domain.</throws>
        /// <param name="key">The key from which the scope will be created.</param>
        /// <returns>The KeyScope</returns>
        public static KeyScope FromKey(Key key)
        {
            if (!key.Value.StartsWith(Domain, StringComparison.InvariantCulture))
            {
                // Key must have a domain in order to get a KeyScope from it.
                throw new DataAccessException(String.Format("Can't create KeyScope from key [{0}] as it has no domain.", key));
            }

            // last separator before the key segment (so we can trim it below).
            var lastSep = key.Value.LastIndexOf(Separator, StringComparison.InvariantCulture);

            // substring starts at first non-domain segment
            int subStart = Domain.Length + 1;
            int subLen = lastSep - subStart;

            return new KeyScope(key.Value.Substring(subStart, subLen));
        }
示例#3
0
 private void AddKey(Key key)
 {
     _keys.Add(key);
 }
示例#4
0
        public bool Equals(Key key)
        {
            if (key == null) return false;

            return Equals(Value, key.Value);
        }
 private void ResetInputBinding(MenuItem menu, Key key) {
     KeyConverter k = new KeyConverter();
     menu.InputGestureText = k.ConvertToString(key);
     foreach (KeyBinding item in InputBindings) {
         if (item.Key == key) {
             item.Modifiers = ModifierKeys.None;
             break;
         }
     }
 }