public void Fill_InvalidProperty_UsesDefaultValue()
        {
            var target = new List<ScatterPoint>();

            var filler = new ListBuilder<ScatterPoint>();
            filler.Add("B", 0d);
            filler.Fill(target, this.src, args => new ScatterPoint(Convert.ToDouble(args[0]), 0));
        }
        public void Fill_NullProperty_DefaultValueIsExpected()
        {
            var target = new List<ScatterPoint>();

            var filler = new ListBuilder<ScatterPoint>();
            filler.Add(null, 42);
            filler.Fill(target, this.src, args => new ScatterPoint(Convert.ToDouble(args[0]), 0));

            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(42, target[0].X);
        }
        public void FillDataPoints()
        {
            var target = new List<DataPoint>();

            var filler = new ListBuilder<DataPoint>();
            filler.Add("A", 0d);
            filler.Fill(target, this.src, args => new DataPoint(Convert.ToDouble(args[0]), 0));

            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(3.14, target[0].X);
        }
Exemple #4
0
        protected override void Deserialize(object target, XmlElementContext context)
        {
            _listBuilder?.Begin(null, false);

            var targetElements = XmlElementSerializer.GetElements(context.XElement, false, _rootTarget, -1)?.ToArray();

            if (targetElements == null)
            {
                return;
            }

            foreach (var targetElement in targetElements)
            {
                _listBuilder?.Add(_serializer.Deserialize(targetElement));
            }

            SetValue(target, _listBuilder?.End());
        }
Exemple #5
0
        protected sealed override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
        {
            Debug.Assert(types != null);

            QueryResult <ConstructorInfo> queryResult = Query <ConstructorInfo>(bindingAttr);
            ListBuilder <ConstructorInfo> candidates  = new ListBuilder <ConstructorInfo>();

            foreach (ConstructorInfo candidate in queryResult)
            {
                if (candidate.QualifiesBasedOnParameterCount(bindingAttr, callConvention, types))
                {
                    candidates.Add(candidate);
                }
            }

            // For perf and desktop compat, fast-path these specific checks before calling on the binder to break ties.
            if (candidates.Count == 0)
            {
                return(null);
            }

            if (types.Length == 0 && candidates.Count == 1)
            {
                ConstructorInfo firstCandidate = candidates[0];
                ParameterInfo[] parameters     = firstCandidate.GetParametersNoCopy();
                if (parameters.Length == 0)
                {
                    return(firstCandidate);
                }
            }

            if ((bindingAttr & BindingFlags.ExactBinding) != 0)
            {
                return(System.DefaultBinder.ExactBinding(candidates.ToArray(), types, modifiers) as ConstructorInfo);
            }

            if (binder == null)
            {
                binder = DefaultBinder;
            }

            return(binder.SelectMethod(bindingAttr, candidates.ToArray(), types, modifiers) as ConstructorInfo);
        }
        protected override void Deserialize(object target, HeaderdFileContext context)
        {
            Argument.NotNull(context, nameof(context));

            if (string.IsNullOrEmpty(_keyName))
            {
                return;
            }

            _listBuilder?.Begin(null, false);

            try
            {
                foreach (var contextEnry in context.Context[_keyName])
                {
                    _listBuilder?.Add(_converter?.ConvertBack(contextEnry.Content));
                }
            }
            finally
            {
                SetValue(target, _listBuilder?.End());
            }
        }
