本文整理汇总了C#中Jurassic.Library.ObjectInstance.GetOwnPropertyDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectInstance.GetOwnPropertyDescriptor方法的具体用法?C# ObjectInstance.GetOwnPropertyDescriptor怎么用?C# ObjectInstance.GetOwnPropertyDescriptor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jurassic.Library.ObjectInstance
的用法示例。
在下文中一共展示了ObjectInstance.GetOwnPropertyDescriptor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineProperty
public static ObjectInstance DefineProperty(ObjectInstance obj, object key, object attributes)
{
key = TypeConverter.ToPropertyKey(key);
var defaults = obj.GetOwnPropertyDescriptor(key);
if (!(attributes is ObjectInstance))
throw new JavaScriptException(obj.Engine, ErrorType.TypeError, "Invalid descriptor for property '{propertyName}'.");
var descriptor = PropertyDescriptor.FromObject((ObjectInstance)attributes, defaults);
obj.DefineProperty(key, descriptor, true);
return obj;
}
示例2: GetOwnPropertyDescriptor
public static ObjectInstance GetOwnPropertyDescriptor(ObjectInstance obj, object key)
{
var descriptor = obj.GetOwnPropertyDescriptor(TypeConverter.ToPropertyKey(key));
if (descriptor.Exists == false)
return null;
return descriptor.ToObject(obj.Engine);
}
示例3: SetObjectLiteralSetter
/// <summary>
/// Sets the value of a object literal property to a setter. If the value already has a
/// getter then it will be retained.
/// </summary>
/// <param name="obj"> The object to set the property on. </param>
/// <param name="key"> The property key (can be a string or a symbol).</param>
/// <param name="setter"> The setter function. </param>
public static void SetObjectLiteralSetter(ObjectInstance obj, object key, UserDefinedFunction setter)
{
var descriptor = obj.GetOwnPropertyDescriptor(key);
if (descriptor.Exists == false || !descriptor.IsAccessor)
obj.DefineProperty(key, new PropertyDescriptor(null, setter, Library.PropertyAttributes.FullAccess), throwOnError: false);
else
obj.DefineProperty(key, new PropertyDescriptor(descriptor.Getter, setter, Library.PropertyAttributes.FullAccess), throwOnError: false);
}