本文整理匯總了C#中PHP.Core.ScriptContext.BeginSetterChain方法的典型用法代碼示例。如果您正苦於以下問題:C# ScriptContext.BeginSetterChain方法的具體用法?C# ScriptContext.BeginSetterChain怎麽用?C# ScriptContext.BeginSetterChain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PHP.Core.ScriptContext
的用法示例。
在下文中一共展示了ScriptContext.BeginSetterChain方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: EnsurePropertyIsObjectInternal
/// <summary>
/// Ensures that a property value is of <see cref="DObject"/> type.
/// </summary>
/// <param name="obj">The object whose property is to be checked.</param>
/// <param name="name">The property name.</param>
/// <param name="caller"><see cref="Type"/> of the object that request the operation.</param>
/// <param name="propValue">The property value (might get updated).</param>
/// <param name="context">The current <see cref="ScriptContext"/>.</param>
/// <returns>The new property value (dereferenced) or <B>null</B> if evaluation of this compound
/// statement should not proceed.</returns>
internal static DObject EnsurePropertyIsObjectInternal(DObject obj, string name, DTypeDesc caller, ref object propValue,
ScriptContext context)
{
DObject result;
PhpReference reference = propValue as PhpReference;
object value;
if (reference != null && !reference.IsSet)
{
// this CT property has been unset
if (obj.TypeDesc.GetMethod(Name.SpecialMethodNames.Set) != null &&
obj.TypeDesc.RealType.Namespace != null &&
obj.TypeDesc.RealType.Namespace.StartsWith(Namespaces.Library))
{
// create a chain of arguments to be passed to the setter
context.BeginSetterChain(obj);
context.ExtendSetterChain(new RuntimeChainProperty(name));
return ScriptContext.SetterChainSingletonObject;
}
// try to invoke __get
bool getter_exists;
reference = obj.InvokeGetterRef(name, caller, out getter_exists);
if (!getter_exists)
{
result = stdClass.CreateDefaultObject(context);
propValue = new PhpReference(result);
return result;
}
else if (reference == null) return null; // error
value = reference.Value;
}
else value = PhpVariable.Dereference(propValue);
// if property value is a DObject, nothing has to be done
result = value as DObject;
if (result != null) return result;
// if the property is "empty"?
if (IsEmptyForEnsure(value))
{
// create a new stdClass and update the reference
result = stdClass.CreateDefaultObject(context);
if (reference != null)
{
reference.Value = result;
reference.IsSet = true;
}
else propValue = result;
return result;
}
// error - the property is a scalar or a PhpArray or a non-empty string
PhpException.VariableMisusedAsObject(value, false);
return null;
}