using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using xCommons.Extensions; using xModels.Base; namespace xDataService.Extensions { public static class EntityExtensions { /// /// return all values of an entity properties as a json string ... /// /// /// /// public static string GetPropValues (this T item) where T : XBaseEntity { // var props = item.GetType ().GetProperties (); var vals = props.Select (p => p.GetValue (item)); // return vals.ToJSON (); } /// /// check values of all properties of an Entity contains specific value or not ... /// /// /// /// /// public static bool PropValuesContains (this T item, string value) where T : XBaseEntity => item.GetPropValues () .ToNormalString () .Contains (value); /// /// Retrieve Default Column Map of specific Entity ... /// /// /// /// public static IDictionary>> GetDefaultColumnsMap (this T item) where T : XBaseEntity { // if (item.IsNull ()) { return null; } // var result = new Dictionary>> (); var props = item.GetType ().GetProperties (); // foreach (var prop in props) { result.Add ( prop.Name, t => t.GetType ().GetProperty (prop.Name).GetValue (t, null)); } // return result; } /// /// Check a Type is XBaseEntity or not ... /// /// /// public static bool IsXEntity(this Type source) { // var result = !source.IsNull(); if (!result) { return result; } // var baseType = source.BaseType; while(!baseType.IsNull() && baseType != typeof(object)) { // if (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(XBaseEntity<>)) { result = true; break; } // baseType = baseType.BaseType; } // return result; } } }