Beispiel #1
0
    public dynamic Get(string key, dynamic defaultValue = default(dynamic), GenericDictionary options = null)
    {
        // First check for dynamic data callbacks
        if (_dynamicDataCallbacks.ContainsKey(key))
        {
            foreach (var pair in _dynamicDataCallbacks[key])
            {
                foreach (Func <GenericDictionary, dynamic> callback in pair.Value)
                {
                    dynamic result = callback(options);
                    if (result != null && !result.Equals(defaultValue))
                    {
                        return(result);
                    }
                }
            }
        }

        // Return from the database
        if (_dataBase.ContainsKey(key))
        {
            return(_dataBase.Get(key, defaultValue));
        }

        return(defaultValue);
    }
Beispiel #2
0
    void FailConfirmation(string name, GenericDictionary args)
    {
        float failConfirmationTime = args.Get("failConfirmationTime");

        failConfirmationImage.transform.parent.gameObject.SetActive(true);
        failConfirmationImage.DOFillAmount(1f, failConfirmationTime);
    }
Beispiel #3
0
        public LoadFromSqlite(string dbFilePath, int loadWordsLimit = -1)
        {
            var connectionStringParams = new SQLiteConnectionStringBuilder
            {
                DataSource       = dbFilePath,
                Version          = 3,
                CacheSize        = 4096,
                DefaultTimeout   = 100,
                BusyTimeout      = 100,
                UseUTF16Encoding = true,
                ReadOnly         = true,
                SyncMode         = SynchronizationModes.Off,
                JournalMode      = SQLiteJournalModeEnum.Off
            };

            _genericDictionary = new GenericDictionary
            {
                Name        = DictionayName,
                FullName    = DictionayFullName,
                Description = DictionayDescription,
                Website     = DictionayWebsite,
                Version     = DictionayVersion
            };

            _connectionString = connectionStringParams.ToString();
            _loadWordsLimit   = loadWordsLimit;
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var book = new Book {
                Isbn = "1111", Title = "C# Advanced"
            };

            //Classic way
            var numbers = new List();

            numbers.Add(10);

            var books = new BookList();

            books.Add(book);
            //Generic
            var numberList = new GenericList <int>();

            numberList.Add(10);

            var bookList = new GenericList <Book>();

            bookList.Add(book);

            var dictionary = new GenericDictionary <string, Book>();

            dictionary.Add("1234", new Book());
        }
Beispiel #5
0
#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
        public bool TryGetValue(TKey key, out TValue?value)
#pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
        {
            if (_dictionary != null)
            {
                if (!_dictionary.Contains(key))
                {
#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter.
                    value = default;
#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter.
                    return(false);
                }
                else
                {
                    value = (TValue)_dictionary[key];
                    return(true);
                }
            }
#if HAVE_READ_ONLY_COLLECTIONS
            else if (_readOnlyDictionary != null)
            {
                throw new NotSupportedException();
            }
#endif
            else
            {
                return(GenericDictionary.TryGetValue(key, out value));
            }
        }
