private static int FindIndex(IValueContainer container, string nameToFind, int startIndex)
        {
            var count = container.GetCount();

            if (startIndex < 0 || startIndex >= count)
            {
                startIndex = 0;
            }

            for (var i = startIndex; i < count; i++)
            {
                var name = container.GetName(i);
                if (string.Equals(name, nameToFind, StringComparison.Ordinal))
                {
                    return(i);
                }
            }

            for (var i = 0; i < startIndex; i++)
            {
                var name = container.GetName(i);
                if (string.Equals(name, nameToFind, StringComparison.Ordinal))
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemple #2
0
        public static object[] GetValues(this IValueContainer container)
        {
            var values = new object[container.GetCount()];

            for (var i = 0; i < values.Length; i++)
            {
                values[i] = container.GetValue(i);
            }
            return(values);
        }
Exemple #3
0
        public static void CopyTo(this IValueContainer source, IValueContainer target)
        {
            if (source == null || target == null || source.GetCount() == 0 || target.GetCount() == 0)
            {
                return;
            }

            var sourceValues = source.ToEnumerable().ToDictionary(v => v.Name);
            int targetCount  = target.GetCount();

            for (var i = 0; i < targetCount; i++)
            {
                var name = target.GetName(i);
                if (!sourceValues.TryGetValue(name, out var v) || v.Type != target.GetType(i))
                {
                    continue;
                }
                target.SetValue(i, v.Value);
            }
        }
Exemple #4
0
        public static IValueContainer Clone(this IValueContainer container)
        {
            var copy       = new ValueContainer();
            var valueCount = container.GetCount();

            for (var i = 0; i < valueCount; i++)
            {
                copy.Add(container.GetName(i), container.GetType(i), container.GetValue(i));
            }
            return(copy);
        }
Exemple #5
0
        private void SerializeValueContainer(IValueContainer valueContainer, IValueWriter writer)
        {
            var valueCount = valueContainer.GetCount();

            for (var i = 0; i < valueCount; i++)
            {
                var name  = valueContainer.GetName(i);
                var type  = valueContainer.GetType(i);
                var value = valueContainer.GetValue(i);

                SerializeValue(name, type, value, writer);
            }
        }
        public void Read(IObjectReconstructor reconstructor, ISerializer serializer)
        {
            var count = _container.GetCount();

            for (var i = 0; i < count; i++)
            {
                var valueInfo = new ValueInfo
                {
                    Name = _container.GetName(i),
                    Type = _container.GetType(i).ToTypeSerializationInfo(),
                };
                reconstructor.OnValueStart(valueInfo);
                reconstructor.OnValue(_container.GetValue(i));
                reconstructor.OnValueEnd();
            }
        }
        private static int FindIndex(IValueContainer container, Type uniqueTypeToFind)
        {
            var foundIndex = -1;

            var count = container.GetCount();

            for (var i = 0; i < count; i++)
            {
                var type = container.GetType(i);
                if (ReferenceEquals(type, uniqueTypeToFind) || (type.IsInterface && type.IsAssignableFrom(uniqueTypeToFind)))
                {
                    if (foundIndex >= 0)
                    {
                        return(-1);
                    }

                    foundIndex = i;
                }
            }

            return(foundIndex);
        }
Exemple #8
0
 public int GetCount() => _impl.GetCount();
 public int GetCount() => _valuesProxy.GetCount();
 public int GetCount() => _keysProxy.GetCount();