Cartographer.Compiler.ConversionPatternGenericCloser.EnsureMeetsGenericConstraints C# (CSharp) Method

EnsureMeetsGenericConstraints() private method

private EnsureMeetsGenericConstraints ( Type type, Type genericParameter ) : Type
type System.Type
genericParameter System.Type
return System.Type
        Type EnsureMeetsGenericConstraints(Type type, Type genericParameter)
        {
            Debug.Assert(genericParameter.IsGenericParameter, "genericParameter must really be a generic parameter.");
            var genericConstraints = genericParameter.GenericParameterAttributes;
            if (genericConstraints == GenericParameterAttributes.None)
            {
                return type;
            }
            if (genericConstraints.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint))
            {
                if (IsNotNullableValueType(type) == false)
                {
                    return null;
                }
            }
            else
            {
                // no need to check for default .ctor when we have value type, since we know it'll have one anyway
                if (genericConstraints.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint))
                {
                    if (HasDefaultConstructor(type) == false)
                    {
                        return null;
                    }
                }
                if (genericConstraints.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint))
                {
                    if (IsReferenceType(type) == false)
                    {
                        return null;
                    }
                }
            }
            return type;
        }