Ejemplo n.º 1
0
        private static Attribute?GetAttributeThatCanHaveMultiple(Type attributeType, Type classType, MemberInfo?memberInfo, object[] attributes)
        {
            if (attributes.Length == 0)
            {
                return(null);
            }

            if (attributes.Length == 1)
            {
                return((Attribute)attributes[0]);
            }

            ThrowHelper.ThrowInvalidOperationException_SerializationDuplicateAttribute(attributeType, classType, memberInfo);
            return(default);
Ejemplo n.º 2
0
        private JsonPropertyInfo GetPropertyThatHasAttribute(Type attributeType)
        {
            Debug.Assert(_propertyRefs != null);

            JsonPropertyInfo property = null;

            for (int iProperty = 0; iProperty < _propertyRefs.Count; iProperty++)
            {
                PropertyRef      propertyRef      = _propertyRefs[iProperty];
                JsonPropertyInfo jsonPropertyInfo = propertyRef.Info;
                Attribute        attribute        = jsonPropertyInfo.PropertyInfo.GetCustomAttribute(attributeType);
                if (attribute != null)
                {
                    if (property != null)
                    {
                        ThrowHelper.ThrowInvalidOperationException_SerializationDuplicateAttribute(attributeType);
                    }

                    property = jsonPropertyInfo;
                }
            }

            return(property);
        }