using BinaryDad.Extensions; using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Salesforce.NET { internal static class PropertyExtensions { internal static IEnumerable WhereIsSerializable(this IEnumerable properties) { foreach (var property in properties) { var jsonIgnore = property.GetCustomAttribute(); if (jsonIgnore == null) { yield return property; } } } internal static IEnumerable WhereIsQueryable(this IEnumerable properties) { foreach (var property in properties) { var queryIgnore = property.GetCustomAttribute(); if (queryIgnore == null) { yield return property; } } } internal static IDictionary GetPropertyValues(this IEnumerable properties, object value) { return properties .Select(p => { var propertyName = GetSalesforcePropertyName(p); var propertyValue = p.GetValue(value); return new KeyValuePair(propertyName, propertyValue); }) .ToDictionary(); } internal static IEnumerable GetPropertyNames(this IEnumerable properties) { foreach (var property in properties) { yield return GetSalesforcePropertyName(property); } } private static string GetSalesforcePropertyName(PropertyInfo propertyInfo) { var jsonProperty = propertyInfo.GetCustomAttribute(); return jsonProperty?.PropertyName ?? propertyInfo.Name; } } }