public static LineLocator <S> LineLocator <T, S>(this ILineContainer <T> lineContainer, Expression <Func <T, S> > property) where T : IModifiableEntity { PropertyRoute route = lineContainer.Route ?? PropertyRoute.Root(typeof(T)); var element = lineContainer.Element; foreach (var mi in Reflector.GetMemberList(property)) { if (mi is MethodInfo && ((MethodInfo)mi).IsInstantiationOf(MixinDeclarations.miMixin)) { route = route.Add(((MethodInfo)mi).GetGenericArguments()[0]); } else { var newRoute = route.Add(mi); if (newRoute.Parent != route && route != lineContainer.Route) { element = element.FindElement(By.CssSelector("[data-property-path='" + route.PropertyString() + "']")); } route = newRoute; } } return(new LineLocator <S>( elementLocator: element.WithLocator(By.CssSelector("[data-property-path='" + route.PropertyString() + "']")), route: route )); }
static void AddBinding <T>(PropertyRoute route) where T : Entity { var entityEvents = Schema.Current.EntityEvents <T>(); entityEvents.RegisterBinding <PrimaryKey>(route.Add(nameof(FilePathEmbedded.EntityId)), () => true, (t, rowId) => t.Id, (t, rowId, retriever) => t.Id); entityEvents.RegisterBinding <PrimaryKey?>(route.Add(nameof(FilePathEmbedded.MListRowId)), () => true, (t, rowId) => rowId, (t, rowId, retriever) => rowId); var routeType = TypeLogic.GetCleanName(route.RootType); entityEvents.RegisterBinding <string>(route.Add(nameof(FilePathEmbedded.RootType)), () => true, (t, rowId) => routeType, (t, rowId, retriever) => routeType); var propertyRoute = route.PropertyString(); entityEvents.RegisterBinding <string>(route.Add(nameof(FilePathEmbedded.PropertyRoute)), () => true, (t, rowId) => propertyRoute, (t, rowId, retriever) => propertyRoute); }
public static void Register(SchemaBuilder sb, PropertyRoute route, BigStringConfiguration config) { if (sb.Schema.Tables.ContainsKey(route.RootType)) { throw new InvalidOperationException($"{route.RootType} is already included in the Schema. You need to call BigStringLogic.Register earlier in your Starter.Start method."); } if (route.PropertyInfo !.GetCustomAttribute <NotifyChildPropertyAttribute>() == null) { throw new InvalidOperationException($"BigString {route} should have a [NotifyChildPropertyAttribute]."); } if (config.Mode == BigStringMode.Database) { sb.Schema.Settings.FieldAttributes(route.Add(typeof(BigStringMixin)).Add(piFile)) !.Add(new IgnoreAttribute()); } else { if (config.Mode == BigStringMode.File) { sb.Schema.Settings.FieldAttributes(route.Add(piText)) !.Add(new IgnoreAttribute()); } if (config.FileTypeSymbol == null) { throw new InvalidOperationException($"{config.Mode} requires a FileTypeSymbol"); } } Configurations.Add(route, config); }
public static void TaskSetImplementations(LineBase bl) { EntityBase eb = bl as EntityBase; if (eb != null) { PropertyRoute route = bl.PropertyRoute; if (bl.Type.IsMList()) { route = route.Add("Item"); } if (route.Type.CleanType().IsIEntity()) { IImplementationsFinder finder = typeof(ModelEntity).IsAssignableFrom(route.RootType) ? (IImplementationsFinder)Navigator.EntitySettings(route.RootType) : Schema.Current; eb.Implementations = finder.FindImplementations(route); if (eb.Implementations.Value.IsByAll) { EntityLine el = eb as EntityLine; if (el != null) { el.Autocomplete = false; } } } } }
internal override void SetFullMListGetter(PropertyRoute route, Func <Entity, object> getter) { foreach (var field in Fields.Values) { field.Field.SetFullMListGetter(route.Add(field.FieldInfo), entity => field.Getter(getter(entity))); } }
public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route) { if (pc.CustomWriteJsonProperty != null) { pc.CustomWriteJsonProperty(new WriteJsonPropertyContext { JsonWriter = writer, JsonSerializer = serializer, LowerCaseName = lowerCaseName, Entity = mod, ParentPropertyRoute = route, PropertyConverter = pc }); } else { var pr = route.Add(pc.PropertyValidator.PropertyInfo); string error = CanReadPropertyRoute?.Invoke(pr); if (error != null) { return; } using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { writer.WritePropertyName(lowerCaseName); serializer.Serialize(writer, pc.GetValue(mod)); } } }
public static PropertyRoute GetRoute <T, S>(this ILineContainer <T> container, Expression <Func <T, S> > property) where T : ModifiableEntity { PropertyRoute result = container.PreviousRoute ?? PropertyRoute.Root(typeof(T)); foreach (var mi in Reflector.GetMemberList(property)) { result = result.Add(mi); } return(result); }
public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext( jsonReader: reader, jsonSerializer: serializer, entity: entity, parentPropertyRoute: parentRoute, propertyConverter: pc )); } else { object?oldValue = pc.GetValue !(entity); var pi = pc.PropertyValidator !.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType.Nullify(), oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { if (!pi.HasAttribute <IgnoreAttribute>()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) { entity.SetTemporalError(pi, ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); return; } pc.SetValue?.Invoke(entity, newValue); } } } } }
public override PropertyRoute GetEntityPropertyRoute() { PropertyRoute tc = base.GetEntityPropertyRoute(); if (tc == null) { return(null); } return(tc.Add("Item")); }
public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext { JsonReader = reader, JsonSerializer = serializer, Entity = entity, ParentPropertyRoute = parentRoute, PropertyConverter = pc, }); } else { object oldValue = pc.GetValue(entity); var pi = pc.PropertyValidator.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType, oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) //JSON.Net already complaining { return; } pc.SetValue?.Invoke(entity, newValue); } } } } }
public static PropertyRoute Continue(PropertyRoute route, string continuation) { string[] steps = continuation.Replace("/", ".Item.").Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); PropertyRoute context = route; foreach (var step in steps) { context = context.Add(step); } return(context); }
public static PropertyRoute GetRoute <T, S>(this ILineContainer <T> lineContainer, Expression <Func <T, S> > property, out string newPrefix) where T : ModifiableEntity { newPrefix = lineContainer.Prefix; PropertyRoute result = lineContainer.Route ?? PropertyRoute.Root(typeof(T)); foreach (var mi in Reflector.GetMemberList(property)) { if (mi is MethodInfo && ((MethodInfo)mi).IsInstantiationOf(MixinDeclarations.miMixin)) { result = result.Add(((MethodInfo)mi).GetGenericArguments()[0]); } else { result = result.Add(mi); if (newPrefix.HasText()) { newPrefix += "_"; } newPrefix += mi.Name; } } return(result); }
public override PropertyRoute GetPropertyRoute() { if (Parent is ExtensionToken et && et.IsProjection) { return(et.GetElementPropertyRoute()); } PropertyRoute parent = Parent.GetPropertyRoute(); if (parent != null && parent.Type.ElementType() != null) { return(parent.Add("Item")); } return(parent); }
private Dictionary <Type, FieldMixin> GenerateMixins(PropertyRoute propertyRoute, Table table, NameSequence nameSequence) { Dictionary <Type, FieldMixin> mixins = null; foreach (var t in MixinDeclarations.GetMixinDeclarations(table.Type)) { if (mixins == null) { mixins = new Dictionary <Type, FieldMixin>(); } mixins.Add(t, this.GenerateFieldMixin(propertyRoute.Add(t), nameSequence, table)); } return(mixins); }
public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route) { if (pc.CustomWriteJsonProperty != null) { pc.CustomWriteJsonProperty(new WriteJsonPropertyContext { JsonWriter = writer, JsonSerializer = serializer, LowerCaseName = lowerCaseName, Entity = mod, ParentPropertyRoute = route, PropertyConverter = pc }); } else { var pr = route.Add(pc.PropertyValidator.PropertyInfo); string error = CanReadPropertyRoute?.Invoke(pr); if (error != null) { return; } using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { writer.WritePropertyName(lowerCaseName); var val = pc.GetValue(mod); if (val is Lite <Entity> lite) { new LiteJsonConverter().WriteJson(writer, lite, serializer); } else { serializer.Serialize(writer, pc.GetValue(mod)); } if (writer.WriteState == WriteState.Property) { throw new InvalidOperationException($"Impossible to serialize '{mod}' to JSON. Maybe there is a cycle?"); } } } }
internal override void SetFullMListGetter(PropertyRoute route, Func <Entity, object> getter) { foreach (var item in EmbeddedFields.Values) { item.Field.SetFullMListGetter(route.Add(item.FieldInfo), entity => { var embedded = getter(entity); if (embedded == null) { return(null); } return(item.Getter(embedded)); }); } }
static Expression <Func <object, bool> > GetPredicate(List <PropertySetter> predicate, PropertyRoute mainRoute, JsonSerializerOptions options) { var param = Expression.Parameter(typeof(object), "p"); var body = predicate.Select(p => { var pr = mainRoute.Add(p.Property); var lambda = pr.GetLambdaExpression <object, object>(true, mainRoute.GetMListItemsRoute()); var left = Expression.Invoke(lambda, param); object?objClean = ConvertObject(p.Value, pr, options); return((Expression)QueryUtils.GetCompareExpression(p.FilterOperation !.Value, left, Expression.Constant(objClean), inMemory: true)); }).Aggregate((a, b) => Expression.AndAlso(a, b)); return(Expression.Lambda <Func <object, bool> >(body, param)); }
internal PropertyRoute AddPropertyRoute(PropertyInfo pi) { if (typeof(ModelEntity).IsAssignableFrom(Type)) { return(PropertyRoute.Root(Type).Add(pi)); } Type type = Lite.Extract(Type); //Because Add doesn't work with lites if (type != null) { return(PropertyRoute.Root(type).Add(pi)); } PropertyRoute pr = GetPropertyRoute(); if (pr == null) { return(null); } return(pr.Add(pi)); }
public static void SetSetters(ModifiableEntity entity, List <PropertySetter> setters, PropertyRoute route) { var options = SignumServer.JsonSerializerOptions; foreach (var setter in setters) { var pr = route.Add(setter.Property); SignumServer.WebEntityJsonConverterFactory.AssertCanWrite(pr, entity); if (pr.Type.IsMList()) { var elementPr = pr.Add("Item"); var mlist = pr.GetLambdaExpression <ModifiableEntity, IMListPrivate>(false).Compile()(entity); switch (setter.Operation) { case PropertyOperation.AddElement: { var item = (ModifiableEntity)Activator.CreateInstance(elementPr.Type) !; SetSetters(item, setter.Setters !, elementPr); ((IList)mlist).Add(item); } break; case PropertyOperation.ChangeElements: { var predicate = GetPredicate(setter.Predicate !, elementPr, options); var toChange = ((IEnumerable <object>)mlist).Where(predicate.Compile()).ToList(); foreach (var item in toChange) { SetSetters((ModifiableEntity)item, setter.Setters !, elementPr); } } break; case PropertyOperation.RemoveElements: { var predicate = GetPredicate(setter.Predicate !, elementPr, options); var toRemove = ((IEnumerable <object>)mlist).Where(predicate.Compile()).ToList(); foreach (var item in toRemove) { ((IList)mlist).Remove(item); } } break; default: break; } } else if (setter.Operation == PropertyOperation.CreateNewEntity) { var subPr = pr.Type.IsEmbeddedEntity() ? pr : PropertyRoute.Root(TypeLogic.GetType(setter.EntityType !)); var item = (ModifiableEntity)Activator.CreateInstance(subPr.Type) !; SetSetters(item, setter.Setters !, subPr); SetProperty(entity, pr, route, item); } else if (setter.Operation == PropertyOperation.ModifyEntity) { var item = GetProperty(entity, pr, route); if (!(item is ModifiableEntity mod)) { throw new InvalidOperationException($"Unable to change entity in {pr}: {item}"); } SetSetters(mod, setter.Setters !, pr); SetProperty(entity, pr, route, mod); } else { var value = ConvertObject(setter.Value, pr, options); SetProperty(entity, pr, route, value); } } }
public override void WriteJson(JsonWriter writer, object?value, JsonSerializer serializer) { using (HeavyProfiler.LogNoStackTrace("WriteJson", () => value !.GetType().Name)) { PropertyRoute pr = GetCurrentPropertyRoute(value !); ModifiableEntity mod = (ModifiableEntity)value !; writer.WriteStartObject(); if (mod is Entity entity) { writer.WritePropertyName("Type"); writer.WriteValue(TypeLogic.TryGetCleanName(mod.GetType())); writer.WritePropertyName("id"); writer.WriteValue(entity.IdOrNull == null ? null : entity.Id.Object); if (entity.IsNew) { writer.WritePropertyName("isNew"); writer.WriteValue(true); } if (Schema.Current.Table(entity.GetType()).Ticks != null) { writer.WritePropertyName("ticks"); writer.WriteValue(entity.Ticks.ToString()); } } else { writer.WritePropertyName("Type"); writer.WriteValue(mod.GetType().Name); } if (!(mod is MixinEntity)) { writer.WritePropertyName("toStr"); writer.WriteValue(mod.ToString()); } writer.WritePropertyName("modified"); writer.WriteValue(mod.Modified == ModifiedState.Modified || mod.Modified == ModifiedState.SelfModified); foreach (var kvp in PropertyConverter.GetPropertyConverters(value !.GetType())) { WriteJsonProperty(writer, serializer, mod, kvp.Key, kvp.Value, pr); } if (mod.Mixins.Any()) { writer.WritePropertyName("mixins"); writer.WriteStartObject(); foreach (var m in mod.Mixins) { var prm = pr.Add(m.GetType()); using (JsonSerializerExtensions.SetCurrentPropertyRoute(prm)) { writer.WritePropertyName(m.GetType().Name); serializer.Serialize(writer, m); } } writer.WriteEndObject(); } writer.WriteEndObject(); } }
protected Dictionary <string, EntityField> GenerateFields(PropertyRoute root, ITable table, NameSequence preName, bool forceNull, bool inMList) { Dictionary <string, EntityField> result = new Dictionary <string, EntityField>(); var type = root.Type; if (type.IsEntity()) { { PropertyRoute route = root.Add(fiId); Field field = GenerateField(table, route, preName, forceNull, inMList); result.Add(fiId.Name, new EntityField(type, fiId) { Field = field }); } TicksColumnAttribute t = type.GetCustomAttribute <TicksColumnAttribute>(); if (t == null || t.HasTicks) { PropertyRoute route = root.Add(fiTicks); Field field = GenerateField(table, route, preName, forceNull, inMList); result.Add(fiTicks.Name, new EntityField(type, fiTicks) { Field = field }); } Expression exp = ExpressionCleaner.GetFieldExpansion(type, EntityExpression.ToStringMethod); if (exp == null) { PropertyRoute route = root.Add(fiToStr); Field field = GenerateField(table, route, preName, forceNull, inMList); if (result.ContainsKey(fiToStr.Name)) { throw new InvalidOperationException("Duplicated field with name {0} on {1}, shadowing not supported".FormatWith(fiToStr.Name, type.TypeName())); } result.Add(fiToStr.Name, new EntityField(type, fiToStr) { Field = field }); } } foreach (FieldInfo fi in Reflector.InstanceFieldsInOrder(type)) { PropertyRoute route = root.Add(fi); if (Settings.FieldAttribute <IgnoreAttribute>(route) == null) { if (Reflector.TryFindPropertyInfo(fi) == null && !fi.IsPublic && !fi.HasAttribute <FieldWithoutPropertyAttribute>()) { throw new InvalidOperationException("Field '{0}' of type '{1}' has no property".FormatWith(fi.Name, type.Name)); } Field field = GenerateField(table, route, preName, forceNull, inMList); if (result.ContainsKey(fi.Name)) { throw new InvalidOperationException("Duplicated field with name '{0}' on '{1}', shadowing not supported".FormatWith(fi.Name, type.TypeName())); } result.Add(fi.Name, new EntityField(type, fi) { Field = field }); } } return(result); }
protected virtual FieldMList GenerateFieldMList(Table table, PropertyRoute route, NameSequence name) { Type elementType = route.Type.ElementType(); if (table.Ticks == null) { throw new InvalidOperationException("Type '{0}' has field '{1}' but does not Ticks. MList requires concurrency control.".FormatWith(route.Parent.Type.TypeName(), route.FieldInfo.FieldName())); } var orderAttr = Settings.FieldAttribute <PreserveOrderAttribute>(route); FieldValue order = null; if (orderAttr != null) { var pair = Settings.GetSqlDbTypePair(typeof(int)); order = new FieldValue(typeof(int)) { Name = orderAttr.Name ?? "Order", SqlDbType = pair.SqlDbType, UserDefinedTypeName = pair.UserDefinedTypeName, Nullable = false, Size = Settings.GetSqlSize(orderAttr, pair.SqlDbType), Scale = Settings.GetSqlScale(orderAttr, pair.SqlDbType), }; } var keyAttr = Settings.FieldAttribute <PrimaryKeyAttribute>(route) ?? Settings.DefaultPrimaryKeyAttribute; TableMList.PrimaryKeyColumn primaryKey; { var pair = Settings.GetSqlDbType(keyAttr, keyAttr.Type); primaryKey = new TableMList.PrimaryKeyColumn { Name = keyAttr.Name, Type = keyAttr.Type, SqlDbType = pair.SqlDbType, UserDefinedTypeName = pair.UserDefinedTypeName, Default = keyAttr.Default, Identity = keyAttr.Identity, }; } TableMList relationalTable = new TableMList(route.Type) { Name = GenerateTableNameCollection(table, name, Settings.FieldAttribute <TableNameAttribute>(route)), PrimaryKey = primaryKey, BackReference = new FieldReference(table.Type) { Name = GenerateBackReferenceName(table.Type, Settings.FieldAttribute <BackReferenceColumnNameAttribute>(route)), ReferenceTable = table, AvoidForeignKey = Settings.FieldAttribute <AvoidForeignKeyAttribute>(route) != null, }, Order = order, }; relationalTable.Field = GenerateField(relationalTable, route.Add("Item"), NameSequence.Void, forceNull: false, inMList: true); relationalTable.GenerateColumns(); return(new FieldMList(route.Type) { TableMList = relationalTable, }); }
public void WriteJsonProperty(JsonWriter writer, JsonSerializer serializer, ModifiableEntity mod, string lowerCaseName, PropertyConverter pc, PropertyRoute route) { if (pc.CustomWriteJsonProperty != null) { pc.CustomWriteJsonProperty(new WriteJsonPropertyContext { JsonWriter = writer, JsonSerializer = serializer, LowerCaseName = lowerCaseName, Entity = mod, ParentPropertyRoute = route, PropertyConverter = pc }); } else { var pr = route.Add(pc.PropertyValidator.PropertyInfo); string error = CanReadPropertyRoute?.Invoke(pr); if (error != null) return; using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { writer.WritePropertyName(lowerCaseName); serializer.Serialize(writer, pc.GetValue(mod)); } } }
internal override void SetFullMListGetter(PropertyRoute route, Func<Entity, object> getter) { foreach (var field in Fields.Values) { field.Field.SetFullMListGetter(route.Add(field.FieldInfo), entity => field.Getter(getter(entity))); } }
internal override void SetFullMListGetter(PropertyRoute route, Func<Entity, object> getter) { foreach (var item in EmbeddedFields.Values) { item.Field.SetFullMListGetter(route.Add(item.FieldInfo), entity => { var embedded = getter(entity); if (embedded == null) return null; return item.Getter(embedded); }); } }
public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext { JsonReader = reader, JsonSerializer = serializer, Entity = entity, ParentPropertyRoute = parentRoute, PropertyConverter = pc, }); } else { object oldValue = pc.GetValue(entity); var pi = pc.PropertyValidator.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType, oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) //JSON.Net already complaining return; pc.SetValue?.Invoke(entity, newValue); } } } } }
public static string GetPropertyHelp(PropertyRoute pr) { string validations = Validator.TryGetPropertyValidator(pr)?.Let(vs => vs.Validators.CommaAnd(v => v.HelpMessage)); if (validations.HasText()) validations = HelpMessage.Should.NiceToString() + validations; if (Reflector.IsIEntity(pr.Type)) { Implementations imp = Schema.Current.FindImplementations(pr); return EntityProperty(pr, pr.Type, imp.TypeLinks(pr.Type)) + validations; } else if (pr.Type.IsLite()) { Type cleanType = Lite.Extract(pr.Type); Implementations imp = Schema.Current.FindImplementations(pr); return EntityProperty(pr, cleanType, imp.TypeLinks(cleanType)) + validations; } else if (Reflector.IsEmbeddedEntity(pr.Type)) { return EntityProperty(pr, pr.Type, pr.Type.NiceName()); } else if (Reflector.IsMList(pr.Type)) { Type elemType = pr.Type.ElementType(); if (elemType.IsIEntity()) { Implementations imp = Schema.Current.FindImplementations(pr.Add("Item")); return HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo.NiceName(), imp.TypeLinks(elemType)) + validations; } else if (elemType.IsLite()) { Implementations imp = Schema.Current.FindImplementations(pr.Add("Item")); return HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo.NiceName(), imp.TypeLinks(Lite.Extract(elemType))) + validations; } else if (Reflector.IsEmbeddedEntity(elemType)) { return HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo.NiceName(), elemType.NiceName()) + validations; } else { string valueType = ValueType(pr.Add("Item")); return HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo.NiceName(), valueType) + validations; } } else if (pr.Type.UnNullify() == typeof(PrimaryKey)) { var vt = ValueType(PrimaryKey.Type(pr.RootType), null, null); return HelpMessage._0IsThePrimaryKeyOf1OfType2.NiceToString().FormatWith(pr.PropertyInfo.NiceName(), pr.RootType.NiceName(), vt) + validations; } else { string valueType = ValueType(pr); return HelpMessage._0IsA1.NiceToString().ForGenderAndNumber(NaturalLanguageTools.GetGender(valueType)).FormatWith(pr.PropertyInfo.NiceName(), valueType) + validations; } }
public static string GetPropertyHelp(PropertyRoute pr) { string?validations = Validator.TryGetPropertyValidator(pr)?.Let(vs => vs.Validators.Where(v => !(v is NotNullValidatorAttribute)).CommaAnd(v => v.HelpMessage)); if (validations.HasText()) { validations = HelpMessage.Should.NiceToString() + validations; } validations += "."; if (Reflector.IsIEntity(pr.Type)) { Implementations imp = Schema.Current.FindImplementations(pr); return(EntityProperty(pr, pr.Type, imp.TypeLinks(pr.Type)) + validations); } else if (pr.Type.IsLite()) { Type cleanType = Lite.Extract(pr.Type) !; Implementations imp = Schema.Current.FindImplementations(pr); return(EntityProperty(pr, cleanType, imp.TypeLinks(cleanType)) + validations); } else if (Reflector.IsEmbeddedEntity(pr.Type)) { return(EntityProperty(pr, pr.Type, pr.Type.NiceName())); } else if (Reflector.IsMList(pr.Type)) { Type elemType = pr.Type.ElementType() !; if (elemType.IsIEntity()) { Implementations imp = Schema.Current.FindImplementations(pr.Add("Item")); return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), imp.TypeLinks(elemType)) + validations); } else if (elemType.IsLite()) { Implementations imp = Schema.Current.FindImplementations(pr.Add("Item")); return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), imp.TypeLinks(Lite.Extract(elemType) !)) + validations); } else if (Reflector.IsEmbeddedEntity(elemType)) { return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), elemType.NiceName()) + validations); } else { string valueType = ValueType(pr.Add("Item")); return(HelpMessage._0IsACollectionOfElements1.NiceToString(pr.PropertyInfo !.NiceName(), valueType) + validations); } } else if (pr.Type.UnNullify() == typeof(PrimaryKey)) { var vt = ValueType(PrimaryKey.Type(pr.RootType), false, null, null); return(HelpMessage._0IsThePrimaryKeyOf1OfType2.NiceToString().FormatWith(pr.PropertyInfo !.NiceName(), pr.RootType.NiceName(), vt) + validations); } else { string valueType = ValueType(pr); return(HelpMessage._0IsA1.NiceToString().ForGenderAndNumber(NaturalLanguageTools.GetGender(valueType)).FormatWith(pr.PropertyInfo !.NiceName(), valueType) + validations); } }