The metadata system in Intent Architect represents the models created in designers (like Domain Designer, Services Designer, etc.). Templates and decorators query this metadata to generate appropriate code.
public interface IStereotype{ string Name { get; } string GetProperty(string propertyName); T GetProperty<T>(string propertyName); bool TryGetProperty(string propertyName, out string value);}
public string GetTableName(){ if (Model.HasStereotype("Table")) { var tableStereotype = Model.GetStereotype("Table"); var tableName = tableStereotype.GetProperty<string>("Name"); if (!string.IsNullOrWhiteSpace(tableName)) { return tableName; } } // Default to class name return Model.Name;}
public class PropertyTemplate : IntentTemplateBase<PropertyModel>{ public string GetPropertyType() { // Use template's type resolution system var typeName = GetTypeName(Model.TypeReference); // Type resolution handles: // - Finding the correct template that outputs this type // - Adding it as a dependency // - Applying collection formatters (List<T>, IEnumerable<T>, etc.) // - Applying nullable formatters (T?, Nullable<T>) return typeName; }}
Templates access metadata through their Model property:
public class ServiceTemplate : IntentTemplateBase<ServiceModel>{ public string GetServiceMethods() { var methods = new StringBuilder(); foreach (var operation in Model.Operations) { var returnType = GetTypeName(operation.ReturnType); var parameters = string.Join(", ", operation.Parameters.Select(p => $"{GetTypeName(p.TypeReference)} {p.Name}")); methods.AppendLine($"{returnType} {operation.Name}({parameters});"; } return methods.ToString(); }}
Factory extensions access metadata through IApplication.MetadataManager:
protected override void OnAfterMetadataLoad(IApplication application){ // Get all domain classes var domainClasses = application.MetadataManager .Domain(application) .GetClassModels(); foreach (var domainClass in domainClasses) { ValidateDomainClass(domainClass); }}private void ValidateDomainClass(ClassModel model){ // Check for required stereotypes if (model.Attributes.Any() && !model.HasStereotype("Table")) { Logging.Log.Warning($"Class '{model.Name}' has properties but no Table stereotype"); } // Validate properties foreach (var attribute in model.Attributes) { if (attribute.TypeReference.IsCollection && attribute.Name.EndsWith("Id")) { Logging.Log.Warning($"Property '{model.Name}.{attribute.Name}' is a collection but has 'Id' suffix"); } }}
public IEnumerable<ClassModel> GetInheritanceHierarchy(){ var hierarchy = new List<ClassModel> { Model }; var current = Model.BaseType; while (current != null) { hierarchy.Add(current); current = current.BaseType; } return hierarchy;}
public IEnumerable<AttributeModel> GetAllAttributes(){ // Include attributes from base classes return GetInheritanceHierarchy() .SelectMany(c => c.Attributes) .ToList();}