Пример #1
0
        public T GetOrAddPin <T>(Action <T> factory, string id, GraphValueType type = null) where T : IPin, new()
        {
            if (string.IsNullOrEmpty(id))
            {
                var pins = Pins.Where(p => p.Id.StartsWith("#")).ToList();
                id = "#" + (pins.Count == 0?0:pins.Max(p => int.Parse(p.Id.TrimStart('#'))) + 1);
            }
            else
            {
                var pin = Pins.FirstOrDefault(p => p.Id == id);
                if (pin is T tp)
                {
                    return(tp);
                }
            }

            var newPin = new T
            {
                Id    = id,
                Group = this,
            };

            if (type != null)
            {
                newPin.ValueType = type;
            }

            factory?.Invoke(newPin);

            Pins.Add(newPin);
            return(newPin);
        }
Пример #2
0
 public T GetOrAddPin <T>(string id = null, GraphValueType type = null) where T : IPin, new()
 {
     return(GetOrAddPin <T>(null, id, type));
 }