Beispiel #6
0
        public bool Remove(TKey key)
        {
            if (_dictionary != null)
            {
                if (_dictionary.Contains(key))
                {
                    _dictionary.Remove(key);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
#if HAVE_READ_ONLY_COLLECTIONS
            else if (_readOnlyDictionary != null)
            {
                throw new NotSupportedException();
            }
#endif
            else
            {
                return(GenericDictionary.Remove(key));
            }
        }
        public bool TryGetValue(TKey key, [MaybeNull] out TValue value)
        {
            if (_dictionary != null)
            {
                if (!_dictionary.Contains(key))
                {
#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter.
                    value = default;
#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter.
                    return(false);
                }
                else
                {
                    value = (TValue)_dictionary[key];
                    return(true);
                }
            }
#if HAVE_READ_ONLY_COLLECTIONS
            else if (_readOnlyDictionary != null)
            {
                throw new NotSupportedException();
            }
#endif
            else
            {
                return(GenericDictionary.TryGetValue(key, out value));
            }
        }
 public MaterialShaderClassNode()
     : base()
 {
     Generics         = new GenericDictionary();
     CompositionNodes = new Dictionary <string, IMaterialNode>();
     Members          = new Dictionary <ParameterKey, object>();
 }
Beispiel #9
0
        public void CopyTo(KeyValuePair <TKey, TValue>[] array, int arrayIndex)
        {
            if (_dictionary != null)
            {
                // Manual use of IDictionaryEnumerator instead of foreach to avoid DictionaryEntry box allocations.
                IDictionaryEnumerator e = _dictionary.GetEnumerator();
                try
                {
                    while (e.MoveNext())
                    {
                        DictionaryEntry entry = e.Entry;
                        array[arrayIndex++] = new KeyValuePair <TKey, TValue>(
                            (TKey)entry.Key,
                            (TValue)entry.Value
                            );
                    }
                }
                finally
                {
                    (e as IDisposable)?.Dispose();
                }
            }
#if HAVE_READ_ONLY_COLLECTIONS
            else if (_readOnlyDictionary != null)
            {
                throw new NotSupportedException();
            }
#endif
            else
            {
                GenericDictionary.CopyTo(array, arrayIndex);
            }
        }
Beispiel #10
0
        // public delegate TResult Func<in T1,in T2, out TResult>(T1 arg1,T2 arg2);
        static void Main(string[] args)
        {
            int number1 = 5;
            // Lamba
            Func <int, int> squareOfNumber = i => number1 * number1;

            Console.WriteLine(squareOfNumber);

            var lambaDemo   = new LambaDemo();
            var listOFBooks = lambaDemo.GetBooks().Where(x => x.Price < 10).ToList();

            Func <int, int, int> add   = Sum;
            Func <int, int, int> minus = Subtract;
            int result = minus(5, 3);

            Console.WriteLine(result);
            var _doorProcessor = new UnlockDoorProcessor();
            var _door          = new Door();

            _door.KeyNumber = "MY121HN";
            Func <Door, string> processor1 = _doorProcessor.UnclockDoor;

            processor1 += OpenDoorWithRemote;
            var dd = processor1(_door);



            Console.ReadLine();



            var            processor     = new PhotoProcessor();
            var            filters       = new PhotoFilters();
            Action <Photo> filterHandler = filters.ApplyBrightness;

            filterHandler += CustomerFilter;
            filterHandler += filters.ApplyContrast;
            filterHandler += filters.Resize;
            processor.Process("hhh", filterHandler);

            var nullable = new Nullables <int>();
            var genericInitializerObject = new GenericInitializerObject <Student>();
            var student = genericInitializerObject.CreateInitializerObjectGeneric();

            student.Name    = "Sazi";
            student.Surname = "Nyathi";
            var results = nullable.GetVaueOrDefault();

            var number = new GenericList <int>();

            number.Add(10);

            var students = new GenericList <Student>();

            students.Add(student);

            var studentDictinary = new GenericDictionary <int, Student>();

            studentDictinary.Add(1, student);
        }
Beispiel #11
0
    void GameStart(string name, GenericDictionary args)
    {
        float introductionDuration = args.Get("ConstructionTime") + 0.25f + args.Get("PhysicalActivationTime");

        SetHeightLevel(Mathf.Max(MyEventSystem.instance.Get("TowerHeight") - topOffset, initialCameraHeight), introductionDuration);
        cameraRotator.DORotate(new Vector3(0f, cameraRotator.eulerAngles.y + 360f, 0f), introductionDuration, RotateMode.FastBeyond360).SetEase(introductionRotationEase);
    }
Beispiel #12
0
        public bool Remove(KeyValuePair <TKey, TValue> item)
        {
            if (_dictionary != null)
            {
                if (_dictionary.Contains(item.Key))
                {
                    object value = _dictionary[item.Key];

                    if (Equals(value, item.Value))
                    {
                        _dictionary.Remove(item.Key);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
#if HAVE_READ_ONLY_COLLECTIONS
            else if (_readOnlyDictionary != null)
            {
                throw new NotSupportedException();
            }
#endif
            else
            {
                return(GenericDictionary.Remove(item));
            }
        }
Beispiel #13
0
    public void switchMusic(string sceneName, GenericDictionary message)
    {
        if (MasterManager.isMenu(sceneName))
        {
            switchAudio(menuAudio);
            return;
        }

        if (message == null)
        {
            Debug.LogError("Message is null and we are supposed to play biome music");
            return;
        }

        object levelId = message.GetValue <object>("levelId");
        object biome   = message.GetValue <object>("biome");

        if (levelId != null && biome != null)
        {
            LevelData levelData = LevelLoader.instance.LoadLevelData((int)levelId, (DataTypes.BiomeType)biome);

            if (levelData != null)
            {
                if (levelData.isBossLevel)
                {
                    switchAudio(biomeAudioList.bossAudio);
                }
                else
                {
                    switchAudio(biomeAudioList.GetAudioForBiome((DataTypes.BiomeType)biome));
                }
            }
        }
    }
Beispiel #14
0
        public void GenericDictionaryTest()
        {
            var genericDic = new GenericDictionary <string, Book>();
            var book       = new Book();

            genericDic.Add("123", book);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a number  :");
            string num = Console.ReadLine();
            int num1 = int.Parse(num);
            var number = new Nullable<int>(num1);

            Console.WriteLine("Has a value ?:  "+ number.HasValue);
            Console.WriteLine("Value :  "+ number.GetValueOrDefault());
            Console.WriteLine("");

            Console.WriteLine("enter a number :");
            string index = Console.ReadLine();
            Console.WriteLine("enter a Name :");
            string name = Console.ReadLine();

            var Nlist = new GenericDictionary<string,string>();
            Nlist.Add(index, name);

            var NList2 = new GenList<string,string>();
            NList2.Add(index,name);

            List<string> NewList = new List<string> { index, name, num };
            Console.WriteLine(NewList.LongCount());

            Console.WriteLine("choose 1, 2 or 3");
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(NewList[n-1]);


        }
Beispiel #16
0
 void TowerPartClicked(string name, GenericDictionary args)
 {
     if (canThrowBall)
     {
         ThrowBall(args.Get("destination"));
     }
 }
        public async Task <ActionResult> AddFeat(GenericDictionary feat)
        {
            try
            {
                int charID = (int)TempData["char"];
                HttpRequestMessage  message  = CreateServiceRequest(HttpMethod.Get, $"api/Character/{charID}");
                HttpResponseMessage response = await Client.SendAsync(message);

                if (!response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                var responseBody = await response.Content.ReadAsStringAsync();

                Character character = JsonConvert.DeserializeObject <Character>(responseBody);
                character.FeatList.Add(feat.key, feat.value);

                var url = $"https://localhost:44309/api/Character/{charID}";
                response = await Client.PutAsJsonAsync(url, character);

                if (!response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                return(RedirectToAction("Edit", new { id = charID }));
            }

            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Beispiel #18
0
        public static void Update(GenericDictionary <Components.Movement> movements, GenericDictionary <Vector3> directions, GenericDictionary <Quaternion> rotations, GenericDictionary <float> maxSpeeds)
        {
            foreach (KeyValuePair <int, Components.Movement> movement in movements)
            {
                float      maxSpeed;
                Quaternion rotation;
                Vector3    direction;

                if (directions.TryGetValue(movement.Key, out direction))
                {
                    if (maxSpeeds.TryGetValue(movement.Key, out maxSpeed))
                    {
                        if (rotations.TryGetValue(movement.Key, out rotation))
                        {
                            movement.Value.velocity = rotation * direction * maxSpeed;
                        }
                        else
                        {
                            movement.Value.velocity = direction * maxSpeed;
                        }
                    }
                    else
                    {
                        movement.Value.velocity = direction;
                    }
                }
                else
                {
                    movement.Value.velocity = Vector3.zero;
                }
            }
        }
        /// <summary>
        /// Add a new generic parameter.
        /// </summary>
        /// <typeparam name="T">The type of the generic.</typeparam>
        /// <param name="keyName">The name of the generic.</param>
        /// <param name="generics">The target GenericDictionary.</param>
        private void AddKey <T>(string keyName, GenericDictionary generics)
        {
            INodeParameter nodeParameter;
            var            typeT = typeof(T);

            if (typeT == typeof(string))
            {
                nodeParameter = new NodeParameter();
            }
            else if (typeT == typeof(Texture2D))
            {
                nodeParameter = new NodeParameterTexture();
            }
            else if (typeT == typeof(float))
            {
                nodeParameter = new NodeParameterFloat();
            }
            else if (typeT == typeof(int))
            {
                nodeParameter = new NodeParameterInt();
            }
            else if (typeT == typeof(Vector2))
            {
                nodeParameter = new NodeParameterFloat2();
            }
            else if (typeT == typeof(Vector3))
            {
                nodeParameter = new NodeParameterFloat3();
            }
            else if (typeT == typeof(Vector4))
            {
                nodeParameter = new NodeParameterFloat4();
            }
            else if (typeT == typeof(SamplerState))
            {
                nodeParameter = new NodeParameterSampler();
            }
            else
            {
                throw new Exception("Unsupported generic format");
            }

            if (Generics.ContainsKey(keyName))
            {
                var gen = Generics[keyName];
                if (gen == null || gen.GetType() != nodeParameter.GetType())
                {
                    generics[keyName] = nodeParameter;
                }
                else
                {
                    generics[keyName] = gen;
                }
            }
            else
            {
                generics.Add(keyName, nodeParameter);
            }
        }
        public void GenericDictionaryTest1()
        {
            GenericDictionary <string, Book> dictionary = new GenericDictionary <string, Book>();

            dictionary.Add("1234", new Book(isbn: "1111", title: "C# Advanced"));

            Assert.Equal(expected: "C# Advanced", actual: dictionary["1234"].Title);
        }
Beispiel #21
0
        public static void Update(GenericDictionary <Components.Controllable> controllables, Components.BufferedInputs inputs)
        {
            foreach (KeyValuePair <int, Components.Controllable> controllable in controllables)
            {
                for (int i = 0; i < inputs.buffered.Count; i++)
                {
                    float x = controllable.Value.inputAxis.x;
                    float y = controllable.Value.inputAxis.y;

                    if (inputs.buffered[i].key == Enums.Key.Up &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        y += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Up &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        y -= 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Down &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        y -= 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Down &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        y += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Left &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        x -= 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Left &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        x += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Right &&
                        inputs.buffered[i].state == Enums.KeyState.Down)
                    {
                        x += 1.0f;
                    }
                    if (inputs.buffered[i].key == Enums.Key.Right &&
                        inputs.buffered[i].state == Enums.KeyState.Up)
                    {
                        x -= 1.0f;
                    }
                    x = Mathf.Clamp(x, -1.0f, 1.0f);
                    y = Mathf.Clamp(y, -1.0f, 1.0f);
                    controllable.Value.inputAxis.x = x;
                    controllable.Value.inputAxis.y = y;
                }
            }
            inputs.buffered.Clear();
        }
        public static void Add_TriesToAddNullValueToEmptyDictionary_ReturnedFalseAndKeysAndValuesAreEmpty()
        {
            var dictionary = new GenericDictionary <TKey, TValue>();

            Assert.IsFalse(dictionary.Add(null));

            CollectionAssert.IsEmpty(dictionary.Keys);
            CollectionAssert.IsEmpty(dictionary.Values);
        }
Beispiel #23
0
    void ScoreUpdate(string name, GenericDictionary args)
    {
        TowerPart part = args.Get("DestructedTowerPart");

        foreach (Floor floor in towerConstructor.floors)
        {
            floor.TowerPartDestructed(part);
        }
    }
Beispiel #24
0
        private void OnImportFrameMetadata(T texture, int frame, Metadata.MetadataReader metadata, IList <Image> images, Image referenceImage, int mipmapsCount)
        {
            GenericDictionary formatSpecific = new GenericDictionary();

            InteropUtils.ReadFrom(metadata, formatSpecific);
            TextureFormat segment = CreateFrameForGeneralTexture(texture, frame, formatSpecific, images, referenceImage, mipmapsCount);

            segment.FormatSpecificData = formatSpecific;
        }
Beispiel #25
0
        private T OnImportGeneralTextureMetadata(Metadata.MetadataReader metadata)
        {
            GenericDictionary formatSpecific = new GenericDictionary();

            InteropUtils.ReadFrom(metadata, formatSpecific);
            T result = CreateGeneralTextureFromFormatSpecificData(formatSpecific);

            result.FormatSpecificData = formatSpecific;

            return(result);
        }
Beispiel #26
0
        //private static UnityAction listener;

        //public static void Start() {

        //    listener = OnEvent;
        //    EventManager.StartListening(Fudo.Enums.Event.Test, listener);
        //}

        //public static void OnEvent() {
        //    Debug.Log("YYYIEEEAHAAA");
        //}

        public static void Update(GenericDictionary <Vector3> positions, GenericDictionary <Components.Movement> movements)
        {
            foreach (KeyValuePair <int, Components.Movement> movementComponent in movements)
            {
                Vector3 newPos;
                if (positions.TryGetValue(movementComponent.Key, out newPos))
                {
                    positions[movementComponent.Key] = newPos + movementComponent.Value.velocity * Time.deltaTime;
                }
            }
        }
Beispiel #27
0
 void ScoreUpdate(string name, GenericDictionary args = null)
 {
     eliminatedTowerPartsNumber++;
     MyEventSystem.instance.Set("CompletionPercentage", Mathf.Floor((float)eliminatedTowerPartsNumber / (float)TowerPartsNumberToWin * 100f));
     if (eliminatedTowerPartsNumber >= TowerPartsNumberToWin && !gameOver)
     {
         gameOver = true;
         StopCoroutine("waitToConfirmFail");
         MyEventSystem.instance.FireEvent("Win");
     }
 }
Beispiel #28
0
 void ReduceBallsNumberLeft(string name, GenericDictionary args = null)
 {
     ballsNumberleft--;
     MyEventSystem.instance.Set("BallsNumberleft", ballsNumberleft);
     //UPDATE UI
     if (ballsNumberleft < 0 && !gameOver)
     {
         //wait to validate the loss
         StartCoroutine("waitToConfirmFail");
     }
 }
Beispiel #29
0
 public static void Update(GenericDictionary <Components.Controllable> controllables, GenericDictionary <Vector3> directions)
 {
     foreach (KeyValuePair <int, Components.Controllable> controllable in controllables)
     {
         Vector3 direction;
         if (directions.TryGetValue(controllable.Key, out direction))
         {
             direction = new Vector3(controllable.Value.inputAxis.x, 0, controllable.Value.inputAxis.y);
             directions[controllable.Key] = direction;
         }
     }
 }
Beispiel #30
0
 public void FireEvent(string name, GenericDictionary data = null)
 {
     if (_eventCallbacks.ContainsKey(name))
     {
         foreach (var pair in _eventCallbacks[name])
         {
             foreach (EventAction callback in pair.Value)
             {
                 callback(name, data);
             }
         }
     }
 }
Beispiel #31
0
        private static void Main(string[] args)
        {
            var numbers = new GenericList <int>();

            numbers.Add(1);

            var books = new GenericList <Book>();

            books.Add(new Book());

            var dictionary = new GenericDictionary <int, Book>();

            dictionary.Add(1, new Book());
        }
Beispiel #32
0
 public Sweepstakes(string nameInput)
 {
     name = nameInput;
     GenericDictionary = new GenericDictionary<int, string>();
     sweepstakesDictionary = new Dictionary<int, string>();
 }
 private void InitializeDictionaries()
 {
     this.textureDictionary = new GenericDictionary<string, Texture2D>("textures");
     this.fontDictionary = new GenericDictionary<string, SpriteFont>("fonts");
     this.modelDictionary = new GenericDictionary<string, Model>("model");
     this.trackDictionary = new GenericDictionary<string, Camera3DTrack>("camera tracks");
 }
 public void CanSerializeGenericDictionary()
 {
     var expectedBson = Serialize<Document>(new Document("Property", new Document() { { "key1", 10 }, { "key2", 20 } }));
     var obj = new GenericDictionary { Property = new Dictionary<string, int> { { "key1", 10 }, { "key2", 20 } } };
     var bson = Serialize<GenericDictionary>(obj);
     Assert.AreEqual(expectedBson, bson);
 }