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); }
static IEnumerable <TemplateProperty> GetProperties(object value, ITemplatePropertyValueFactory recursive) { var properties = #if USE_REFLECTION_40 value.GetType().GetProperties().Where(p => p.CanRead && p.GetGetMethod().IsPublic&& !p.GetGetMethod().IsStatic&& (p.Name != "Item" || p.GetIndexParameters().Length == 0)); #else value.GetType().GetPropertiesRecursive(); #endif foreach (var prop in properties) { object propValue; try { #if USE_REFLECTION_40 propValue = prop.GetValue(value, null); #else propValue = prop.GetValue(value); #endif } catch (TargetParameterCountException) { SelfLog.WriteLine("The property accessor {0} is a non-default indexer", prop); continue; } catch (TargetInvocationException ex) { SelfLog.WriteLine("The property accessor {0} threw exception {1}", prop, ex); propValue = "The property accessor threw an exception: " + ex.InnerException.GetType().Name; } yield return(new TemplateProperty(prop.Name, recursive.CreatePropertyValue(propValue, true))); } }
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 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 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) { #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 TryDestructure(object value, ITemplatePropertyValueFactory propertyValueFactory, out TemplatePropertyValue result) { if (value == null) { throw new ArgumentNullException("value"); } if (!_canApply(value.GetType())) { result = null; return(false); } var projected = _projection(value); result = propertyValueFactory.CreatePropertyValue(projected, true); return(true); }
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; }
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); }
static IEnumerable<TemplateProperty> GetProperties(object value, ITemplatePropertyValueFactory recursive) { var properties = #if USE_REFLECTION_40 value.GetType().GetProperties().Where(p => p.CanRead && p.GetGetMethod().IsPublic && !p.GetGetMethod().IsStatic && (p.Name != "Item" || p.GetIndexParameters().Length == 0)); #else value.GetType().GetPropertiesRecursive(); #endif foreach (var prop in properties) { object propValue; try { #if USE_REFLECTION_40 propValue = prop.GetValue(value, null); #else propValue = prop.GetValue(value); #endif } catch (TargetParameterCountException) { SelfLog.WriteLine("The property accessor {0} is a non-default indexer", prop); continue; } catch (TargetInvocationException ex) { SelfLog.WriteLine("The property accessor {0} threw exception {1}", prop, ex); propValue = "The property accessor threw an exception: " + ex.InnerException.GetType().Name; } yield return new TemplateProperty(prop.Name, recursive.CreatePropertyValue(propValue, true)); } }