/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="value"> The initial cached value of the drawer. </param>
        /// <param name="memberInfo"> LinkedMemberInfo for the class member that the created drawer represents. Can be null. </param>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="label"> The prefix label. </param>
        /// <param name="readOnly"> True if drawer should be read only. </param>
        /// <returns> The drawer instance, ready to be used. </returns>
        public static ConstraintedTypeDrawer Create([CanBeNull] Type value, [NotNull] Type[] baseTypeConstraints, TypeConstraint typeCategoryConstraint, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            ConstraintedTypeDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new ConstraintedTypeDrawer();
            }
            result.Setup(value, baseTypeConstraints, typeCategoryConstraint, memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
Exemple #2
0
        /// <inheritdoc />
        protected override void DoBuildMembers()
        {
            int count = memberBuildList.Count;

            var genericTypeArguments = Value;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(count == genericTypeArguments.Length, "memberBuildList.Count=" + memberBuildList.Count + " != " + genericTypeArguments.Length);
                        #endif

                        #if DEV_MODE
            Debug.Log("GenericTypeArgumentDrawer.DoBuildMembers called with types.Length=" + genericTypeArguments.Length + ", memberBuildList.Count=" + memberBuildList.Count + ", drawInSingleRow=" + drawInSingleRow);
                        #endif

            DrawerArrayPool.Resize(ref members, count);
            for (int n = count - 1; n >= 0; n--)
            {
                var            argumentMemberInfo = memberBuildList[0];
                var            type = argumentMemberInfo.Type;
                var            baseTypeConstraints = type.GetGenericParameterConstraints();
                TypeConstraint typeCategoryConstraint;
                var            specialConstraintMask = type.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
                if ((specialConstraintMask & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
                {
                    typeCategoryConstraint = TypeConstraint.Class;
                }
                else if ((specialConstraintMask & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
                {
                    typeCategoryConstraint = TypeConstraint.Struct;
                }
                else
                {
                    typeCategoryConstraint = TypeConstraint.None;
                }

                if (baseTypeConstraints.Length > 0)
                {
                    members[n] = ConstraintedTypeDrawer.Create(type, baseTypeConstraints, typeCategoryConstraint, argumentMemberInfo, this, GUIContent.none, ReadOnly);
                }
                else
                {
                    members[n] = TypeDrawer.Create(type, argumentMemberInfo, this, GUIContent.none, ReadOnly);
                }
            }
        }