コード例 #1
0
        private ControllerMethod BuildControllerMethod(string url, Method method, Resource resource, ControllerObject parent, IDictionary <string, Parameter> parentUriParameters)
        {
            var relativeUri = UrlGeneratorHelper.GetRelativeUri(url, parent.PrefixUri);

            var parentUrl = UrlGeneratorHelper.GetParentUri(url, resource.RelativeUri);

            string b = resource.Methods.FirstOrDefault(m => m.Verb == method.Verb && m.SecuredBy != null && m.SecuredBy.Any()).SecuredBy.FirstOrDefault();

            return(new ControllerMethod
            {
                Name = NetNamingMapper.GetMethodName(method.Verb ?? "Get" + resource.RelativeUri),
                Parameter = GetParameter(GeneratorServiceHelper.GetKeyForResource(method, resource, parentUrl), method, resource, url),
                UriParameters = uriParametersGenerator.GetUriParameters(resource, url, parentUriParameters),
                ReturnType = GetReturnType(GeneratorServiceHelper.GetKeyForResource(method, resource, parentUrl), method, resource, url),
                Comment = GetComment(resource, method, url),
                Url = relativeUri,
                Verb = NetNamingMapper.Capitalize(method.Verb),
                Parent = null,
                UseSecurity =
                    raml.SecuredBy != null && raml.SecuredBy.Any() ||
                    resource.Methods.Any(m => m.Verb == method.Verb && m.SecuredBy != null && m.SecuredBy.Any()),
                SecuredBy =
                    raml.SecuredBy ??
                    resource.Methods.FirstOrDefault(m => m.Verb == method.Verb && m.SecuredBy != null && m.SecuredBy.Any()).SecuredBy,
                SecurityParameters = GetSecurityParameters(raml, method)
            });
        }
コード例 #2
0
        protected string GetUniqueObjectName(Resource resource, Resource parent)
        {
            string objectName;

            if (resource.RelativeUri.StartsWith("/{") && resource.RelativeUri.EndsWith("}"))
            {
                objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(resource));
            }
            else
            {
                objectName = NetNamingMapper.GetObjectName(resource.RelativeUri);
                if (classesNames.Contains(objectName))
                {
                    objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(resource));
                }
            }

            if (string.IsNullOrWhiteSpace(objectName))
            {
                throw new InvalidOperationException("object name is null for " + resource.RelativeUri);
            }

            if (!classesNames.Contains(objectName))
            {
                return(objectName);
            }

            if (parent == null || string.IsNullOrWhiteSpace(parent.RelativeUri))
            {
                return(GetUniqueObjectName(objectName));
            }

            if (resource.RelativeUri.StartsWith("/{") && parent.RelativeUri.EndsWith("}"))
            {
                objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(parent)) + objectName;
            }
            else
            {
                objectName = NetNamingMapper.GetObjectName(parent.RelativeUri) + objectName;
                if (classesNames.Contains(objectName))
                {
                    objectName = NetNamingMapper.Capitalize(GetObjectNameForParameter(parent));
                }
            }

            if (string.IsNullOrWhiteSpace(objectName))
            {
                throw new InvalidOperationException("object name is null for " + resource.RelativeUri);
            }

            if (!classesNames.Contains(objectName))
            {
                return(objectName);
            }

            return(GetUniqueObjectName(objectName));
        }
コード例 #3
0
 private static Property ConvertGeneratorParamToProperty(GeneratorParameter p)
 {
     return(new Property
     {
         Name = NetNamingMapper.Capitalize(p.Name),
         Description = p.Description,
         Type = p.Type,
         Required = true
     });
 }
コード例 #4
0
        public static string GetPropertyName(string name)
        {
            var propName = name.Replace(":", string.Empty);

            propName = propName.Replace("/", string.Empty);
            propName = propName.Replace("-", string.Empty);
            propName = NetNamingMapper.Capitalize(propName);

            if (StartsWithNumber(propName))
            {
                propName = "P" + propName;
            }

            return(propName);
        }
コード例 #5
0
 public static string GetNamespace(string title)
 {
     return(NetNamingMapper.Capitalize(NetNamingMapper.RemoveIndalidChars(title)));
 }