private bool GetValueRangeAttribute()

in resharper/resharper-unity/src/Unity/CSharp/Psi/CodeAnnotations/CustomCodeAnnotationProvider.cs [154:193]


        private bool GetValueRangeAttribute(IClrDeclaredElement element,
            AttributeInstanceCollection attributeInstanceCollection,
            out ICollection<IAttributeInstance> collection)
        {
            collection = EmptyList<IAttributeInstance>.InstanceList;

            if (!(element is IField field) || !element.IsFromUnityProject()) return false;

            if (myUnityApi.IsSerialisedField(field).HasFlag(SerializedFieldStatus.NonSerializedField))
                return false;

            // Integer value analysis only works on integers, but it will make use of annotations applied to values that
            // are convertible to int, such as byte/sbyte and short/ushort. It doesn't currently use values applied to
            // uint, or long/ulong, but it is planned, so we'll apply to all sizes of integer.
            var predefinedType = myPredefinedTypeCache.GetOrCreatePredefinedType(element.Module);
            if (!Equals(field.Type, predefinedType.Int) && !Equals(field.Type, predefinedType.Uint) &&
                !Equals(field.Type, predefinedType.Long) && !Equals(field.Type, predefinedType.Ulong) &&
                !Equals(field.Type, predefinedType.Short) && !Equals(field.Type, predefinedType.Ushort) &&
                !Equals(field.Type, predefinedType.Byte) && !Equals(field.Type, predefinedType.Sbyte))
            {
                return false;
            }

            foreach (var attributeInstance in attributeInstanceCollection.GetAllOwnAttributes())
            {
                foreach (var unityRangeAttributeProvider in myUnityRangeAttributeProviders)
                {
                    if (unityRangeAttributeProvider.IsApplicable(attributeInstance))
                    {
                        var from = unityRangeAttributeProvider.GetMinValue(attributeInstance);
                        var to = unityRangeAttributeProvider.GetMaxValue(attributeInstance);
                        
                        collection = CreateRangeAttributeInstance(element, from, to);
                        return true;
                    }
                }
            }

            return false;
        }