Пример #1
0
 public static ExpandoObject ShapeDataWithRequestedFields <TSource>(this TSource obj, string fieldsSeparatedByCommas = null, bool addLinks = false) where TSource : class
 {
     if (obj != null)
     {
         List <PropertyInfo> propertyListInfo = ExtensionHelper.GetPropertiesFromObject <TSource>(fieldsSeparatedByCommas, addLinks);
         return(ExtensionHelper.CreateExpandoObjectFromProperties(obj, propertyListInfo));
     }
     throw new ArgumentNullException();
 }
Пример #2
0
        public static IEnumerable <ExpandoObject> ShapeCollectionDataWithRequestedFields <TSource>(this IEnumerable <TSource> collection, string fieldsSeparatedByCommas = null, bool addLinks = false)
        {
            IList <ExpandoObject> dynamicCollection = new List <ExpandoObject>();

            if (collection != null)
            {
                List <PropertyInfo> propertyListInfo = ExtensionHelper.GetPropertiesFromObject <TSource>(fieldsSeparatedByCommas, addLinks);
                foreach (TSource element in collection)
                {
                    ExpandoObject dynamicObject = ExtensionHelper.CreateExpandoObjectFromProperties(element, propertyListInfo);
                    dynamicCollection.Add(dynamicObject);
                }
                return(dynamicCollection);
            }
            throw new ArgumentNullException("The collection is empty");
        }