本文整理汇总了C#中Pchp.Core.PhpValue.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# PhpValue.ToString方法的具体用法?C# PhpValue.ToString怎么用?C# PhpValue.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pchp.Core.PhpValue
的用法示例。
在下文中一共展示了PhpValue.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: is_callable
/// <summary>
/// Verifies that the contents of a variable can be called as a function.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="variable">The variable.</param>
/// <param name="syntaxOnly">If <B>true</B>, it is only checked that has <pararef name="variable"/>
/// a valid structure to be used as a callback. if <B>false</B>, the existence of the function (or
/// method) is also verified.</param>
/// <param name="callableName">Receives the name of the function or method (for example
/// <c>SomeClass::SomeMethod</c>).</param>
/// <returns><B>true</B> if <paramref name="variable"/> denotes a function, <B>false</B>
/// otherwise.</returns>
public static bool is_callable(Context ctx /*, caller*/, PhpValue variable, bool syntaxOnly, out string callableName)
{
var callback = variable.AsCallable();
if (PhpVariable.IsValidCallback(callback))
{
callableName = callback.ToString();
return true;
}
callableName = variable.ToString(ctx);
return false;
}
示例2: settype
/// <summary>
/// Sets variable's type.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="variable">The variable.</param>
/// <param name="type">The string identifying a new type. See PHP manual for details.</param>
/// <returns>Whether <paramref name="type"/> is valid type identifier.</returns>
/// <exception cref="PhpException"><paramref name="type"/> has invalid value.</exception>
public static bool settype(Context ctx, ref PhpValue variable, string type)
{
switch (type.ToLowerInvariant())
{
case "bool":
case "boolean":
variable = PhpValue.Create(variable.ToBoolean());
return true;
case "int":
case "integer":
variable = PhpValue.Create(variable.ToLong());
return true;
case "float":
case "double":
variable = PhpValue.Create(variable.ToDouble());
return true;
case "string":
variable = PhpValue.Create(variable.ToString(ctx));
return true;
case "array":
variable = PhpValue.Create(variable.AsArray());
return true;
case "object":
variable = PhpValue.FromClass(variable.ToClass());
return true;
case "null":
variable = PhpValue.Null;
return true;
}
//PhpException.InvalidArgument("type", LibResources.GetString("invalid_type_name"));
//return false;
throw new ArgumentException(nameof(type));
}
示例3: range
/// <summary>
/// Creates an array containing range of elements with arbitrary step.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="low">Lower bound of the interval.</param>
/// <param name="high">Upper bound of the interval.</param>
/// <param name="step">The step.</param>
/// <returns>The array.</returns>
/// <remarks>
/// Implements PHP awful range function. The result depends on types and
/// content of parameters under the following rules:
/// <list type="number">
/// <item>
/// <description>
/// If at least one parameter (low, high or step) is of type double or is a string wholly representing
/// double value (i.e. whole string is converted to a number and no chars remains,
/// e.g. "1.5" is wholly representing but the value "1.5x" is not)
/// than
/// range of double values is generated with a step treated as a double value
/// (e.g. <c>range("1x","2.5x","0.5") = array(1.0, 1.5, 2.0, 2.5)</c> etc.)
/// otherwise
/// </description>
/// </item>
/// <item>
/// <description>
/// if at least one bound (i.e. low or high parameter) is of type int or is a string wholly representing
/// integer value
/// than
/// range of integer values is generated with a step treated as integer value
/// (e.g. <c>range("1x","2","1.5") = array(1, 2, 3, 4)</c> etc.)
/// otherwise
/// </description>
/// </item>
/// <item>
/// <description>
/// low and high are both non-empty strings (otherwise one of the two previous conditions would be true),
/// so the first characters of these strings are taken and a sequence of characters is generated.
/// </description>
/// </item>
/// </list>
/// Moreover, if <paramref name="low"/> is greater than <paramref name="high"/> then descending sequence is generated
/// and ascending one otherwise. If <paramref name="step"/> is less than zero than an absolute value is used.
/// </remarks>
/// <exception cref="PhpException">Thrown if the <paramref name="step"/> argument is zero (or its absolute value less than 1 in the case 2).</exception>
public static PhpArray range(Context ctx, PhpValue low, PhpValue high, PhpValue step)
{
PhpNumber num_low, num_high, num_step;
// converts each parameter to a number, determines what type of number it is (int/double)
// and whether it wholly represents that number:
var info_step = step.ToNumber(out num_step);
var info_low = low.ToNumber(out num_low);
var info_high = high.ToNumber(out num_high);
var is_step_double = (info_step & Core.Convert.NumberInfo.Double) != 0;
var is_low_double = (info_low & Core.Convert.NumberInfo.Double) != 0;
var is_high_double = (info_high & Core.Convert.NumberInfo.Double) != 0;
var w_step = (info_step & Core.Convert.NumberInfo.IsNumber) != 0;
var w_low = (info_low & Core.Convert.NumberInfo.IsNumber) != 0;
var w_high = (info_high & Core.Convert.NumberInfo.IsNumber) != 0;
// at least one parameter is a double or its numeric value is wholly double:
if (is_low_double && w_low || is_high_double && w_high || is_step_double && w_step)
{
return RangeOfDoubles(num_low.ToDouble(), num_high.ToDouble(), num_step.ToDouble());
}
// at least one bound is wholly integer (doesn't matter what the step is):
if (!is_low_double && w_low || !is_high_double && w_high)
{
// at least one long integer:
return RangeOfLongInts(num_low.ToLong(), num_high.ToLong(), num_step.ToLong());
}
// both bounds are strings which are not wholly representing numbers (other types wholly represents a number):
string slow = low.ToString(ctx);
string shigh = high.ToString(ctx);
// because each string doesn't represent a number it isn't empty:
Debug.Assert(slow != "" && shigh != "");
return RangeOfChars(slow[0], shigh[0], (int)num_step.ToLong());
}
示例4: strval
/// <summary>
/// Converts to string.
/// </summary>
/// <param name="ctx">Current runtime context.</param>
/// <param name="variable">The variable.</param>
/// <returns>The converted value.</returns>
public static string strval(Context ctx, PhpValue variable) => variable.ToString(ctx);
示例5: Echo
public void Echo(PhpValue value)
{
Output.Write(value.ToString(this)); // TODO: echo byte[] properly
}