예제 #1
0
        /// <summary>
        /// Helper API to convert a type to its canonical or universal canonical form.
        /// Note that for now, there is no mixture between specific canonical and universal canonical forms,
        /// meaning that the canonical form or Foo<string, int> can either be Foo<__Canon, int> or
        /// Foo<__UniversalCanon, __UniversalCanon>. It cannot be Foo<__Canon, __UniversalCanon> (yet)
        /// for simplicity. We can always change that rule in the futue and add support for the mixture, but
        /// for now we are keeping it simple.
        /// </summary>
        public static TypeDesc ConvertToCanon(TypeDesc typeToConvert, CanonicalFormKind kind)
        {
            TypeSystemContext context = typeToConvert.Context;

            if (kind == CanonicalFormKind.Universal)
            {
                return(context.UniversalCanonType);
            }
            else if (kind == CanonicalFormKind.Specific)
            {
                if (typeToConvert is DefType)
                {
                    if (typeToConvert == context.UniversalCanonType)
                    {
                        return(context.UniversalCanonType);
                    }

                    DefType defTypeToConvert = (DefType)typeToConvert;

                    if (!defTypeToConvert.IsValueType)
                    {
                        return(context.CanonType);
                    }
                    else if (defTypeToConvert.HasInstantiation)
                    {
                        return(defTypeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific));
                    }
                    else
                    {
                        return(typeToConvert);
                    }
                }
                else if (typeToConvert.IsArray)
                {
                    return(context.CanonType);
                }
                else
                {
                    return(typeToConvert.ConvertToCanonForm(CanonicalFormKind.Specific));
                }
            }
            else
            {
                Debug.Assert(false);
                return(null);
            }
        }
예제 #2
0
 protected override TypeDesc ConvertToCanonFormImpl(CanonicalFormKind kind)
 {
     return(_rawCanonType.ConvertToCanonForm(kind));
 }