本文整理汇总了C#中PHP.Core.PhpArray.Add方法的典型用法代码示例。如果您正苦于以下问题:C# PhpArray.Add方法的具体用法?C# PhpArray.Add怎么用?C# PhpArray.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP.Core.PhpArray
的用法示例。
在下文中一共展示了PhpArray.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildErrorInfo
public static PhpArray BuildErrorInfo(string sqlstate, object driver_error, string message)
{
PhpArray arr = new PhpArray();
arr.Add(0, sqlstate);
arr.Add(1, driver_error);
arr.Add(2, message);
return arr;
}
示例2: PrintFunctions
public static PhpArray PrintFunctions()
{
PhpArray result = new PhpArray();
result.Add("name", new PhpArray());
result.Add("type", new PhpArray());
result.Add("method", new PhpArray());
Assembly assembly = typeof(PhpDocumentation).Assembly;
//PhpLibraryModule.EnumerateFunctions(assembly, new PhpLibraryModule.FunctionsEnumCallback(FunctionsCallback), result);
return result;
}
示例3: GetFunctions
public static PhpArray GetFunctions()
{
var context = ScriptContext.CurrentContext;
if (context.IsSplAutoloadEnabled)
{
PhpArray result = new PhpArray();
foreach (var func in context.SplAutoloadFunctions)
result.Add(func.ToPhpRepresentation());
return result;
}
else
{
return null;
}
}
示例4: BindObject
private static object BindObject(object obj, Type type)
{
FieldInfo[] fi = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
var runtimeFields = new PhpArray(fi.Length);
object value;
bool specified = true;
FieldInfo field;
for (int i = 0; i < fi.Length; ++i)
{
field = fi[i];
specified = true;
if (i + 1 < fi.Length && Attribute.IsDefined(fi[i + 1], typeof(XmlIgnoreAttribute)))
{
value = fi[i + 1].GetValue(obj);
if (value == null)
specified = false;
else
specified = (bool)value;
i++;
}
if (specified)
{
value = Bind(field.GetValue(obj), field);
if (value != null)
runtimeFields.Add(field.Name, value);
}
}
return new stdClass()
{
RuntimeFields = runtimeFields
};
}
示例5: getModifierNames
/// <summary>
/// Gets an array of modifier names contained in modifiers flags.
/// </summary>
//[ImplementsMethod]
public static PhpArray getModifierNames(int modifiers)
{
PhpArray result = new PhpArray();
Modifiers flags = (Modifiers)modifiers;
if ((flags & (Modifiers.Abstract | Modifiers.AbstractClass)) != 0)
result.Add("abstract");
if ((flags & (Modifiers.Abstract | Modifiers.AbstractClass)) != 0)
result.Add("final");
switch (flags & Modifiers.VisibilityMask)
{
case Modifiers.Public: result.Add("public"); break;
case Modifiers.Protected: result.Add("protected"); break;
case Modifiers.Private: result.Add("private"); break;
}
if ((flags & Modifiers.Static) != 0)
result.Add("static");
return result;
}
示例6: MapIdentity
/// <summary>
/// Default callback for <see cref="Map"/>.
/// </summary>
/// <param name="instance">Unused.</param>
/// <param name="stack">A PHP stack.</param>
/// <returns>A <see cref="PhpArray"/> containing items on the stack (passed as arguments).</returns>
private static object MapIdentity(object instance, PhpStack stack)
{
PhpArray result = new PhpArray(stack.ArgCount, 0);
for (int i = 1; i <= stack.ArgCount; i++)
{
result.Add(PhpVariable.Copy(stack.PeekValueUnchecked(i), CopyReason.PassedByCopy));
}
stack.RemoveFrame();
return result;
}
示例7: Filter
public static PhpArray Filter(PHP.Core.Reflection.DTypeDesc _, PhpArray array)
{
var _result = new PhpArray();
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
if (Core.Convert.ObjectToBoolean(enumerator.CurrentValue))
_result.Add(enumerator.CurrentKey, enumerator.CurrentValue);
return _result;
}
示例8: Unique
public static PhpArray Unique(PhpArray array, ArrayUniqueSortFlags sortFlags /*= String*/)
{
if (array == null)
{
PhpException.ArgumentNull("array");
return null;
}
IComparer comparer;
switch(sortFlags)
{
case ArrayUniqueSortFlags.Regular:
comparer = PhpComparer.Default; break;
case ArrayUniqueSortFlags.Numeric:
comparer = PhpNumericComparer.Default; break;
case ArrayUniqueSortFlags.String:
comparer = PhpStringComparer.Default; break;
case ArrayUniqueSortFlags.LocaleString:
default:
PhpException.ArgumentValueNotSupported("sortFlags", (int)sortFlags);
return null;
}
PhpArray result = new PhpArray(array.Count);
HashSet<object>/*!*/identitySet = new HashSet<object>(new ObjectEqualityComparer(comparer));
// get only unique values - first found
using (var enumerator = array.GetFastEnumerator())
while (enumerator.MoveNext())
{
if (identitySet.Add(PhpVariable.Dereference(enumerator.CurrentValue)))
result.Add(enumerator.Current);
}
result.InplaceCopyOnReturn = true;
return result;
}
示例9: MergeRecursiveInternal
/// <summary>
/// Adds items of "array" to "result" merging those whose string keys are the same.
/// </summary>
private static bool MergeRecursiveInternal(PhpArray/*!*/ result, PhpArray/*!*/ array, bool deepCopy)
{
foreach (KeyValuePair<IntStringKey, object> entry in array)
{
if (entry.Key.IsString)
{
if (result.ContainsKey(entry.Key))
{
// the result array already contains the item => merging take place
object xv = result[entry.Key];
object yv = entry.Value;
// source item:
object x = PhpVariable.Dereference(xv);
object y = PhpVariable.Dereference(yv);
PhpArray ax = x as PhpArray;
PhpArray ay = y as PhpArray;
// if x is not a reference then we can reuse the ax array for the result
// since it has been deeply copied when added to the resulting array:
PhpArray item_result = (deepCopy && x == xv && ax != null) ? ax : new PhpArray();
if (ax != null && ay != null)
{
if (ax != item_result)
ax.AddTo(item_result, deepCopy);
if (ax.Visited && ay.Visited) return false;
ax.Visited = true;
ay.Visited = true;
// merges ay to the item result (may lead to stack overflow,
// but only with both arrays recursively referencing themselves - who cares?):
bool finite = MergeRecursiveInternal(item_result, ay, deepCopy);
ax.Visited = false;
ay.Visited = false;
if (!finite) return false;
}
else
{
if (ax != null)
{
if (ax != item_result)
ax.AddTo(item_result, deepCopy);
}
else
{
/*if (x != null)*/
item_result.Add((deepCopy) ? PhpVariable.DeepCopy(x) : x);
}
if (ay != null) ay.AddTo(item_result, deepCopy);
else /*if (y != null)*/ item_result.Add((deepCopy) ? PhpVariable.DeepCopy(y) : y);
}
result[entry.Key] = item_result;
}
else
{
// PHP does no dereferencing when items are not merged:
result.Add(entry.Key, (deepCopy) ? PhpVariable.DeepCopy(entry.Value) : entry.Value);
}
}
else
{
// PHP does no dereferencing when items are not merged:
result.Add((deepCopy) ? PhpVariable.DeepCopy(entry.Value) : entry.Value);
}
}
return true;
}
示例10: RangeOfChars
/// <summary>
/// Creates an array containing range of characters from the [low;high] interval with arbitrary step.
/// </summary>
/// <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>
/// <exception cref="PhpException">Thrown if the <paramref name="step"/> argument is zero.</exception>
public static PhpArray RangeOfChars(char low, char high, int step)
{
if (step == 0)
{
PhpException.InvalidArgument("step", LibResources.GetString("arg:zero"));
step = 1;
}
if (step < 0) step = -step;
PhpArray result = new PhpArray(Math.Abs(high - low) / step + 1, 0);
if (high >= low)
{
for (int i = 0; low <= high; i++, low = unchecked((char)(low + step))) result.Add(i, low.ToString());
}
else
{
for (int i = 0; low >= high; i++, low = unchecked((char)(low - step))) result.Add(i, low.ToString());
}
return result;
}
示例11: EnsureItemIsArraySimple
/// <summary>
/// Ensures a specified array item is an instance of <see cref="PhpArray"/>.
/// </summary>
/// <param name="array">The <see cref="PhpArray"/> which item should be an array.</param>
/// <param name="key">The key identifying which item should be an array.</param>
/// <remarks>
/// A new instance of <see cref="PhpArray"/> is assigned to the item if it is not an array yet.
/// Array is expected to contain no <see cref="PhpReference"/>.
/// Treats empty key as a missing key.
/// </remarks>
internal static PhpArray EnsureItemIsArraySimple(PhpArray/*!*/ array, string key)
{
Debug.Assert(array != null);
Debug.Assert(!(array is PhpArrayString) && !(array is Library.SPL.PhpArrayObject));
// treats empty key as a missing key:
if (key == String.Empty)
{
PhpArray array_item = new PhpArray();
array.Add(array_item);
return array_item;
}
IntStringKey array_key = Core.Convert.StringToArrayKey(key);
return array.table._ensure_item_array(ref array_key, array);
//element = array.GetElement(array_key);
//// creates a new array if an item is not one:
//array_item = (element != null) ? element.Value as PhpArray : null;
//if (array_item == null)
//{
// array_item = new PhpArray();
// if (element != null)
// {
// if (array.table.IsShared)
// {
// // we are going to change the internal array, it must be writable
// array.EnsureWritable();
// element = array.table.dict[array_key]; // get the item again
// }
// element.Value = array_item;
// }
// else
// array.Add(array_key, array_item);
//}
//return array_item;
}
示例12: SetItemEpilogue
private static void SetItemEpilogue(object value, ref object var)
{
Debug.Assert(var == null || var.GetType() != typeof(PhpArray));
PhpArray array;
// creates a new array and stores it into a new item which is added to the array:
if (IsEmptyForEnsure(var))
{
array = new PhpArray(1, 0);
array.Add(value);
var = array;
return;
}
// PhpArray derivates:
if ((array = var as PhpArray) != null)
{
if (array.Add(value) == 0)
PhpException.Throw(PhpError.Warning, CoreResources.GetString("integer_key_reached_max_value"));
return;
}
// object behaving as array:
DObject dobj = var as DObject;
if (dobj != null && dobj.RealObject is Library.SPL.ArrayAccess)
{
//PhpStack stack = ScriptContext.CurrentContext.Stack;
//stack.AddFrame(null, value);
//dobj.InvokeMethod(Library.SPL.PhpArrayObject.offsetSet, null, stack.Context);
((Library.SPL.ArrayAccess)dobj.RealObject).offsetSet(ScriptContext.CurrentContext, null, value);
return;
}
// errors:
PhpException.VariableMisusedAsArray(var, false);
}
示例13: GetItemRef
public static PhpReference GetItemRef(ref object var)
{
Debug.Assert(!(var is PhpReference));
// PhpArray:
if (var != null && var.GetType() == typeof(PhpArray)) // fast check for PhpArray, not derived types
return ((PhpArray)var).GetArrayItemRef();
// creates a new reference and adds it to an a new array:
if (IsEmptyForEnsure(var))
{
PhpArray array;
var = array = new PhpArray(1, 0);
PhpReference result = new PhpReference();
array.Add(result);
return result;
}
return GetItemRefEpilogue(null, ref var);
}
示例14: SetVariable
public static void SetVariable(ScriptContext/*!*/ context, Dictionary<string, object> locals,
string/*!*/ name, object value)
{
Debug.Assert(name != null && !(value is PhpReference));
if (locals != null)
{
// included in method //
object item;
PhpReference ref_item;
if (locals.TryGetValue(name, out item) && (ref_item = item as PhpReference) != null)
ref_item.Value = value;
else
locals[name] = value;
}
else
{
// true global code //
PhpArray globals = context.AutoGlobals.Globals.Value as PhpArray;
if (globals == null)
{
context.AutoGlobals.Globals.Value = globals = new PhpArray();
globals.Add(name, value);
return;
}
object item;
PhpReference ref_item;
if (globals.TryGetValue(name, out item) && (ref_item = item as PhpReference) != null)
ref_item.Value = value;
else
globals[name] = value;
}
}
示例15: GetHandlers
public static PhpArray GetHandlers()
{
BufferedOutput bo = ScriptContext.CurrentContext.BufferedOutput;
PhpArray result = new PhpArray(bo.Level, 0);
for (int i = 0; i < bo.Level; i++)
{
result.Add(bo.GetLevelName(i));
}
return result;
}