public List <CypherProperty> PropertiesForPurpose <TEntity, TAttr>(ICypherExtensionContext context, TEntity entity) where TEntity : class where TAttr : CypherExtensionAttribute { var key = AddKeyAttribute <TEntity, TAttr>(context, entity); return(_typeProperties[key]); }
internal static string ToCypherString <TEntity, TAttr>(this TEntity entity, ICypherExtensionContext context, string paramKey = null, List <CypherProperty> useProperties = null) where TAttr : CypherExtensionAttribute where TEntity : class { var properties = useProperties ?? CypherTypeItemHelper.PropertiesForPurpose <TEntity, TAttr>(entity); return(entity.GetMatchCypher(context, properties, paramKey)); }
internal static string ApplyCasing(this string value, ICypherExtensionContext context) { var useCamelCase = (context.JsonContractResolver is CamelCasePropertyNamesContractResolver); if (useCamelCase) { return(string.Format( "{0}{1}" , value.Substring(0, 1).ToLowerInvariant() , value.Length > 1 ? value.Substring(1, value.Length - 1) : string.Empty)); } return(value); }
public CypherTypeItem AddKeyAttribute <TEntity, TAttr>(ICypherExtensionContext context, TEntity entity) where TAttr : CypherExtensionAttribute where TEntity : class { var type = entity.GetType(); var key = new CypherTypeItem { Type = type, AttributeType = typeof(TAttr) }; //check cache if (!_typeProperties.ContainsKey(key)) { //strip off properties create map for usage _typeProperties.AddOrUpdate(key, type.GetProperties().Where(x => x.GetCustomAttributes(typeof(TAttr), true).Any()) .Select(x => new CypherProperty { TypeName = x.Name, JsonName = x.Name.ApplyCasing(context) }) .ToList(), (k, e) => e); } return(key); }
internal static string GetMatchCypher <TEntity>(this TEntity entity , ICypherExtensionContext context , List <CypherProperty> useProperties , string paramKey) where TEntity : class { var label = entity.EntityLabel(); paramKey = entity.EntityParamKey(paramKey); var matchProperties = useProperties .Select(x => string.Format("{0}:{{{1}}}.{0}", x.JsonName, GetMatchParamName(paramKey))) .ToList(); var jsonProperties = string.Join(",", matchProperties); var parameterCypher = matchProperties.Count == 0 ? string.Empty : AsWrappedVariable(jsonProperties); var cypher = GetMatchCypher(paramKey, label, parameterCypher); return(cypher); }