public static string Create(Type type, ScriptUnitAttribute attr) { var sb = new StringBuilder(); var methods = type.GetMethods(); foreach (var method in methods) { var attributes = method.GetCustomAttributes <ControllerMethodAttribute>(); if (attributes.Any()) { foreach (var attribute in attributes) { var parameters = method.GetParameters(); sb.Append(string.Format(method.ReturnType == typeof(void) ? VoidControllerMethod : ControllerMethod, HttpMethodToAttribute(attribute), method.ReturnType, method.Name, parameters.Any() ? ParametersToParameters(parameters) : string.Empty, parameters.Any() ? ParametersToCallParams(parameters) : string.Empty, string.IsNullOrWhiteSpace(attribute.Policy) ? "[AllowAnonymous]" : $"[Authorize(Policy = \"{attribute.Policy}\")]")); sb.AppendLine(); } } } return(string.Format(ControllerTemplate, attr.Name, sb.ToString(), type)); }
public static Tuple <string, string> Create(Type type, ScriptUnitAttribute attr) { var sb = new StringBuilder(); var methods = type.GetMethods(); foreach (var method in methods) { var attributes = method.GetCustomAttributes <HubMethodAttribute>(); if (attributes.Any()) { foreach (var attribute in attributes) { var parameters = method.GetParameters(); sb.Append(string.Format(method.ReturnType == typeof(void) ? VoidHubMethod : HubMethod, method.ReturnType, method.Name, parameters.Any() ? ParametersToParameters(parameters) : string.Empty, parameters.Any() ? ParametersToCallParams(parameters) : string.Empty)); sb.AppendLine(); } } } return(new Tuple <string, string>(attr.Name + "Hub", string.Format(HubTemplate, attr.Name, sb.ToString(), type, attr.ClientInterface != null ? $"<{attr.ClientInterface}>" : ""))); }