Ejemplo n.º 1
0
        /// <inheritdoc />
        public virtual MorestachioFormatterModel Add(MethodInfo method,
                                                     MorestachioFormatterAttribute morestachioFormatterAttribute)
        {
            morestachioFormatterAttribute.ValidateFormatter(method);
            var arguments = morestachioFormatterAttribute.GetParameters(method);

            var name = morestachioFormatterAttribute.GetFormatterName(method);;
            var morestachioFormatterModel = new MorestachioFormatterModel(name,
                                                                          morestachioFormatterAttribute.Description,
                                                                          arguments.FirstOrDefault(e => e.IsSourceObject)?.ParameterType ?? typeof(object),
                                                                          morestachioFormatterAttribute.OutputType ?? method.ReturnType,
                                                                          method.GetCustomAttributes <MorestachioFormatterInputAttribute>()
                                                                          .Select(e => new InputDescription(e.Description, e.OutputType, e.Example)).ToArray(),
                                                                          morestachioFormatterAttribute.ReturnHint,
                                                                          method,
                                                                          new MultiFormatterInfoCollection(arguments),
                                                                          !morestachioFormatterAttribute.IsSourceObjectAware,
                                                                          morestachioFormatterAttribute.LinkFunctionTarget);

            name = name ?? "{NULL}";

            if (!Formatters.TryGetValue(name, out var formatters))
            {
                formatters       = new List <MorestachioFormatterModel>();
                Formatters[name] = formatters;
            }

            formatters.Add(morestachioFormatterModel);
            return(morestachioFormatterModel);
        }
        /// <summary>
        ///		Adds a new Function to the list of formatters
        /// </summary>
        public static MultiFormatterInfoCollection AddSingle(this IMorestachioFormatterService service, Delegate function, [NotNull] MorestachioFormatterAttribute attribute)
        {
            attribute.OutputType = function.Method.ReturnType;
            attribute.ReturnHint = "None";

            var morestachioFormatterModel = service.Add(function.Method, attribute);

            morestachioFormatterModel.FunctionTarget = function.Target;
            return(morestachioFormatterModel.MetaData);
        }