/// <summary>
 /// Gets or sets the element with the specified key.
 /// </summary>
 /// <returns>
 /// The element with the specified key.
 /// </returns>
 /// <param name="key">The key of the element to get or set.
 ///                 </param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.
 ///                 </exception><exception cref="T:System.Collections.Generic.KeyNotFoundException">The property is retrieved and <paramref name="key"/> is not found.
 ///                 </exception><exception cref="T:System.NotSupportedException">The property is set and the <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.
 ///                 </exception>
 public TValue this[TKey key]
 {
     get
     {
         TValue tvalue = default(TValue);
         InForiegnFrame(() =>
         {
             PlTerm newPlTermV = PrologCLR.PlC(_getvalue, KeyToTerm(key), PlTerm.PlVar());
             bool res          = PlCall(_module, _getvalue, new PlTermV(newPlTermV));
             if (res)
             {
                 tvalue = (TValue)PrologCLR.CastTerm(newPlTermV.Arg(1), valueType);
             }
             else
             {
                 // tvalue = default(TValue);
             }
         });
         return(tvalue);
     }
     set
     {
         Remove(key);
         Add(new KeyValuePair <TKey, TValue>(key, value));
     }
 }
Exemple #2
0
        public object GetSymbol(string name)
        {
            PlTerm termout = PlTerm.PlVar();

            if (!ModuleCall("GetSymbol", PlNamed(name), termout))
            {
                return(null);
            }
            return(PrologCLR.CastTerm(termout, typeof(System.Object)));
        }
            /// <summary>
            /// Advances the enumerator to the next element of the collection.
            /// </summary>
            /// <returns>
            /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
            /// </returns>
            /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created.
            ///                 </exception><filterpriority>2</filterpriority>
            public bool MoveNext()
            {
                if (!plQuery.NextSolution())
                {
                    Dispose();
                    return(false);
                }
                nonLeft = false;
                PlTerm plQueryArgs = plQuery.Args[0];

                currentValue = PrologCLR.CastTerm(plQueryArgs, _dictionary.keyType);;
                return(true);
            }
Exemple #4
0
        public object Eval(object obj)
        {
            PlTerm termin = PlTerm.PlVar();

            if (obj is PlTerm)
            {
                termin.Unify((PlTerm)obj);
            }
            else
            {
                termin.FromObject(obj);
            }
            PlTerm termout = PlTerm.PlVar();

            if (!ModuleCall("Eval", termin, termout))
            {
                return(null);
            }
            return(PrologCLR.CastTerm(termout, typeof(System.Object)));
        }
        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <returns>
        /// true if the object that implements <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the specified key; otherwise, false.
        /// </returns>
        /// <param name="key">The key whose value to get.
        ///                 </param><param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value"/> parameter. This parameter is passed uninitialized.
        ///                 </param><exception cref="T:System.ArgumentNullException"><paramref name="key"/> is null.
        ///                 </exception>
        public bool TryGetValue(TKey key, out TValue value)
        {
            TValue value0 = default(TValue);
            bool   res    = false;

            InForiegnFrame(() =>
            {
                PlTerm plTermPlVar = PlTerm.PlVar();
                PlTermV newPlTermV = new PlTermV(KeyToTerm(key), plTermPlVar);
                res = PlCall(_module, _getvalue, newPlTermV);
                if (res)
                {
                    value0 = (TValue)PrologCLR.CastTerm(newPlTermV[1], valueType);
                }
                else
                {
                }
            });
            value = value0;
            return(res);
        }
Exemple #6
0
 public static object CallProlog(object target, string module, string name, int arity, object origin, object[] paramz, Type returnType, bool discard)
 {
     if (!ClientReady)
     {
         return(null);
     }
     return(InvokeFromC(() =>
     {
         PlTermV args = NewPlTermV(arity);
         int fillAt = 0;
         if (origin != null)
         {
             args[fillAt++].FromObject(origin);
         }
         for (int i = 0; i < paramz.Length; i++)
         {
             args[fillAt++].FromObject(paramz[i]);
         }
         bool IsVoid = returnType == typeof(void);
         if (!IsVoid)
         {
             //args[fillAt] = PlTerm.PlVar();
         }
         if (!PlQuery.PlCall(module, name, args))
         {
             if (!IsVoid)
             {
                 Warn("Failed Event Handler {0} failed", target);
             }
         }
         if (IsVoid)
         {
             return null;
         }
         object ret = PrologCLR.CastTerm(args[fillAt], returnType);
         return ret;
     }, discard));
 }