Esempio n. 1
0
        /// <summary>
        /// Populates the Included Property with ResourceObjects
        /// </summary>
        /// <param name="dataSet">The data conatining the properties</param>
        /// <param name="includedProperties">Defines which properties are to be included</param>
        private void SetupIncludes(IEnumerable <T> dataSet, IEnumerable <PropertyInfo> includedProperties, Uri queryString = null)
        {
            // ignore if no data is present
            if (!includedProperties.Any())
            {
                return;
            }

            if (Included == null)
            {
                Included = new JsonApiResourceObjectDictionary();
            }
            // process each item in data
            foreach (var data in dataSet)
            {
                // iterate over all of the items' properties and look for the requested properties
                var propertiesArray = data.GetType().GetProperties();
                foreach (var propertyInfo in propertiesArray)
                {
                    if (includedProperties.Any(x => x.Name == propertyInfo.Name))
                    {
                        if (typeof(IJsonApiDataModel).IsAssignableFrom(propertyInfo.PropertyType))
                        {
                            var rawData = propertyInfo.GetValue(data) as IJsonApiDataModel;
                            Included.AddResource(JsonApiResourceBuilder.Build(rawData, false));
                        }
                        else if (propertyInfo.PropertyType.IsNonStringEnumerable() && propertyInfo.GetValue(data) is IEnumerable <IJsonApiDataModel> rawData)
                        {
                            foreach (var item in rawData)
                            {
                                Included.AddResource(JsonApiResourceBuilder.Build(item, false));
                            }
                        }
                    }
                }
            }
            if (Included.ResourceObjectDictionary.Count < 1)
            {
                Included = null;
            }
        }
 public static JsonApiResourceObject GetResource(this JsonApiResourceObjectDictionary resourceDictionary, object id, Type type)
 {
     return(resourceDictionary.GetResource(BtbrdCoreIdConverters.ConvertToString(id), type.GetJsonApiClassName()));
 }
 public static JsonApiResourceObject GetResource(this JsonApiResourceObjectDictionary resourceDictionary, object id, JsonApiResource apiResource)
 {
     return(resourceDictionary.GetResource(BtbrdCoreIdConverters.ConvertToString(id), apiResource.ResourceType));
 }