Exemple #7
0
        protected sealed override PropertyInfo?GetPropertyImpl(string name, BindingFlags bindingAttr, Binder?binder, Type?returnType, Type[]?types, ParameterModifier[]?modifiers)
        {
            Debug.Assert(name != null);

            // GetPropertyImpl() is a funnel for two groups of api. We can distinguish by comparing "types" to null.
            if (types == null && returnType == null)
            {
                // Group #1: This group of api accept only a name and BindingFlags. The other parameters are hard-wired by the non-virtual api entrypoints.
                Debug.Assert(binder == null);
                Debug.Assert(modifiers == null);
                return(Query <PropertyInfo>(name, bindingAttr).Disambiguate());
            }
            else
            {
                // Group #2: This group of api takes a set of parameter types, a return type (both cannot be null) and an optional binder.
                QueryResult <PropertyInfo> queryResult = Query <PropertyInfo>(name, bindingAttr);
                ListBuilder <PropertyInfo> candidates  = default;
                foreach (PropertyInfo candidate in queryResult)
                {
                    if (types == null || (candidate.GetIndexParameters().Length == types.Length))
                    {
                        candidates.Add(candidate);
                    }
                }

                if (candidates.Count == 0)
                {
                    return(null);
                }

                // For perf and .NET Framework compat, fast-path these specific checks before calling on the binder to break ties.
                if (types == null || types.Length == 0)
                {
                    // no arguments
                    if (candidates.Count == 1)
                    {
                        PropertyInfo firstCandidate = candidates[0];
                        if (!(returnType is null) && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
                        {
                            return(null);
                        }
                        return(firstCandidate);
                    }
                    else
                    {
                        if (returnType is null)
                        {
                            // if we are here we have no args or property type to select over and we have more than one property with that name
                            throw new AmbiguousMatchException();
                        }
                    }
                }

                if ((bindingAttr & BindingFlags.ExactBinding) != 0)
                {
                    return(System.DefaultBinder.ExactPropertyBinding(candidates.ToArray(), returnType, types, modifiers));
                }

                if (binder == null)
                {
                    binder = Loader.GetDefaultBinder();
                }

                return(binder.SelectProperty(bindingAttr, candidates.ToArray(), returnType, types, modifiers));
            }
        }
        /// <summary>
        /// Updates the points from the <see cref="ItemsSeries.ItemsSource" />.
        /// </summary>
        private void UpdateItemsSourcePoints()
        {
            // Use the Mapping property to generate the points
            if (this.Mapping != null)
            {
                this.ClearItemsSourcePoints();
                foreach (var item in this.ItemsSource)
                {
                    this.itemsSourcePoints.Add(this.Mapping(item));
                }

                return;
            }

            var sourceAsListOfDataPoints = this.ItemsSource as List <DataPoint>;

            if (sourceAsListOfDataPoints != null)
            {
                this.itemsSourcePoints     = sourceAsListOfDataPoints;
                this.ownsItemsSourcePoints = false;
                return;
            }

            this.ClearItemsSourcePoints();

            var sourceAsEnumerableDataPoints = this.ItemsSource as IEnumerable <DataPoint>;

            if (sourceAsEnumerableDataPoints != null)
            {
                this.itemsSourcePoints.AddRange(sourceAsEnumerableDataPoints);
                return;
            }

            // Get DataPoints from the items in ItemsSource
            // if they implement IDataPointProvider
            // If DataFields are set, this is not used
            if (this.DataFieldX == null || this.DataFieldY == null)
            {
                foreach (var item in this.ItemsSource)
                {
                    if (item is DataPoint)
                    {
                        this.itemsSourcePoints.Add((DataPoint)item);
                        continue;
                    }

                    var idpp = item as IDataPointProvider;
                    if (idpp == null)
                    {
                        continue;
                    }

                    this.itemsSourcePoints.Add(idpp.GetDataPoint());
                }
            }
            else
            {
                var filler = new ListBuilder <DataPoint>();
                filler.Add(this.DataFieldX, double.NaN);
                filler.Add(this.DataFieldY, double.NaN);
                filler.Fill(this.itemsSourcePoints, this.ItemsSource, args => new DataPoint(Convert.ToDouble(args[0]), Convert.ToDouble(args[1])));
            }
        }
        /// <summary>
        /// Updates the points from the <see cref="ItemsSeries.ItemsSource" />.
        /// </summary>
        private void UpdateItemsSourcePoints()
        {
            // Use the Mapping property to generate the points
            if (this.Mapping != null)
            {
                this.ClearItemsSourcePoints();
                foreach (var item in this.ItemsSource)
                {
                    this.itemsSourcePoints.Add(this.Mapping(item));
                }

                return;
            }

            var sourceAsListOfDataPoints = this.ItemsSource as List<DataPoint>;
            if (sourceAsListOfDataPoints != null)
            {
                this.itemsSourcePoints = sourceAsListOfDataPoints;
                this.ownsItemsSourcePoints = false;
                return;
            }

            this.ClearItemsSourcePoints();

            var sourceAsEnumerableDataPoints = this.ItemsSource as IEnumerable<DataPoint>;
            if (sourceAsEnumerableDataPoints != null)
            {
                this.itemsSourcePoints.AddRange(sourceAsEnumerableDataPoints);
                return;
            }

            // Get DataPoints from the items in ItemsSource
            // if they implement IDataPointProvider
            // If DataFields are set, this is not used
            if (this.DataFieldX == null || this.DataFieldY == null)
            {
                foreach (var item in this.ItemsSource)
                {
                    if (item is DataPoint)
                    {
                        this.itemsSourcePoints.Add((DataPoint)item);
                        continue;
                    }

                    var idpp = item as IDataPointProvider;
                    if (idpp == null)
                    {
                        continue;
                    }

                    this.itemsSourcePoints.Add(idpp.GetDataPoint());
                }
            }
            else
            {
                var filler = new ListBuilder<DataPoint>();
                filler.Add(this.DataFieldX, double.NaN);
                filler.Add(this.DataFieldY, double.NaN);
                filler.Fill(this.itemsSourcePoints, this.ItemsSource, args => new DataPoint(Axes.Axis.ToDouble(args[0]), Axes.Axis.ToDouble(args[1])));
            }
        }
        public static object CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
        {
            if (type == null)
                throw new ArgumentNullException(nameof(type));

            // If they didn't specify a lookup, then we will provide the default lookup.
            const BindingFlags LookupMask = (BindingFlags)0x000000FF;
            if ((bindingAttr & LookupMask) == 0)
                bindingAttr |= BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance;

            if (activationAttributes != null && activationAttributes.Length > 0)
                throw new NotSupportedException(SR.NotSupported_ActivAttr);

            type = type.UnderlyingSystemType;
            CreateInstanceCheckType(type);

            if (args == null)
                args = Array.Empty<object>();
            int numArgs = args.Length;

            // This short-circuit depends on the fact that the toolchain prohibits valuetypes with nullary constructors. Unfortunately, we can't check for the presence of nullary
            // constructors without risking a MissingMetadataException, and we can't regress the prior N behavior that allowed CreateInstance on valuetypes to work regardless of metadata. 
            if (numArgs == 0 && type.IsValueType)
                return RuntimeAugments.NewObject(type.TypeHandle);

            Type[] argTypes = new Type[numArgs];
            for (int i = 0; i < numArgs; i++)
            {
                argTypes[i] = args[i]?.GetType();
            }

            ConstructorInfo[] candidates = type.GetConstructors(bindingAttr);
            ListBuilder<MethodBase> matches = new ListBuilder<MethodBase>(candidates.Length);
            for (int i = 0; i < candidates.Length; i++)
            {
                if (candidates[i].QualifiesBasedOnParameterCount(bindingAttr, CallingConventions.Any, argTypes))
                    matches.Add(candidates[i]);
            }
            if (matches.Count == 0)
                throw new MissingMethodException(SR.Arg_NoDefCTor);

            if (binder == null)
                binder = Type.DefaultBinder;

            object state = null;
            MethodBase invokeMethod = binder.BindToMethod(bindingAttr, matches.ToArray(), ref args, null, culture, null, out state);
            if (invokeMethod.GetParametersNoCopy().Length == 0)
            {
                if (args.Length != 0)
                {

                    Debug.Assert((invokeMethod.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs);
                    throw new NotSupportedException(SR.NotSupported_CallToVarArg);
                }

                // Desktop compat: CoreClr invokes a "fast-path" here (call Activator.CreateInstance(type, true)) that also
                // bypasses the binder.ReorderArgumentArray() call. That "fast-path" isn't a fast-path for us so we won't do that
                // but we'll still null out the "state" variable to bypass the Reorder call.
                //
                // The only time this matters at all is if (1) a third party binder is being used and (2) it actually reordered the array
                // which it shouldn't have done because (a) we didn't request it to bind arguments by name, and (b) it's kinda hard to
                // reorder a zero-length args array. But who knows what a third party binder will do if we make a call to it that we didn't 
                // used to do, so we'll preserve the CoreClr order of calls just to be safe.
                state = null;
            }

            object result = ((ConstructorInfo)invokeMethod).Invoke(bindingAttr, binder, args, culture);
            if (state != null)
                binder.ReorderArgumentArray(ref args, state);
            return result;
        }
Exemple #11
0
        /// <summary>
        /// Updates the data.
        /// </summary>
        protected internal override void UpdateData()
        {
            if (this.ItemsSource == null)
            {
                return;
            }

            this.slices.Clear();

            var filler = new ListBuilder<PieSlice>();
            filler.Add(this.LabelField, (string)null);
            filler.Add(this.ValueField, double.NaN);
            filler.Add(this.ColorField, OxyColors.Automatic);
            filler.Add(this.IsExplodedField, false);
            filler.FillT(
                this.slices,
                this.ItemsSource,
                args =>
                new PieSlice((string)args[0], Convert.ToDouble(args[1]))
                {
                    Fill = (OxyColor)args[2],
                    IsExploded = (bool)args[3]
                });
        }
        /// <summary>
        /// Updates the data.
        /// </summary>
        protected internal override void UpdateData()
        {
            if (this.ItemsSource != null)
            {
                this.Items.Clear();

                var filler = new ListBuilder<IntervalBarItem>();
                filler.Add(this.MinimumField, double.NaN);
                filler.Add(this.MaximumField, double.NaN);
                filler.FillT(this.Items, this.ItemsSource, args => new IntervalBarItem() { Start = Convert.ToDouble(args[0]), End = Convert.ToDouble(args[1]) });
            }
        }
Exemple #13
0
        /// <summary>
        /// Updates the data.
        /// </summary>
        protected internal override void UpdateData()
        {
            if (this.ItemsSource == null)
            {
                return;
            }

            this.items.Clear();

            // Use the mapping to generate the points
            if (this.Mapping != null)
            {
                foreach (var item in this.ItemsSource)
                {
                    this.items.Add(this.Mapping(item));
                }

                return;
            }

            var sequenceOfHighLowItems = this.ItemsSource as IEnumerable<HighLowItem>;
            if (sequenceOfHighLowItems != null)
            {
                this.items.AddRange(sequenceOfHighLowItems);
                return;
            }

            var filler = new ListBuilder<HighLowItem>();
            filler.Add(this.DataFieldX, double.NaN);
            filler.Add(this.DataFieldHigh, double.NaN);
            filler.Add(this.DataFieldLow, double.NaN);
            filler.Add(this.DataFieldOpen, double.NaN);
            filler.Add(this.DataFieldClose, double.NaN);
            filler.FillT(this.items, this.ItemsSource, args => new HighLowItem(Axis.ToDouble(args[0]), Convert.ToDouble(args[1]), Convert.ToDouble(args[2]), Convert.ToDouble(args[3]), Convert.ToDouble(args[4])));
        }
Exemple #14
0
        /// <summary>
        /// The update data.
        /// </summary>
        protected internal override void UpdateData()
        {
            base.UpdateData();

            if (this.ItemsSource == null)
            {
                this.IsPoints2Defined = this.points2.Count > 0;

                if (this.IsPoints2Defined)
                {
                    this.actualPoints2 = this.points2;
                }
                else
                {
                    this.actualPoints2 = this.GetConstantPoints2().ToList();
                }

                return;
            }

            this.itemsSourcePoints2.Clear();

            // TODO: make it consistent with DataPointSeries.UpdateItemsSourcePoints
            // Using reflection on DataFieldX2 and DataFieldY2
            this.IsPoints2Defined = this.DataFieldX2 != null && this.DataFieldY2 != null;

            if (this.IsPoints2Defined)
            {
                var filler = new ListBuilder<DataPoint>();
                filler.Add(this.DataFieldX2, double.NaN);
                filler.Add(this.DataFieldY2, double.NaN);
                filler.Fill(this.itemsSourcePoints2, this.ItemsSource, args => new DataPoint(Axes.Axis.ToDouble(args[0]), Axes.Axis.ToDouble(args[1])));
            }
            else
            {
                this.itemsSourcePoints2.AddRange(this.GetConstantPoints2());
            }
        }