예제 #1
0
 /// <summary>
 /// Get a value out of the dictionary, or return a default value if dictionary doesn't
 /// contain the given key.
 /// </summary>
 /// <typeparam name="TKey"></typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="dict">        The dictionary to search.</param>
 /// <param name="key">         The key to look for in <paramref name="dict"/>.</param>
 /// <param name="defaultValue">
 /// The value to return if <paramref name="key"/> does not exist in <paramref name="dict"/>.
 /// </param>
 /// <returns>
 /// If <paramref name="key"/> exists in <paramref name="dict"/>, returns the mapped value. If
 /// it doesn't, returns <paramref name="defaultValue"/>.
 /// </returns>
 /// <example><code><![CDATA[
 /// var dict = new Dictionary<string, int>
 /// {
 ///     { "a", 1 }, { "b", 2 }
 /// };
 /// dict.Get("a"); // --> 1
 /// dict.Get("b"); // --> 2
 /// dict.Get("c"); // --> 0
 /// dict.Get("d", 3); // --> 3
 /// ]]></code></example>
 public static TValue Get <TKey, TValue>(this IDictionary <TKey, TValue> dict, TKey key, TValue defaultValue = default)
 {
     if (key is null)
     {
         return(defaultValue);
     }
     else if (dict?.ContainsKey(key) == true)
     {
         return(dict[key]);
     }
     else
     {
         return(defaultValue);
     }
 }
예제 #2
0
    protected override void OnPageEncountered(Uri url, System.Collections.Generic.IDictionary <string, string> query, System.Collections.Generic.IDictionary <string, string> fragment)
    {
        // Remove state from dictionaries.
        // We are ignoring request state forgery status
        // as we're hitting an ASP.NET service which forwards
        // to a third-party OAuth service itself
        if (query.ContainsKey("state"))
        {
            query.Remove("state");
        }

        if (fragment.ContainsKey("state"))
        {
            fragment.Remove("state");
        }

        base.OnPageEncountered(url, query, fragment);
    }
예제 #3
0
    /// <summary>
    /// Call InitUnit at Monobehavior.Awake().
    /// Put all kinds of data into dictionary.
    /// </summary>
    public void InitUnitData()
    {
        HP = MaxHP;
        if (AttackData != null)
        {
            foreach (AttackData attackData in AttackData)
            {
                AttackDataDict.Add(attackData.Name, attackData);
            }
        }
        if (MoveData != null)
        {
            foreach (MoveData moveData in MoveData)
            {
                MoveDataDict.Add(moveData.Name, moveData);
            }
        }
        if (IdleData != null)
        {
            foreach (IdleData idleData in IdleData)
            {
                IdleDataDict.Add(idleData.Name, idleData);
            }
        }
        if (EffectData != null)
        {
            foreach (EffectData effectData in EffectData)
            {
                EffectDataDict.Add(effectData.Name, effectData);
            }
        }
        if (RotateData != null)
        {
            foreach (RotateData rotateData in RotateData)
            {
                RotateDataDict.Add(rotateData.Name, rotateData);
            }
        }
        if (ReceiveDamageData != null)
        {
            foreach (ReceiveDamageData receiveDamageData in ReceiveDamageData)
            {
                foreach (DamageForm _form in receiveDamageData.ApplicableDamageForm)
                {
                    if (ReceiveDamageDataDict.ContainsKey(_form) == false)
                    {
                        System.Collections.Generic.IList <ReceiveDamageData> L = new System.Collections.Generic.List <ReceiveDamageData> ();
                        L.Add(receiveDamageData);
                        ReceiveDamageDataDict [_form] = L;
                    }
                    else
                    {
                        ReceiveDamageDataDict [_form].Add(receiveDamageData);
                    }
                }
            }
        }

        if (DeathData != null)
        {
            foreach (DeathData dieData in DeathData)
            {
                foreach (DamageForm _damageForm in dieData.ApplicableDamageForm)
                {
                    if (DeathDataDict.ContainsKey(_damageForm) == false)
                    {
                        System.Collections.Generic.IList <DeathData> L = new System.Collections.Generic.List <DeathData> ();
                        L.Add(dieData);
                        DeathDataDict [_damageForm] = L;
                    }
                    else
                    {
                        DeathDataDict [_damageForm].Add(dieData);
                    }
                }
            }
        }

        if (DecalData != null)
        {
            foreach (DecalData decal in DecalData)
            {
                DecalDataDict.Add(decal.Name, decal);
            }
        }

        if (AudioData != null)
        {
            foreach (AudioData audioData in AudioData)
            {
                this.AudioDataDict.Add(audioData.Name, audioData);
            }
        }
    }
예제 #4
0
 /// <summary>
 /// Determines whether the dictionary contains an element with the specified key.
 /// </summary>
 /// <param name="key">The key to locate in the dictionary.</param>
 /// <returns>true if the dictionary contains an element with the key; otherwise, false.</returns>
 public bool ContainsKey(TKey key)
 {
     return(_data.ContainsKey(key));
 }