GetPropertyValue() public méthode

Gets the value of the property with the given name.
The prototype chain is searched if the property does not exist directly on this object.
public GetPropertyValue ( object key ) : object
key object The property key (either a string or a Symbol).
Résultat object
Exemple #1
0
        /// <summary>
        /// Gets the value of the property with the given name.
        /// </summary>
        /// <param name="key"> The property key (either a string or a Symbol). </param>
        /// <param name="thisValue"> The value of the "this" keyword inside a getter. </param>
        /// <returns> The value of the property, or <c>null</c> if the property doesn't exist. </returns>
        /// <remarks> The prototype chain is searched if the property does not exist directly on
        /// this object. </remarks>
        public override object GetPropertyValue(object key, object thisValue)
        {
            // Check for revocation.
            if (target == null || handler == null)
            {
                throw new JavaScriptException(ErrorType.TypeError, "Cannot call 'get' on a proxy that has been revoked.");
            }

            // Call the handler, if one exists.
            var trap = handler.GetMethod("get");

            if (trap == null)
            {
                return(target.GetPropertyValue(key, thisValue));
            }
            var result = trap.CallLateBound(handler, target, key, thisValue);

            // Validate.
            var targetDescriptor = target.GetOwnPropertyDescriptor(key);

            if (targetDescriptor.Exists && !targetDescriptor.IsConfigurable)
            {
                if (!targetDescriptor.IsAccessor && !targetDescriptor.IsWritable && !TypeComparer.SameValue(result, targetDescriptor.Value))
                {
                    throw new JavaScriptException(ErrorType.TypeError, $"'get' on proxy: property '{TypeConverter.ToString(key)}' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '{TypeConverter.ToString(targetDescriptor.Value)}' but got '{TypeConverter.ToString(result)}').");
                }
                if (targetDescriptor.IsAccessor && targetDescriptor.Getter == null && result != null && result != Undefined.Value)
                {
                    throw new JavaScriptException(ErrorType.TypeError, $"'get' on proxy: property '{TypeConverter.ToString(key)}' is a non-configurable accessor property on the proxy target and does not have a getter function, but the trap did not return 'undefined' (got '{TypeConverter.ToString(result)}').");
                }
            }
            return(result);
        }
Exemple #2
0
        public static object Get(ObjectInstance target, object propertyKey, object receiver = null)
        {
            propertyKey = TypeConverter.ToPropertyKey(propertyKey);
            if (receiver == null)
            {
                receiver = target;
            }
            object result = target.GetPropertyValue(propertyKey, TypeConverter.ToObject(target.Engine, receiver));

            return(result == null ? Undefined.Value : result);
        }
        public static T FromObject <T>(Jurassic.Library.ObjectInstance instance) where T : new()
        {
            if (instance == null)
            {
                return(default(T));
            }

            var ret = new T();

            foreach (var pi in ret.GetType().GetProperties())
            {
                try
                {
                    var value = instance.GetPropertyValue(JsonPropertyName(pi));
                    if (pi.PropertyType.IsPrimitive || pi.PropertyType == typeof(string))
                    {
                        pi.SetValue(ret, Convert.ChangeType(value, pi.PropertyType), null);
                    }
                }
                catch { }
            }
            return(ret);
        }
        public static ResultPerPageFree FromObjectInstance(Jurassic.Library.ObjectInstance instance)
        {
            /*为了简单,省去1万地反射...*/
            var ret = new ResultPerPageFree();

            foreach (var pi in ret.GetType().GetProperties())
            {
                try
                {
                    var value = instance.GetPropertyValue(JsonPropertyName(pi));
                    if (pi.Name == "GroupsList")
                    {
                        var ls = value as ArrayInstance;
                        if (ls != null)
                        {
                            var wxGroups = (from ObjectInstance o in ls.ElementValues select FromObject <WxGroup>(o)).ToList();
                            pi.SetValue(ret, wxGroups, null);
                        }
                    }
                    else if (pi.Name == "FriendsList")
                    {
                        var ls = value as ArrayInstance;
                        if (ls != null)
                        {
                            var wxGroups = (from ObjectInstance o in ls.ElementValues select FromObject <WxUserFree>(o)).ToList();
                            pi.SetValue(ret, wxGroups, null);
                        }
                    }
                    else
                    {
                        pi.SetValue(ret, Convert.ChangeType(value, pi.PropertyType), null);
                    }
                }
                catch { }
            }
            return(ret);
        }
        public void SendEmail(ObjectInstance email)
        {
            if (email == null)
                throw new ArgumentNullException("email");

            foreach (var requiredProperty in new[] { "BodyText", "Subject", "Recipients" })
            {
                if (email.HasProperty(requiredProperty))
                    continue;
                throw new ArgumentException(string.Format("Property {0} is mandatory", requiredProperty));
            }

            MailItem newMail = application.CreateItem(OlItemType.olMailItem);

            newMail.Body = email.GetPropertyValue("BodyText").ToString();
            newMail.Subject = email.GetPropertyValue("Subject").ToString();

            var recipients = email.GetPropertyValue("Recipients").ToString().Split(',');

            foreach (var rec in recipients.Select(recipient => newMail.Recipients.Add(recipient)))
                rec.Resolve();

            newMail.Send();
        }
        public ArrayInstance GetMailsForFolder(ObjectInstance parameters)
        {
            if (parameters.HasProperty("UniqueId"))
                return GetMailsForFolderInternal(parameters.GetPropertyValue("UniqueId").ToString(), null);

            if (parameters.HasProperty("FolderName"))
            {
                var folderPath = parameters.GetPropertyValue("FolderName").ToString().Split('/');

                if (folderPath.Length != 2)
                    throw new NotSupportedException("At the moment only paths like 'Personal Folders/Foo' are supported");

                var root = folderPath.First();
                var folderName = folderPath.Last();

                var children = GetChildrenFor(root);
                foreach (FolderInstance child in children.ElementValues.Cast<FolderInstance>()
                                                            .Where(child => child.GetPropertyValue("Name").ToString() == folderName))
                    return GetMailsForFolderInternal(child.GetPropertyValue("UniqueId").ToString(), null);
                return Engine.Array.New();
            }

            throw new NotSupportedException(string.Format("Requires an object with either 'UniqueId' or 'FolderName' as parameter"));
        }