public override void SetValue(Context ctx, object instance, PhpValue value) { if (IsReadOnly) { throw new NotSupportedException(); } _field.SetValue(_staticsGetter(ctx), value.ToClr(_field.FieldType)); }
public override void SetValue(Context ctx, object instance, PhpValue value) { var setter = _property.SetMethod; if (setter == null) { throw new NotSupportedException(); } setter.Invoke(instance, new[] { value.ToClr(_property.PropertyType) }); }
/// <summary> /// Converts a W3C PHP object to the corresponding W3C .NET object. /// </summary> public static object /*!*/ PhpToDotNet(Context ctx, PhpValue arg) { if (arg.IsNull) { return(String.Empty); } // Node* (XPath) if (arg.IsObject) { var node = arg.Object as DOMNode; if (node != null) { return(node.XmlNode.CreateNavigator()); } // Node Set (XPath), Result Tree Fragment (XSLT) DOMNodeList list = arg.Object as DOMNodeList; if (list != null) { XPathNavigator[] navs = new XPathNavigator[list.length]; for (int i = 0; i < list.length; i++) { navs[i] = list.item(i).XmlNode.CreateNavigator(); } return(navs); } // any other object return(arg.ToString(ctx)); } // TODO: Handle PhpArray separately? // String (XPath), Boolean (XPath), Number (XPath) return(arg.ToClr()); }
public void InitializeParameter(DbParameter p) { p.Direction = (Type.HasValue && (Type.Value & PARAM.PARAM_INPUT_OUTPUT) != 0) ? ParameterDirection.InputOutput : ParameterDirection.Input; if (Variable.IsNull) { p.Value = DBNull.Value; // TODO: p.DbType } else if (Type.HasValue) { switch (Type.Value & ~PARAM.PARAM_INPUT_OUTPUT) { case PARAM.PARAM_BOOL: p.Value = Utilities.DbValueHelper.AsObject(Variable.ToBoolean()); p.DbType = DbType.Boolean; break; case PARAM.PARAM_INT: p.Value = Variable.ToLong(); p.DbType = DbType.Int64; break; case PARAM.PARAM_STR: if (Variable.IsUnicodeString(out var str)) { p.Value = str; p.DbType = DbType.String; } else if (Variable.IsBinaryString(out var bin)) { p.Value = bin.ToBytes(Encoding.UTF8); p.DbType = DbType.Binary; } else { p.Value = Variable.ToString(); p.DbType = DbType.String; } break; case PARAM.PARAM_NULL: p.Value = DBNull.Value; // TODO: p.DbType break; case PARAM.PARAM_ZVAL: p.Value = Variable.ToClr(); // TODO: p.DbType break; default: throw new NotImplementedException(Type.Value.ToString()); } } else { p.Value = Variable.ToClr(); // TODO: p.DbType } }
public PhpValueDebugView(PhpValue value) { DebugValue = value.ToClr(); }
public static PhpValue getIntItem(Context ctx, PhpValue obj, PhpValue key) { return(getItem(ctx, obj.ToClr(), key.ToInt())); }
public static PhpValue getStrItem(Context ctx, PhpValue obj, PhpValue key) { return(getItem(ctx, obj.ToClr(), key.ToString(ctx))); }
/// <summary> /// 将PHP类型转换回CLR类型,主要用于解决将PHP类型传进object类型的C#类库时的奇怪问题(比如传进去后变为NULL) /// </summary> /// <param name="ctx">PhpContext</param> /// <param name="value">PHP值</param> /// <returns>CLR类型</returns> public static object toObject(Context ctx, PhpValue value) { return(value.ToClr()); }
public override void SetValue(Context ctx, object instance, PhpValue value) { _field.SetValue(instance, value.ToClr(_field.FieldType)); }