コード例 #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 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);
            }
        }