private JToken SerializeMetadata() { var valueType = _value.GetType(); var isCollection = false; if (typeof(IEnumerable).IsAssignableFrom(valueType)) { isCollection = true; valueType = valueType.GetGenericTypeParameterOfCollection() ?? valueType; } var metaObject = _resource.GetMetadata(_value, valueType, isCollection); if (metaObject is JToken) { return(metaObject as JToken); } return(metaObject == null ? null : JToken.FromObject(metaObject, _serializer)); }
private JToken SerializeMetadata() { var valueType = _value.GetType(); var isCollection = false; if (typeof(IEnumerable).IsAssignableFrom(valueType)) { isCollection = true; // if our value is an enumerable, get the type of the items in the collection var collectionType = valueType.GetInterfaces().FirstOrDefault(i => i.Name.Contains("IEnumerable") && i.IsGenericType); valueType = collectionType?.GenericTypeArguments[0] ?? valueType; } var metaObject = _resource.GetMetadata(_value, valueType, isCollection); if (metaObject is JToken) { return(metaObject as JToken); } return(metaObject == null ? null : JToken.FromObject(metaObject, _serializer)); }