Exemplo n.º 1
0
        /// <summary>Enumerates all properties and accounts for any custom ones if the object defines it.</summary>
        public IEnumerable <string> PropertyEnumerator(object obj)
        {
            // Got a custom one?
            PropertyVariable pv = GetProperty("Properties");

            if (pv == null)
            {
                foreach (KeyValuePair <string, PropertyVariable> kvp in Properties)
                {
                    if (kvp.Value.IsEnumerable)
                    {
                        yield return(kvp.Key);
                    }
                }
            }
            else
            {
                // Get the value:
                IEnumerable <string> set = pv.GetValue(obj) as IEnumerable <string>;

                // Iterate it:
                foreach (string str in set)
                {
                    yield return(str);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Enumerates all the values in the given object.</summary>
        public IEnumerable <object> PropertyValues(object obj)
        {
            // Got a custom one?
            PropertyVariable pv = GetProperty("PropertyValues");

            if (pv == null)
            {
                foreach (KeyValuePair <string, PropertyVariable> kvp in Properties)
                {
                    if (kvp.Value.IsEnumerable)
                    {
                        // Read the value:
                        object value = kvp.Value.GetValue(obj);

                        yield return(value);
                    }
                }
            }
            else
            {
                // Get the value:
                IEnumerable <object> set = pv.GetValue(obj) as IEnumerable <object>;

                // Iterate it:
                foreach (object s in set)
                {
                    yield return(s);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>Pulls a generic property from the given object at runtime.</summary>
        public static object GetPropertyValue(ScriptEngine engine, object thisObj, string property)
        {
            // Exists?
            if (thisObj == null)
            {
                throw new NullReferenceException("Attempted to read property '" + property + "' from a null reference.");
            }

            // Get the prototype:
            Prototype proto = engine.Prototypes.Get(thisObj.GetType());

            // Get the property:
            PropertyVariable pv = proto.GetProperty(property);

            if (pv == null)
            {
                // Undefined:
                return(Nitrassic.Undefined.Value);
            }

            // Get the value:
            return(pv.GetValue(thisObj));
        }