Пример #1
0
        internal override void SetIndex(string name, object value)
        {
            if (TrySet(TypedParameters, name, value, (v, t) => this[t.Item1] = value))
            {
                return;
            }

            var prop = InternalParameters.Where(p => HasName(p, name)).ToList();

            if (prop.Count == 0 && IsLocked())
            {
                throw new InvalidOperationException($"Parameter with name '{name}' does not exist. To add new parameters object must first be unlocked.");
            }

            if (IsSensorTarget(value))
            {
                foreach (var obj in prop)
                {
                    InternalParameters.Remove(obj);
                }

                Add(name, value);
            }
            else
            {
                SetOrAddCustom(prop, name, value);
            }
        }
        internal virtual void SetIndex(string name, object value)
        {
            if (TrySet(TypedParameters, name, value, (v, t) => this[t.Item1] = value))
            {
                return;
            }
            if (TrySet(TypedProperties, name, value, (v, t) => t.Item2.SetValue(this, v)))
            {
                return;
            }

            var props = InternalParameters.Where(p => HasName(p, name, trimName)).ToList();

            SetOrAddCustom(props, name, value);
        }
        internal bool RemoveInternal(string name, bool ignoreUnderscore)
        {
            var toRemove = InternalParameters.Where(p => HasName(p, name, ignoreUnderscore)).ToList();

            if (toRemove.Count == 0)
            {
                return(false);
            }

            foreach (var obj in toRemove)
            {
                InternalParameters.Remove(obj);
            }

            return(true);
        }
Пример #4
0
        private object GetIndex(string name)
        {
            Tuple <Parameter, PropertyInfo>      param;
            Tuple <ObjectProperty, PropertyInfo> prop;

            if (TypedParameters.TryGetValue(name, out param, true))
            {
                return(this[param.Item1]);
            }
            if (TypedProperties.TryGetValue(name, out prop, true, trimName))
            {
                return(prop.Item2.GetValue(this));
            }

            var matches = InternalParameters
                          .Where(p => HasName(p, name, trimName))
                          .Select(p =>
            {
                if (p.Value is IParameterContainerValue)
                {
                    return(((IParameterContainerValue)p.Value).Value);
                }

                return(p.Value);
            })
                          .ToList();

            if (matches.Count == 1)
            {
                return(matches.First());
            }

            if (matches.Count > 0)
            {
                if (matches.All(o => o is GenericSensorTarget))
                {
                    return(matches.Cast <GenericSensorTarget>().ToArray());
                }

                throw new NotSupportedException($"Property '{name}' contains an invalid collection of elements");
            }

            throw new InvalidOperationException($"Parameter with name '{name}' does not exist.");
        }