public static bool PropertyExists(DTypeDesc caller, object classNameOrObject, string propertyName) { ScriptContext context = ScriptContext.CurrentContext; DTypeDesc type = ClassNameOrObjectToType(context, null, caller, classNameOrObject, true); if (type == null) { return(false); } // determine the calling class context //DTypeDesc caller = PhpStackTrace.GetClassContext(); if (caller != null && caller.IsUnknown) { caller = PhpStackTrace.GetClassContext(); } DPropertyDesc property; if (type.GetProperty(new VariableName(propertyName), caller, out property) == GetMemberResult.OK) { // CT property was found return(true); } else { // search RT fields, if possible DObject obj = classNameOrObject as DObject; return(obj != null && obj.RuntimeFields != null && obj.RuntimeFields.ContainsKey(propertyName)); } }
/// <summary> /// Gets the <see cref="DPropertyDesc"/> of a static property of a class. /// </summary> /// <param name="type">The class to get the property of.</param> /// <param name="propertyName">The property name.</param> /// <param name="caller"><see cref="DTypeDesc"/> of the object that request the retrieval.</param> /// <param name="context">Current <see cref="ScriptContext"/>.</param> /// <param name="quiet">If <B>true</B>, the "property not found" exception should not be thrown.</param> /// <returns>The <see cref="DPropertyDesc"/> representing the static property or <B>null</B> if an error occurs.</returns> /// <exception cref="PhpException">The property denoted by <paramref name="propertyName"/> was not found. (Error)</exception> /// <exception cref="PhpException">The property is inaccessible due to its protected or private visibility level (Error). /// </exception> internal static DPropertyDesc GetStaticPropertyDesc(DTypeDesc type, object propertyName, DTypeDesc caller, ScriptContext context, bool quiet) { if (type == null) return null; // convert propertyName to string string name = (propertyName == null ? String.Empty : Convert.ObjectToString(propertyName)); // find the property DPropertyDesc property; switch (type.GetProperty(new VariableName(name), caller, out property)) { case GetMemberResult.NotFound: { if (!quiet) PhpException.UndeclaredStaticProperty(type.MakeFullName(), name); return null; } case GetMemberResult.BadVisibility: { if (!quiet) { PhpException.PropertyNotAccessible( property.DeclaringType.MakeFullName(), name, (caller == null ? String.Empty : caller.MakeFullName()), property.IsProtected); } return null; } case GetMemberResult.OK: { if (!property.IsStatic) goto case GetMemberResult.NotFound; break; } } // make sure that the property has been initialized for this request property.EnsureInitialized(context); return property; }