/// <summary> /// Division of <paramref name="left"/> and <paramref name="right"/> accorsing to PHP semantics. /// </summary> /// <param name="left">Left operand.</param> /// <param name="right">Right operand.</param> /// <returns>Quotient of <paramref name="left"/> and <paramref name="right"/>.</returns> public static PhpNumber operator /(PhpValue left, PhpValue right) => Operators.Div(ref left, ref right);
public static PhpValue operator &(PhpValue left, PhpValue right) => Operators.BitAnd(ref left, ref right);
public static PhpValue operator |(PhpValue left, PhpValue right) => Operators.BitOr(ref left, ref right);
public static PhpValue operator ~(PhpValue x) => Operators.BitNot(ref x);
public override PhpValue GetArrayItem(ref PhpValue me, PhpValue index, bool quiet) => me.Array.GetItemValue(index); // , quiet); public override PhpAlias EnsureItemAlias(ref PhpValue me, PhpValue index, bool quiet) => Operators.EnsureItemAlias(me.Array, index, quiet);
public override IPhpArray GetArrayAccess(ref PhpValue me) => Operators.EnsureArray(me.Object);
public override IPhpEnumerator GetForeachEnumerator(ref PhpValue me, bool aliasedValues, RuntimeTypeHandle caller) => Operators.GetForeachEnumerator(me.Object, aliasedValues, caller);
//static Delegate Create_T_to_PhpValue() //{ // var type = typeof(T); // if (type == typeof(PhpValue)) return Utilities.FuncExtensions.Identity<PhpValue>(); // if (type == typeof(int)) return new Func<int, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(long)) return new Func<long, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(bool)) return new Func<bool, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(double)) return new Func<double, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(float)) return new Func<float, PhpValue>(x => PhpValue.Create((double)x)); // if (type == typeof(string)) return new Func<string, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(uint)) return new Func<uint, PhpValue>(x => PhpValue.Create((long)x)); // if (type == typeof(byte[])) return new Func<byte[], PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(PhpNumber)) return new Func<PhpNumber, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(PhpArray)) return new Func<PhpArray, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(PhpString)) return new Func<PhpString, PhpValue>(x => PhpValue.Create(x)); // if (type == typeof(PhpAlias)) return new Func<PhpAlias, PhpValue>(x => PhpValue.Create(x)); // //if (type == typeof(object)) return new Func<object, PhpValue>(x => PhpValue.FromClass(x)); // throw new NotImplementedException(); //} static Delegate Create_PhpValue_to_T() { var type = typeof(T); if (type == typeof(PhpValue)) { return(Utilities.FuncExtensions.Identity <PhpValue>()); } if (type == typeof(PhpAlias)) { return(new Func <PhpValue, PhpAlias>(x => x.AsPhpAlias())); } if (type == typeof(string)) { return(new Func <PhpValue, string>(x => x.ToString())); } if (type == typeof(double)) { return(new Func <PhpValue, double>(x => x.ToDouble())); } if (type == typeof(float)) { return(new Func <PhpValue, float>(x => (float)x.ToDouble())); } if (type == typeof(long)) { return(new Func <PhpValue, long>(x => x.ToLong())); } if (type == typeof(int)) { return(new Func <PhpValue, int>(x => (int)x.ToLong())); } if (type == typeof(bool)) { return(new Func <PhpValue, bool>(x => x.ToBoolean())); } if (type == typeof(PhpArray)) { return(new Func <PhpValue, PhpArray>(x => x.ToArray())); } if (type.IsValueType) { if (type.IsGenericType) { // Nullable<U> if (type.GetGenericTypeDefinition() == typeof(Nullable <>)) { var typeU = type.GenericTypeArguments[0]; if (typeU == typeof(bool)) { return(new Func <PhpValue, Nullable <bool> >(x => Operators.IsSet(x) ? (bool?)x.ToBoolean() : null)); } if (typeU == typeof(int)) { return(new Func <PhpValue, Nullable <int> >(x => Operators.IsSet(x) ? (int?)(int)x.ToLong() : null)); } if (typeU == typeof(long)) { return(new Func <PhpValue, Nullable <long> >(x => Operators.IsSet(x) ? (long?)x.ToLong() : null)); } if (typeU == typeof(double)) { return(new Func <PhpValue, Nullable <double> >(x => Operators.IsSet(x) ? (double?)x.ToDouble() : null)); } } } } else // type.IsReferenceType { // Delegate if (type.BaseType == typeof(MulticastDelegate)) { // Error: needs Context throw new ArgumentException(); } // Object return(new Func <PhpValue, T>(x => (T)x.AsObject())); } throw new NotImplementedException(); }