PropertyWithMoreThanOneMatch() статический приватный Метод

InvalidOperationException with message like "More than one property '{0}' on type '{1}' is compatible with the supplied arguments."
static private PropertyWithMoreThanOneMatch ( object p0, object p1 ) : Exception
p0 object
p1 object
Результат Exception
Пример #1
0
        private static PropertyInfo?FindProperty(
            [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] Type type,
            string propertyName,
            Expression[]?arguments,
            BindingFlags flags)
        {
            PropertyInfo?property = null;

            foreach (PropertyInfo pi in type.GetProperties(flags))
            {
                if (pi.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase) && IsCompatible(pi, arguments))
                {
                    if (property == null)
                    {
                        property = pi;
                    }
                    else
                    {
                        throw Error.PropertyWithMoreThanOneMatch(propertyName, type);
                    }
                }
            }

            return(property);
        }
Пример #2
0
        private static PropertyInfo FindProperty(Type type, string propertyName, Expression[] arguments, BindingFlags flags)
        {
            var props   = type.GetProperties(flags).Where(x => x.Name.Equals(propertyName, StringComparison.CurrentCultureIgnoreCase));
            var members = new List <PropertyInfo>(props).ToArray();

            if (members == null || members.Length == 0)
            {
                return(null);
            }

            PropertyInfo pi;
            var          propertyInfos = members.Map(t => t);
            var          count         = FindBestProperty(propertyInfos, arguments, out pi);

            if (count == 0)
            {
                return(null);
            }

            if (count > 1)
            {
                throw Error.PropertyWithMoreThanOneMatch(propertyName, type);
            }

            return(pi);
        }
Пример #3
0
        private static PropertyInfo FindProperty(Type type, string propertyName, Expression[] arguments, BindingFlags flags)
        {
            PropertyInfo property = null;

            foreach (PropertyInfo pi in type.GetProperties(flags))
            {
                if (pi.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase) && IsCompatible(pi, arguments))
                {
                    if (property == null)
                    {
                        property = pi;
                    }
                    else
                    {
                        throw Error.PropertyWithMoreThanOneMatch(propertyName, type);
                    }
                }
            }

            return(property);
        }