//public static string MakeUrlEncodeable(this IOperationParameterModel parameter) //{ // if (!UrlEncodablePrimitives.Contains(parameter.TypeReference.Name)) // { // return parameter.Name; // } // return string.Format(UrlEncodablePrimitives[parameter.TypeReference.Name], parameter.Name); //} private static string GetParameterBindingAttribute(this IOperationParameterModel operationParameterModel) { const string parameterBinding = "Parameter Binding"; const string propertyType = "Type"; const string propertyCustomType = "Custom Type"; const string customValue = "Custom"; if (!operationParameterModel.HasStereotype(parameterBinding)) { return(string.Empty); } var attributeName = operationParameterModel.GetStereotypeProperty <string>(parameterBinding, propertyType); if (!string.Equals(attributeName, customValue, StringComparison.OrdinalIgnoreCase)) { return($"[{attributeName}]"); } var customAttributeValue = operationParameterModel.GetStereotypeProperty <string>(parameterBinding, propertyCustomType); if (string.IsNullOrWhiteSpace(customAttributeValue)) { throw new System.Exception("Parameter Binding was set to custom but no Custom attribute type was specified"); } return($"[{customAttributeValue}]"); }
private string GetParameterBindingAttribute(IOperationModel operation, IOperationParameterModel parameter) { const string ParameterBinding = "Parameter Binding"; const string PropertyType = "Type"; const string PropertyCustomType = "Custom Type"; const string CustomValue = "Custom"; if (parameter.HasStereotype(ParameterBinding)) { var attributeName = parameter.GetStereotypeProperty <string>(ParameterBinding, PropertyType); if (string.Equals(attributeName, CustomValue, StringComparison.OrdinalIgnoreCase)) { var customAttributeValue = parameter.GetStereotypeProperty <string>(ParameterBinding, PropertyCustomType); if (string.IsNullOrWhiteSpace(customAttributeValue)) { throw new Exception("Parameter Binding was set to custom but no Custom attribute type was specified"); } return($"[{customAttributeValue}]"); } return($"[{attributeName}]"); } if (operation.Parameters.Count(p => p.TypeReference.Type == ReferenceType.ClassType) == 1 && parameter.TypeReference.Type == ReferenceType.ClassType) { return("[FromBody]"); } return(string.Empty); }
private static bool IsFromBody(IOperationParameterModel parameter) { var csharpPrimitives = new[] { "guid", "System.Guid", "bool", "Boolean", "System.Boolean", "byte", "Byte", "System.Byte", "sbyte", "SByte", "System.SByte", "char", "Char", "System.Char", "decimal", "Decimal", "System.Decimal", "double", "Double", "System.Double", "float", "Single", "System.Single", "int", "Int32", "System.Int32", "uint", "UInt32", "System.UInt32", "long", "Int64", "System.Int64", "ulong", "UInt64", "System.UInt64", "short", "Int16", "System.Int16", "ushort", "UInt16", "System.UInt16", "string", "String", "System.String" }; // NB: Order of conditional checks is important here return(GetParameterBindingAttribute(parameter) == "[FromBody]" || !csharpPrimitives.Contains(parameter.TypeReference.Name)); }
private string EmitPropertyAssignments(IMetaDataManager metaDataManager, SoftwareFactory.Engine.IApplication application, IClass domainModel, string domainVarName, IOperationParameterModel operationParameterModel) { var sb = new StringBuilder(); var dto = metaDataManager.GetDTOModels(application).First(p => p.Id == operationParameterModel.TypeReference.Id); foreach (var domainAttribute in domainModel.Attributes) { var dtoField = dto.Fields.FirstOrDefault(p => p.Name.Equals(domainAttribute.Name, StringComparison.OrdinalIgnoreCase)); if (dtoField == null) { sb.AppendLine($" #warning No matching field found for {domainAttribute.Name}"); continue; } if (domainAttribute.Type.Id != dtoField.TypeReference.Id) { sb.AppendLine($" #warning No matching type for Domain: {domainAttribute.Name} and DTO: {dtoField.Name}"); continue; } sb.AppendLine($" {domainVarName}.{domainAttribute.Name.ToPascalCase()} = {operationParameterModel.Name}.{dtoField.Name.ToPascalCase()};"); } return(sb.ToString().Trim()); }
public override IEnumerable <string> PayloadPropertyDecorators(IOperationParameterModel parameter) => new string[] { };
public IEnumerable <string> PayloadPropertyDecorators(IOperationParameterModel parameter) { return(GetDecorators().SelectMany(x => x.PayloadPropertyDecorators(parameter))); }
public static bool IsFromBody(this IOperationParameterModel parameter) { // NB: Order of conditional checks is important here return(GetParameterBindingAttribute(parameter) == "[FromBody]" || !UrlEncodablePrimitives.Contains(parameter.TypeReference.Name)); }