Exemple #1
0
        private static PlTerm typeToSpec(Class type)
        {
            if (type == null)
            {
                return(PLNULL);
            }
            if (type.IsArray && type.HasElementType)
            {
                if (type.GetArrayRank() != 1)
                {
                    return(PlC("arrayOf", typeToSpec(type.GetElementType()), ToProlog(type.GetArrayRank())));
                }
                return(PlC("arrayOf", typeToSpec(type.GetElementType())));
            }
            if (type.IsGenericParameter)
            {
                Type[] gt = type.GetGenericParameterConstraints();
                return(PlC("<" + type.FullName ?? type.Name + ">", ToPlTermVSpecs(gt)));
            }
            if (type.IsPointer)
            {
                Type gt = type.GetElementType();
                return(PlC("pointer", typeToSpec(gt)));
            }
            if (type.IsByRef)
            {
                Type gt = type.GetElementType();
                return(PlC("byref", typeToSpec(gt)));
            }
            // @todo if false , use IsGenericType
            if (false)
            {
                if (typeof(Nullable <>).IsAssignableFrom(type))
                {
                    Error("@todo Not Implemented NULLABLE");
                    Type gt = type.GetElementType();
                    return(PlC("nullable", typeToSpec(gt)));
                }
            }

            if (type.IsGenericType)
            {
                Type    gt        = type.GetGenericTypeDefinition();
                Type[]  gtp       = type.GetGenericArguments();
                PlTermV vt        = ToPlTermVSpecs(gtp);
                string  typeName  = type.FullName ?? type.Name;
                int     gtpLength = gtp.Length;
                int     indexOf   = typeName.IndexOf("`" + gtpLength);
                if (indexOf > 0)
                {
                    typeName = typeName.Substring(0, indexOf);
                }
                else
                {
                    Debug("cant chop arity {0} off string '{1}' ", gtpLength, typeName);
                }
                return(PlC(typeName, vt));
            }
            if (type.HasElementType)
            {
                string named = typeToName(type);
                Error("@todo Not Implemented " + named);
                Type gt = type.GetElementType();
                if (gt == type)
                {
                    gt = typeof(object);
                }
                return(PlC("elementType", PlTerm.PlAtom(named), typeToSpec(gt)));
            }
            if (type.IsSpecialName || string.IsNullOrEmpty(type.Name) || string.IsNullOrEmpty(type.FullName) || string.IsNullOrEmpty(type.Namespace))
            {
                string named = typeToName(type);
                Error("@todo Not Implemented " + named);
                Type gt = type.UnderlyingSystemType;
                if (gt == type)
                {
                    gt = typeof(object);
                }
                return(PlC("static", PlTerm.PlAtom(named), typeToSpec(gt)));
            }
            return(PlTerm.PlAtom(typeToName(type)));
        }
Exemple #2
0
        private static PlTerm typeToSpec(Class type)
        {
            if (type == null) return PLNULL;
            if (type.IsArray && type.HasElementType)
            {
                if (type.GetArrayRank() != 1)
                {
                    return PlC("arrayOf", typeToSpec(type.GetElementType()), ToProlog(type.GetArrayRank()));
                }
                return PlC("arrayOf", typeToSpec(type.GetElementType()));
            }
            if (type.IsGenericParameter)
            {
                Type[] gt = type.GetGenericParameterConstraints();
                return PlC("<" + type.FullName ?? type.Name + ">", ToPlTermVSpecs(gt));
            }
            if (type.IsPointer)
            {
                Type gt = type.GetElementType();
                return PlC("pointer", typeToSpec(gt));
            }
            if (type.IsByRef)
            {
                Type gt = type.GetElementType();
                return PlC("byref", typeToSpec(gt));
            }
            // @todo if false , use IsGenericType
            if (false) if (typeof(Nullable<>).IsAssignableFrom(type))
            {
                Error("@todo Not Implemented NULLABLE");
                Type gt = type.GetElementType();
                return PlC("nullable", typeToSpec(gt));
            }

            if (type.IsGenericType )
            {
                Type gt = type.GetGenericTypeDefinition();
                Type[] gtp = type.GetGenericArguments();
                PlTermV vt = ToPlTermVSpecs(gtp);
                string typeName = type.FullName ?? type.Name;
                int gtpLength = gtp.Length;
                int indexOf = typeName.IndexOf("`" + gtpLength);
                if (indexOf > 0)
                {
                    typeName = typeName.Substring(0, indexOf);
                }
                else
                {
                    Debug("cant chop arity {0} off string '{1}' ", gtpLength, typeName);
                }
                return PlC(typeName, vt);
            }
            if (type.HasElementType)
            {
                string named = typeToName(type);
                Error("@todo Not Implemented " + named);
                Type gt = type.GetElementType();
                if (gt == type) gt = typeof(object);
                return PlC("elementType", PlTerm.PlAtom(named), typeToSpec(gt));
            }
            if (type.IsSpecialName || string.IsNullOrEmpty(type.Name) || string.IsNullOrEmpty(type.FullName) || string.IsNullOrEmpty(type.Namespace))
            {
                string named = typeToName(type);
                Error("@todo Not Implemented " + named);
                Type gt = type.UnderlyingSystemType;
                if (gt == type) gt = typeof (object);
                return PlC("static", PlTerm.PlAtom(named), typeToSpec(gt));
            }
            return PlTerm.PlAtom(typeToName(type));
        }