Пример #1
0
 private void @new(string key, nutility.Tree <string, InputReplLevel> tree)
 {
     if (reserved.ContainsKey(key) || key.StartsWith("?"))
     {
         Writer.WriteLine($"For clarity, please choose another id because '{key}' is reserved.");
     }
     else if (tree.ContainsKey(key))
     {
         Writer.WriteLine($"{key} already identifies an existing input class or input instance.");
     }
     else
     {
         InputClassReplLevel current_class = tree.Value as InputClassReplLevel;
         if (current_class == null)
         {
             Writer.WriteLine($"A new input instance is currently supported only on input class levels.");
         }
         else
         {
             var new_instance = Activator.CreateInstance(current_class.InputClass);
             var new_level    = new nutility.InputInstanceReplLevel(key, new_instance);
             tree[new_level.ID] = new nutility.Tree <string, nutility.InputReplLevel> {
                 Value = new_level, Parent = tree
             };
             Writer.WriteLine($"\t{key} ({current_class.InputClass.FullName})");
         }
     }
 }
Пример #2
0
        private void delete(string key, nutility.Tree <string, InputReplLevel> tree)
        {
            var instance_level = tree.ContainsKey(key) ? (tree[key].Value as InputInstanceReplLevel) : null;

            if (instance_level != null)
            {
                var         instance   = instance_level.InputInstance;
                var         classname  = instance?.GetType().FullName;
                IDisposable disposable = instance as IDisposable;
                if (disposable != null)
                {
                    Writer.WriteLine($"\t{key} ({classname}) disposing...");
                    disposable.Dispose();
                    Writer.WriteLine($"\t{key} ({classname}) disposed.");
                }
                tree.Remove(key);
                Writer.WriteLine($"\t{key} ({classname}) removed.");
            }
            else
            {
                Writer.WriteLine($"{key} not found among existing instances at current input level.");
            }
        }