Пример #1
0
        //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);
        }