DictionaryUtils

We found 10 examples in language CSharp for this search. You will see 22 fragments of code.

		#region IDictionary implementation

		public void Add (TKey key, TValue value)
		{
			//This is multicast delegate create contiuation
			var val = DictionaryUtils.CreatePromise(stateManager,((Delegate)(object)value));
            internalDictCase5.Add(key, new CollectionStateObjectReference((IStateObject)val));
            AddReferenceIntoStateObjectSurrogate(val);
        }

		public bool TryGetValue (TKey key, out TValue value)
		{
			CollectionStateObjectReference internalValue;
			var ret = internalDictCase5.TryGetValue (key, out internalValue);
			if (ret) {

				var cont = internalValue.Target as IPromise;
				if (cont != null) {
					value = (TValue)DictionaryUtils.RetrieveDelegateFromPromise(typeof(TValue), cont);
				} else
					value = default(TValue);
				return true;
			}
			value = default(TValue);
			return false;
		}

		#endregion

		#region ICollection implementation

		public void Add (KeyValuePair<TKey, TValue> item)
		{
			//This is multicast delegate create contiuation
			var val = DictionaryUtils.CreatePromise(stateManager,(Delegate)(object)item.Value);
			internalDictCase5.Add (item.Key, new CollectionStateObjectReference ((IStateObject)val));
            AddReferenceIntoStateObjectSurrogate(val);
		}

    private static void Main() {
            Dictionary<int, float> dct = new Dictionary<int, float> {
                {1,8.65f },
                {2,7.65f },
                { 3, 8.89f },
                { 4, 8.90f },
                { 5, 7.95f }
            };
            DictionaryUtils utils = new DictionaryUtils(dct);
            Console.WriteLine($"min {utils.GetMinValue(1, 4)}\nmax {utils.GetMaxValue(1, 4)}");
            //prints -->  min 7.65 
            //            max 8.9
            
            Console.ReadLine();
        }

    [Fact]
    public void SumDictionariesByKey_ASingleEmptyDictionary_ReturnsTheSameDictionary()
    {
        // arrange
        var dictionaries = new List<Dictionary<string, int>>
        {
            new()
        };
        // act
        var result = DictionaryUtils.SumDictionariesByKey(dictionaries);

        // assert
        Assert.True(CompareDictionaries(new Dictionary<string, int>(), result));
    }
    
    

    [Theory]
    [ClassData(typeof(SumDictionariesTestData))]
    public void SumDictionaries_MultipleDictionaries_ReturnsTheirSum(Dictionary<string,int>[] dictionariesToSum, Dictionary<string,int> expected)
    {
        // arrange
        
        // act
        var result = DictionaryUtils.SumDictionariesByKey(dictionariesToSum);

        // assert
        Assert.True(CompareDictionaries(expected, result));
    }


        [Fact]
        public void AddOrUpdate_Dictionary_GetDefaultValueShouldGetDefault()
        {
            // Arrange
            IDictionary<int, string> dict = new Dictionary<int, string>();
            dict.Add(1, "abc");
            dict.Add(2, "bca");

            // Act & assert
            Assert.Equal("default", DictionaryUtils.GetValueOrDefault(dict, 5, "default"));
            Assert.Equal("abc", DictionaryUtils.GetValueOrDefault(dict, 1, "abc"));
        }


        public void setTarget(IVistaConnection target)
        {
            throw new NotImplementedException();
        }

        #region Helpers

        #region Outpatient Classification Types
        
        public IList<OutpatientClassificationType> getOutpatientClassificationTypes()
        {
            ReadRangeRequest request = buildGetOutpatientClassificationTypesRequest();
            ReadRangeResponse response = new CrrudDaoFactory().getCrrudDao(_cxn).readRange(request);
            return toOutpatientClassificationTypes(response);
        }

        internal ReadRangeRequest buildGetOutpatientClassificationTypesRequest()
        {
            ReadRangeRequest request = new ReadRangeRequest(_cxn.getSource());
            request.setFile("409.41");
            request.setFields(".01;.04;.06;.07");
            return request;
        }

        internal IList<OutpatientClassificationType> toOutpatientClassificationTypes(ReadRangeResponse response)
        {
            IList<OutpatientClassificationType> result = new List<OutpatientClassificationType>();

            if (response.value == null || response.value.Count == 0)
            {
                return result;
            }

            foreach (String s in response.value)
            {
                String[] pieces = StringUtils.split(s, StringUtils.CARAT);
                OutpatientClassificationType current = new OutpatientClassificationType();
                current.id = pieces[0];
                current.name = pieces[1];
                current.displayName = pieces[3];
                current.abbreviation = pieces[4];
                result.Add(current);
            }

            return result;
        }

        #endregion

        #endregion

        #region Get Outpatient Encounter

        /// <summary>
        /// Fetch an outpatient encounter by ID. Returns parent encounter, child encounters, classisfications
        /// </summary>
        /// <param name="encounterId"></param>
        /// <returns></returns>
        public OutpatientEncounter getEncounter(String encounterId)
        {
            ReadRequest request = buildGetOutpatientEncounterRequest(encounterId);
            ReadResponse response = new CrrudDaoFactory().getCrrudDao(_cxn).read(request);
            return toEncounter(response);
        }

        internal ReadRequest buildGetOutpatientEncounterRequest(String encounterId)
        {
            ReadRequest request = new ReadRequest(_cxn.getSource());
            request.setFile("409.68");
            request.setIens(encounterId);
            return request;
        }



	public static void findById(string playerId, Dictionary<string, object> requestParameters, Scoreflex.ModelCallback<Player> callback) { 
		Scoreflex.Get("/players/"+playerId, requestParameters, (bool success, Dictionary<string,object> answer) => {
			if (success == false) { 
				callback(false, null);
				return;
			}
			Player result = new Player(answer);
			callback(success, result);
		});
	}

	public static void findById(string playerId, Scoreflex.ModelCallback<Player> callback) { 
		findById(playerId, null, callback);
	}

	public static void findMe(Dictionary<string, object> requestParameters, Scoreflex.ModelCallback<Player> callback) { 
		Player.findById("me", requestParameters, callback);
	}

	public static void findMe(Scoreflex.ModelCallback<Player> callback) { 
		Player.findById("me", callback);
	 }


	public static void findById(string id, Dictionary<string, object> requestParameters, Scoreflex.ModelCallback<Game> callback) { 
		Scoreflex.Get("/games/"+id, requestParameters, (bool success, Dictionary<string, object> result) => {
			if (success == false) {
				callback(false, null);
				return;
			} 

			callback(success, new Game(result));
		}); 
	}

	public static void findById(string id, Scoreflex.ModelCallback<Game> callback) { 
		findById(id, null, callback);
	}

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ChallengeEndConditions {
	protected Dictionary<string, object> _jsonValue;

	public string duration {
		get {return (string) DictionaryUtils.getValueForKey(_jsonValue ,"duration", null);}
	}

	public long scoreToBeat {
		get {return (long) DictionaryUtils.getValueForKey(_jsonValue, "scoreToBeat", -1);}
	}

	public List<object> scoreToBeatLimits {
		get {return (List<object>) DictionaryUtils.getValueForKey(_jsonValue, "scoreToBeatLimits", null);}
	}

	public string maxTimePerPlayer { 
		get {return (string) DictionaryUtils.getValueForKey(_jsonValue,"maxTimePerPlayer",null);}
	}

	public string maxPlayingTimePerPlayer { 
		get {return (string) DictionaryUtils.getValueForKey(_jsonValue, "maxPlayingTimePerPlayer", null);}
	}

	public string maxTurnTimePerPlayer { 
		get {return (string) DictionaryUtils.getValueForKey(_jsonValue, "maxTurnTimePerPlayer", null);}
	}

	public string maxTurnsPerPlayer { 
		get {return (string) DictionaryUtils.getValueForKey(_jsonValue, "maxTurnsPerPlayer", null);}
	}

	public ChallengeEndConditions(Dictionary<string, object> value) { 
		_jsonValue = value;

	}

}

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Score {

	Dictionary<string, object>	_jsonValues;

	public string formattedCompact { 
		get { return (string)DictionaryUtils.getValueForKey(_jsonValues, "formattedCompact", null);}
	}

	public string deviceModel {
		get { return (string) DictionaryUtils.getValueForKey(_jsonValues,"deviceModel", null);}
	}

	public long score { 
		get { return (long) DictionaryUtils.getValueForKey(_jsonValues,"score", (long)-1);}
	}

	public string formattedLong { 
		get {return (string) DictionaryUtils.getValueForKey(_jsonValues, "formattedLong", null);}
	}

	public string devicePlatform { 
		get {return (string) DictionaryUtils.getValueForKey(_jsonValues, "devicePlatform", null);}
	}

	public long time {
		get {return (long) DictionaryUtils.getValueForKey(_jsonValues, "time", (long) -1);}
	}

	public Score(Dictionary<string, object> score) { 
		_jsonValues = score;
	}

}

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Turn  {
	Dictionary<string, object> _jsonValue; 

	public long sequence {
		get {return (long) DictionaryUtils.getValueForKey(_jsonValue, "sequence", (long) -1);}
	}

	public List<string> currentPlayers {
		get {return (List<string>) DictionaryUtils.getValueForKey(_jsonValue, "currentPlayers", null);}
	}

	public long startTimestamp {
		get {return (long) DictionaryUtils.getValueForKey(_jsonValue, "startTimestamp", (long) -1);}
	}

	public long expireTimestamp {
		get {return (long) DictionaryUtils.getValueForKey(_jsonValue, "expireTimestamp", (long)-1);}
	}

	public Dictionary<string, object> turnHistory {
		get{return (Dictionary<string, object>) DictionaryUtils.getValueForKey(_jsonValue, "turnHistory", null);}
	}

	public Dictionary<string, object> outcome {
		get{return (Dictionary<string, object>) DictionaryUtils.getValueForKey(_jsonValue, "outcome", null);}
	}
	
	public Turn(Dictionary<string, object> values) { 
		_jsonValue = values;
	}
}

Microsoft.Recognizers.Text.NumberWithUnit.Utilities.DictionaryUtils : Object

Methods :

public static Void BindDictionary(IDictionary<StringString> dictionary = , IDictionary<StringString> sourceDictionary = )
public static Void BindUnitsString(IDictionary<StringString> sourceDictionary = , String key = , String source = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()