public override void ExecuteConstraint(IModelElement mel, ConstraintContext ctx) { var pv = mel.GetPropertyValue(_property); if (pv == null) { return; } ctx.PropertyName = _property.Name; CheckHandler(pv.Value, pv.OldValue, ctx, Constraint); }
private void SerializeProperties(IModelElement element) { var schemaInfo = GetSchemaInfo(element); foreach (var prop in schemaInfo.GetProperties(true)) { var value = element.GetPropertyValue(prop); if (value.HasValue) { _writer.PushProperty("property", prop.Name, Platform.PlatformServices.Current.ObjectSerializer.Serialize(prop.Serialize(value.Value))); } } }
private void SerializeElement(IModelElement element, bool insertComma) { if (element == null || !_serialized.Add(element.Id)) { return; } if (element is IModelRelationship && !HasOption(JSonSerializationOption.SerializeRelationship)) { return; } insertComma = WriteStartElement(element, insertComma); var schemaInfo = GetSchemaInfo(element); var schema = schemaInfo.Schema; foreach (var relationship in schema.GetRelationships(start: schemaInfo)) { var relationshipSchema = relationship as ISchemaRelationship; if (relationshipSchema != null && relationshipSchema.StartPropertyName != null) { insertComma = SerializeReference(element, relationshipSchema, true, insertComma); } } // Opposites foreach (var relationship in schema.GetRelationships(end: schemaInfo)) { var relationshipSchema = relationship as ISchemaRelationship; if (relationshipSchema != null && relationshipSchema.EndPropertyName != null)//&& relationshipSchema.StartPropertyName == null) // Only if the relationship has not been serialized previously (StartPropertyName != null) { insertComma = SerializeReference(element, relationshipSchema, false, insertComma); } } foreach (var prop in schemaInfo.GetProperties(true)) { var value = element.GetPropertyValue(prop); if (value.HasValue) { WriteKeyValue(prop.Name, Platform.PlatformServices.Current.ObjectSerializer.Serialize(prop.Serialize(value.Value)), insertComma); insertComma = true; } } _depth--; WriteEndElement(); }
///------------------------------------------------------------------------------------------------- /// <summary> /// Helper to format a message with named item corresponding to a property element. Each item /// must be declared with a property name. The format to use is {propertyName[,length][:formatstring]} /// </summary> /// <param name="message"> /// Message to format. /// </param> /// <param name="elem"> /// Element to use. /// </param> /// <returns> /// a formatted string. /// </returns> ///------------------------------------------------------------------------------------------------- public static string CreateMessage(string message, IModelElement elem) { if (elem == null) { return(message); } var result = ReplacePropertyNameWhithIndexValues(message); List <object> values = new List <object>(); foreach (var property in result.Item2) { switch (property) { case "Id": values.Add(elem.Id); break; case "DomainModel": values.Add(elem.DomainModel.Name); break; case "SchemaInfo": values.Add(elem.SchemaInfo.Id); break; default: var schemaProperty = elem.SchemaInfo.GetProperties(true).FirstOrDefault(p => String.Compare(p.Name, property, StringComparison.Ordinal) == 0); PropertyValue pv = null; if (schemaProperty != null && (pv = elem.GetPropertyValue(schemaProperty)) != null) { values.Add(pv.Value); } else { values.Add(null); } break; } } return(string.Format(result.Item1, values.ToArray())); }