本文整理汇总了C#中DObject.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# DObject.GetEnumerator方法的具体用法?C# DObject.GetEnumerator怎么用?C# DObject.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DObject
的用法示例。
在下文中一共展示了DObject.GetEnumerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetObjectVars
//[return: PhpDeepCopy] // already deep copied
public static PhpArray GetObjectVars(DTypeDesc caller, DObject obj, bool IgnoreReferences)
{
if (obj == null) return null;
Converter<object, object> copy = null;
///////////////////////////////////////
// This is hot fix for a reference counting problem when reference aren't released in same way as in PHP.
// Hence, we need to perform deep copy ignoring references
if (IgnoreReferences)
copy = (value) =>
{
PhpReference refValue = value as PhpReference;
if (refValue != null)
return copy(refValue.Value);
PhpArray array = value as PhpArray;
if (array != null)
{
PhpArray dst = new PhpArray(array.IntegerCount, array.StringCount);
foreach (KeyValuePair<IntStringKey, object> entry in array)
{
// checks whether a value is a reference pointing to the instance itself:
refValue = entry.Value as PhpReference;
if (refValue != null && refValue.Value == array)
{
// copies the value so that it will self-reference the new instance (not the old one):
dst.Add(entry.Key, new PhpReference(dst));
}
else
{
dst.Add(entry.Key, copy(entry.Value));
}
}
return dst;
}
return value;
};
else
copy = (value) => { return PhpVariable.DeepCopy(value); }; // perform InplaceDeepCopy() here to save one more iteration through the array
///////////////////////////////////////
PhpArray result = new PhpArray(0, obj.Count);
var foreachEnumerator = obj.GetEnumerator((caller != null && caller.IsUnknown) ? PhpStackTrace.GetClassContext() : caller);
while (foreachEnumerator.MoveNext())
//foreach (DictionaryEntry pair in obj)
{
DictionaryEntry pair = (DictionaryEntry)foreachEnumerator.Current;
result.Add((string)pair.Key, copy(pair.Value));
}
//result.InplaceCopyOnReturn = true; // already deep copied
return result;
}