Example #1
0
 public void TestTypeResolving()
 {
     var res = new ObjectPType(sctx, "System.Threading.Thread");
     Assert.AreEqual(PType.Object[typeof (Thread)], res);
 }
Example #2
0
        /// <summary>
        ///     Creates a new <see cref = "PType" /> instance given its CLR <see cref = "Type" />, encapsulated in an <see
        ///      cref = "ObjectPType" />.
        /// </summary>
        /// <param name = "sctx">The stack context in which to create the <see cref = "PType" /></param>
        /// <param name = "ptypeClrType">A CLR <see cref = "Type" /> that inherits from <see cref = "PType" />, encapsulated in a <see
        ///      cref = "ObjectPType" /> object.</param>
        /// <param name = "args">An array of type arguments.</param>
        /// <returns>The created <see cref = "PType" /> instance.</returns>
        /// <exception cref = "ArgumentException">The <see cref = "System.Type" /> provided by the <see
        ///      cref = "ObjectPType.ClrType" /> property of <paramref name = "ptypeClrType" /> does not inherit from <see
        ///      cref = "PType" />.</exception>
        /// <exception cref = "PrexoniteException">If a silent error occured during the creation of the <see cref = "PType" /> instance.</exception>
        public PType CreatePType(StackContext sctx, ObjectPType ptypeClrType, PValue[] args)
        {
            if (!PType.IsPType(ptypeClrType))
                throw new ArgumentException(
                    "Cannot construct PType. ClrType " + ptypeClrType.ClrType +
                        " is not a PType.");

            //Performance optimizations
            var clrType = ptypeClrType.ClrType;
            if (clrType == typeof (IntPType))
                return PType.Int;
            if (clrType == typeof (RealPType))
                return PType.Real;
            if (clrType == typeof (BoolPType))
                return PType.Bool;
            if (clrType == typeof (StringPType))
                return PType.String;
            if (clrType == typeof (NullPType))
                return PType.Null;
            if (clrType == typeof (ObjectPType) && args.Length > 0 && args[0].Type == PType.String)
                return PType.Object[sctx, (string) args[0].Value];
            if (clrType == typeof (ListPType))
                return PType.List;
            if (clrType == typeof (HashPType))
                return PType.Hash;
            if (clrType == typeof (CharPType))
                return PType.Char;
            if (clrType == typeof (StructurePType))
                return PType.Structure;

            var result =
                ptypeClrType.Construct(sctx, new[] {PType.Object.CreatePValue(args)});
            if (result == null || result.IsNull)
                throw new PrexoniteException(
                    "Could not construct PType (resulted in null reference)");
            if (!PType.IsPType(result))
                throw new PrexoniteException(
                    "Could not construct PType (" + result.ClrType +
                        " is not a PType).");
            return result.Value as PType;
        }
Example #3
0
 /// <summary>
 ///     Constructs a PType instance from the supplied arguments.
 /// </summary>
 /// <param name = "ptypeClrType">An <see cref = "ObjectPType" /> of a class that inherits from <see cref = "PType" />.</param>
 /// <param name = "args">The list of arguments to pass to the constructor.</param>
 /// <returns>An instance of the supplied <see cref = "Type" />.</returns>
 public PType ConstructPType(ObjectPType ptypeClrType, PValue[] args)
 {
     return ParentEngine.CreatePType(this, ptypeClrType, args);
 }