コード例 #1
0
        public bool AddVariable(NTVariable value, Type t)
        {
            if (string.IsNullOrEmpty(value.GetKey()))
            {
                return(false);
            }

            Type newVariableType = t;

            NTVariableDictionary variableTypeDictionary = new NTVariableDictionary(t);

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(value.GetKey()))
                {
                    return(false);
                }
                else
                {
                    variableTypeDictionary.Add(value.GetKey(), value);
                    dictionary[newVariableType.ToString()] = variableTypeDictionary;
                    onModified?.Invoke();
                    return(true);
                }
            }
            else
            {
                variableTypeDictionary.Add(value.GetKey(), value);
                dictionary.Add(newVariableType.ToString(), variableTypeDictionary);
                onModified?.Invoke();
                return(true);
            }
        }
コード例 #2
0
        public void RemoveVariable(string key, Type variableType)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            if (dictionary.ContainsKey(variableType.ToString()))
            {
                NTVariableDictionary variableTypeDictionary = dictionary[variableType.ToString()];
                variableTypeDictionary.Remove(key);
                dictionary[variableType.ToString()] = variableTypeDictionary;
                onModified?.Invoke();
            }
        }
コード例 #3
0
        public void RemoveVariable <T>(string key) where T : NTVariable
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            Type newVariableType = typeof(T);

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                NTVariableDictionary variableTypeDictionary = dictionary[newVariableType.ToString()];
                variableTypeDictionary.Remove(key);
                dictionary[newVariableType.ToString()] = variableTypeDictionary;
                onModified?.Invoke();
            }
        }
コード例 #4
0
        public bool AddVariable(Type varType, object value)
        {
            NTVariable ntVar = (NTVariable)value;

            if (ntVar == null)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(ntVar.GetKey()))
            {
                return(false);
            }

            Type newVariableType = varType;
            NTVariableDictionary variableTypeDictionary = new NTVariableDictionary(newVariableType);

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                if (variableTypeDictionary.ContainsKey(ntVar.GetKey()))
                {
                    return(false);
                }
                else
                {
                    variableTypeDictionary.Add(ntVar.GetKey(), ntVar);
                    dictionary[newVariableType.ToString()] = variableTypeDictionary;
                    onModified?.Invoke();
                    return(true);
                }
            }
            else
            {
                variableTypeDictionary.Add(ntVar.GetKey(), ntVar);
                dictionary.Add(newVariableType.ToString(), variableTypeDictionary);
                onModified?.Invoke();
                return(true);
            }
        }
コード例 #5
0
        public List <string> GetOptions(Type variableType, string key, out int index)
        {
            List <string> options = new List <string>();

            index = -1;

            Type newVariableType = variableType;

            if (newVariableType == null)
            {
                return(options);
            }

            NTVariableDictionary variableTypeDictionary = new NTVariableDictionary(newVariableType);

            if (dictionary.ContainsKey(newVariableType.ToString()))
            {
                variableTypeDictionary = dictionary[newVariableType.ToString()];
                options = variableTypeDictionary.keys;
                index   = options.IndexOf(key);
            }

            return(options);
        }