コード例 #1
0
        /// <summary>
        /// Callback for enumerating property names and values.
        /// </summary>
        /// <param name="key"> The object instance to retrieve the properties for. </param>
        /// <returns> An enumerable list of ExpandableObjectProperty instances. </returns>
        private IEnumerable <ExpandableObjectProperty> EnumerateProperties(object key)
        {
            var obj = key as Jurassic.Library.ObjectInstance;

            if (obj == null)
            {
                throw new InvalidOperationException("Can only enumerate ObjectInstances.");
            }
            foreach (var property in obj.Properties)
            {
                object value     = (property.Attributes & ~PropertyAttributes.FullAccess) == 0 ? property.Value : obj[property.Name];
                Color  color     = Colors.Black;
                string valueText = Jurassic.TypeConverter.ToString(value);
                if (value is string)
                {
                    // Make sure the string isn't too long.
                    if (valueText.Length > 100)
                    {
                        valueText = valueText.Substring(0, 100) + "...";
                    }
                    valueText = Jurassic.Library.StringInstance.Quote(valueText);
                }
                else if (property.Value == null || value == Jurassic.Undefined.Value)
                {
                    color = Colors.Gray;
                }
                var result = new ExpandableObjectProperty(property.Name, valueText, value as Jurassic.Library.ObjectInstance);
                result.Color = color;
                yield return(result);
            }
        }
コード例 #2
0
 /// <summary>
 /// Callback for enumerating property names and values.
 /// </summary>
 /// <param name="key"> The object instance to retrieve the properties for. </param>
 /// <returns> An enumerable list of ExpandableObjectProperty instances. </returns>
 private IEnumerable<ExpandableObjectProperty> EnumerateProperties(object key)
 {
     var obj = key as Jurassic.Library.ObjectInstance;
     if (obj == null)
         throw new InvalidOperationException("Can only enumerate ObjectInstances.");
     foreach (var property in obj.Properties)
     {
         object value = (property.Attributes & ~PropertyAttributes.FullAccess) == 0 ? property.Value : obj[property.Name];
         Color color = Colors.Black;
         string valueText = Jurassic.TypeConverter.ToString(value);
         if (value is string)
         {
             // Make sure the string isn't too long.
             if (valueText.Length > 100)
                 valueText = valueText.Substring(0, 100) + "...";
             valueText = Jurassic.Library.StringInstance.Quote(valueText);
         }
         else if (property.Value == null || value == Jurassic.Undefined.Value)
             color = Colors.Gray;
         var result = new ExpandableObjectProperty(property.Name, valueText, value as Jurassic.Library.ObjectInstance);
         result.Color = color;
         yield return result;
     }
 }