public bool TryConvertToScalar(object value, ITemplatePropertyValueFactory propertyValueFactory, out ScalarValue result)
 {
     var type = value.GetType();
     #if USE_REFLECTION_40
     if (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(Nullable<>))
     #else
     if (!type.IsConstructedGenericType || type.GetGenericTypeDefinition() != typeof(Nullable<>))
     #endif
     {
         result = null;
         return false;
     }
     #if USE_DYNAMIC
     var dynamicValue = (dynamic)value;
     var innerValue = dynamicValue.HasValue ? (object)dynamicValue.Value : null;
     #elif USE_REFLECTION_40
     var targetType = type.GetGenericArguments()[0];
     var innerValue = Convert.ChangeType(value, targetType, null);
     #else
     var targetType = type.GenericTypeArguments[0];
     var innerValue = Convert.ChangeType(value, targetType);
     #endif
     result = propertyValueFactory.CreatePropertyValue(innerValue) as ScalarValue;
     return result != null;
 }
        public bool TryConvertToScalar(object value, ITemplatePropertyValueFactory propertyValueFactory, out ScalarValue result)
        {
            if (_scalarTypes.Contains(value.GetType()))
            {
                result = new ScalarValue(value);
                return true;
            }

            result = null;
            return false;
        }
        public bool TryDestructure(object value, ITemplatePropertyValueFactory propertyValueFactory, out TemplatePropertyValue result)
        {
            var del = value as Delegate;
            if (del != null)
            {
                result = new ScalarValue(del.ToString());
                return true;
            }

            result = null;
            return false;
        }
        public bool TryConvertToScalar(object value, ITemplatePropertyValueFactory propertyValueFactory, out ScalarValue result)
        {
            // These types and their subclasses are property-laden and deep;
            // most sinks will convert them to strings.
            if (value is Type || value is MemberInfo)
            {
                result = new ScalarValue(value);
                return true;
            }

            result = null;
            return false;
        }
        public bool TryConvertToScalar(object value, ITemplatePropertyValueFactory propertyValueFactory, out ScalarValue result)
        {
            #if USE_REFLECTION_40
            if (value.GetType().IsEnum)
            #else
            if (value.GetType().GetTypeInfo().IsEnum)
            #endif
            {
                result = new ScalarValue(value);
                return true;
            }

            result = null;
            return false;
        }
        public bool TryConvertToScalar(object value, ITemplatePropertyValueFactory propertyValueFactory, out ScalarValue result)
        {
            var bytes = value as byte[];
            if (bytes == null)
            {
                result = null;
                return false;
            }

            if (bytes.Length > MaximumByteArrayLength)
            {
                var start = string.Concat(bytes.Take(16).Select(b => b.ToString("X2")));
                var description = start + "... (" + bytes.Length + " bytes)";
                result = new ScalarValue(description);
            }
            else
            {
                result = new ScalarValue(bytes.ToArray());
            }

            return true;
        }