コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: HubCreator.cs プロジェクト: alexsandrocruz/scribi
        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}>" : "")));
        }