/// <summary> /// Returns object data. /// </summary> /// <returns></returns> public virtual object Data() { if (IsAssigned()) { return(_containee.Data()); } return(null); }
public override bool Unify(AbstractTerm term) { if (term.IsReference) { term.Assign(this); return(true); } if (term.IsConstant) { bool res = term.Data().Equals(this.Data()); return(res); } return(false); }
public void Assign() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm("ali"); term.Assign(con); Assert.AreSame(term.Dereference(), con); Assert.AreSame(term.Dereference(), con.Dereference()); Assert.AreEqual(term.Data(), con.Data()); Assert.AreSame(term.Reference(), con.Reference()); Assert.IsFalse(term.IsList); Assert.IsFalse(term.IsObject); Assert.IsFalse(term.IsReference); Assert.IsFalse(term.IsStructure); Assert.IsTrue(term.IsConstant); }
public bool Getproperty(AbstractTerm obj, AbstractTerm method, AbstractTerm returnObject) { if (obj.IsConstant) { // invoke a static get property Assembly asm = GetRequiredAssembly(obj.Data() as string, runtime); ; Type type = asm.GetType(obj.Data() as string); if (type == null) { return false; } if (type.GetProperty(method.Data() as string) == null) { return false; } object res = type.InvokeMember(method.Data() as string, BindingFlags.GetProperty | BindingFlags.Static | BindingFlags.Public, null, null, null); switch (res.GetType().ToString()) { case "System.String": AbstractTerm rC = new ConstantTerm(res.ToString()); if (!returnObject.Unify(rC)) { return false; } break; case "System.Char": case "System.Int32": case "System.Boolean": AbstractTerm returnConstant = new ConstantTerm(res.ToString()); if (!returnObject.Unify(returnConstant)) { return false; } break; default: returnObject.Unify(new ObjectTerm(res)); break; } } else { if (obj.Data().GetType().GetProperty(method.Data() as string) == null) { return false; } // invoke an instance get property object res = obj.Data().GetType().InvokeMember(method.Data() as string, BindingFlags.Default | BindingFlags.ExactBinding | BindingFlags.GetProperty, null, obj.Data(), null); switch (res.GetType().ToString()) { case "System.Char": case "System.String": case "System.Int32": case "System.Boolean": returnObject.Unify(new ConstantTerm(res.ToString())); break; default: returnObject.Unify(new ObjectTerm(res)); break; } } return true; }
public void Data() { AbstractTerm t = new AbstractTerm(); Assert.IsNull(t.Data()); }
public void Unify_ref_con() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm(); Assert.IsTrue(term.Unify(con)); Assert.AreEqual(term.Data(), con.Data()); Assert.AreSame(term.Reference(), con.Reference()); Assert.IsTrue(term.IsConstant); Assert.IsFalse(term.IsReference); }
public override bool Unify(AbstractTerm term) { // Unify with a .NET object if (term.IsObject) { if (_data.Equals(term.Data())) { return true; } else if (_data == term.Data()) { return true; } return false; } // Unify with a constant if (term.IsConstant) { // unify with an int int v; float x; if (Int32.TryParse((string)term.Data(), out v)) { if (_data.GetType().ToString() == "System.Int32") { if (((int)_data) == v) { return true; } else { return false; } } return false; } // Unify with a float else if (float.TryParse((string)term.Data(), out x)) { if (_data.GetType().ToString() == "System.Float") { if (((float)_data) == x) { return true; } else { return false; } } return false; } // Unify with a constant atom/string else { if (_data.GetType().ToString() == "System.String") { if (((string)_data) == ((string)term.Data())) { return true; } else { return false; } } return false; } } // Unify with a list (need to unify it with an ArrayList) else { return false; } // Unify with a structure // Unify with a reference }
public override bool Unify(AbstractTerm term) { if (term.IsReference) { term.Assign(this); return true; } if (term.IsConstant) { bool res = term.Data().Equals(this.Data()); return res; } return false; }
public bool Setproperty(AbstractTerm obj, AbstractTerm method, AbstractTerm objValue) { if (obj.IsConstant) { // invoke a static method Assembly asm = GetRequiredAssembly(obj.Data() as string, runtime); Type type = asm.GetType(obj.Data() as string); if (type == null) { return false; } ArrayList paramArray = new ArrayList(); ParameterInfo par = type.GetMethod(method.Data() as string).GetParameters()[0]; switch (par.GetType().ToString()) { case "System.Int32": paramArray.Add(Int32.Parse(objValue.Data() as string)); break; case "System.Char": paramArray.Add(objValue.Data().ToString()[0]); break; case "System.String": paramArray.Add(objValue.Data() as string); break; case "System.Boolean": paramArray.Add(Boolean.Parse(objValue.Data() as string)); break; default: // pass Variable.Object paramArray.Add(objValue); break; } object res = type.InvokeMember(method.Data() as string, BindingFlags.Static | BindingFlags.Public | BindingFlags.SetProperty, null, obj, paramArray.ToArray()); switch (res.GetType().ToString()) { case "System.Char": case "System.String": case "System.Int32": case "System.Boolean": objValue.Unify(new ConstantTerm(res.ToString())); break; default: objValue.Unify(new ObjectTerm(res)); break; } } else { ArrayList paramArray = new ArrayList(); Type t = obj.Data().GetType(); PropertyInfo pInfo = t.GetProperty(method.Data() as string); if (pInfo == null) { return false; } if (pInfo.CanWrite == false) { return false; } switch (pInfo.PropertyType.ToString()) { case "System.Int32": paramArray.Add(Int32.Parse(objValue.Data() as string)); break; case "System.Char": paramArray.Add(objValue.Data().ToString()[0]); break; case "System.String": paramArray.Add(objValue.Data() as string); break; case "System.Boolean": paramArray.Add(Boolean.Parse(objValue.Data() as string)); break; default: // pass Variable.Object paramArray.Add(objValue); break; } object res = obj.Data().GetType().InvokeMember(method.Data() as string, BindingFlags.Default | BindingFlags.ExactBinding | BindingFlags.SetProperty, null, obj.Data(), paramArray.ToArray()); } return true; }
public void Unify_con_ref() { AbstractTerm term = new AbstractTerm(); ConstantTerm con = new ConstantTerm("ali"); Assert.IsTrue(con.Unify(term)); Assert.AreSame(term.Data(), con.Data()); }
private bool InvokeMethod(AbstractTerm obj, AbstractTerm method, AbstractTerm returnObject, AbstractMachineState state) { if (obj.IsConstant) { // invoke a static method Assembly asm = GetRequiredAssembly(obj.Data() as string, state); Type type = asm.GetType(obj.Data() as string); if (type == null) { return false; } ArrayList paramArray = new ArrayList(); GetTypes(type.GetMethod(method.Data() as string), method, ref paramArray, obj); object[] arguments = paramArray.ToArray(); object res = type.InvokeMember(method.Data() as string, BindingFlags.Static | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, arguments); switch (res.GetType().ToString()) { case "System.Char": case "System.String": case "System.Int32": case "System.Boolean": returnObject.Assign(new ConstantTerm(res.ToString())); break; default: returnObject.Assign(new ObjectTerm(res)); break; } SetTypes(method, arguments); } else { // invoke an instance method ArrayList paramArray = new ArrayList(); GetTypes(obj.Data().GetType().GetMethod(method.Data() as string), method, ref paramArray, obj); object classObject = obj.Data(); MethodInfo omi = classObject.GetType().GetMethod(method.Data() as string); object[] arguments = paramArray.ToArray(); object res = obj.Data().GetType().InvokeMember(method.Data() as string, BindingFlags.Default | BindingFlags.ExactBinding | BindingFlags.InvokeMethod, null, obj.Data(), arguments); if (res != null) { switch (res.GetType().ToString()) { case "System.String": ConstantTerm rC = new ConstantTerm(res.ToString()); if (!returnObject.Unify(rC)) { return false; } break; case "System.Char": case "System.Int32": case "System.Boolean": ConstantTerm returnConstant = new ConstantTerm(res.ToString()); if (!returnObject.Unify(returnConstant)) { return false; } break; default: returnObject.Assign(new ObjectTerm(res)); break; } } SetTypes(method, arguments); } return true; }
public override bool Unify(AbstractTerm term) { // Unify with a .NET object if (term.IsObject) { if (_data.Equals(term.Data())) { return(true); } else if (_data == term.Data()) { return(true); } return(false); } // Unify with a constant if (term.IsConstant) { // unify with an int int v; float x; if (Int32.TryParse((string)term.Data(), out v)) { if (_data.GetType().ToString() == "System.Int32") { if (((int)_data) == v) { return(true); } else { return(false); } } return(false); } // Unify with a float else if (float.TryParse((string)term.Data(), out x)) { if (_data.GetType().ToString() == "System.Float") { if (((float)_data) == x) { return(true); } else { return(false); } } return(false); } // Unify with a constant atom/string else { if (_data.GetType().ToString() == "System.String") { if (((string)_data) == ((string)term.Data())) { return(true); } else { return(false); } } return(false); } } // Unify with a list (need to unify it with an ArrayList) else { return(false); } // Unify with a structure // Unify with a reference }