Exemplo n.º 1
0
        /// <summary>
        ///     Adds all formatter that are decorated with the <see cref="MorestachioFormatterAttribute" />
        /// </summary>
        public static void AddFromType(this IMorestachioFormatterService service, Type type)
        {
            foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Public))
            {
                var hasFormatterAttr = method.GetCustomAttributes <MorestachioFormatterAttribute>();
                foreach (var morestachioFormatterAttribute in hasFormatterAttr)
                {
                    if (morestachioFormatterAttribute == null)
                    {
                        continue;
                    }

                    service.Add(method, morestachioFormatterAttribute);
                }
            }
            foreach (var method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public))
            {
                var hasFormatterAttr = method.GetCustomAttributes <MorestachioFormatterAttribute>();
                foreach (var morestachioFormatterAttribute in hasFormatterAttr)
                {
                    if (morestachioFormatterAttribute == null)
                    {
                        continue;
                    }

                    morestachioFormatterAttribute.LinkFunctionTarget  = true;
                    morestachioFormatterAttribute.IsSourceObjectAware = false;
                    service.Add(method, morestachioFormatterAttribute);
                }
            }
        }
        /// <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);
        }
        public static MultiFormatterInfoCollection AddSingle(this IMorestachioFormatterService service, Delegate function, [CanBeNull] string name = null)
        {
            var morestachioFormatterModel = service.Add(function.Method, new MorestachioFormatterAttribute(name, "Autogenerated description")
            {
                OutputType = function.Method.ReturnType,
                ReturnHint = "None",
            });

            morestachioFormatterModel.FunctionTarget = function.Target;
            return(morestachioFormatterModel.MetaData);
        }
        /// <summary>
        ///     Adds all formatter that are decorated with the <see cref="MorestachioFormatterAttribute" />
        /// </summary>
        /// <param name="type">The type.</param>
        public static void AddFromType(this IMorestachioFormatterService service, Type type)
        {
            foreach (var method in type.GetMethods(BindingFlags.Static | BindingFlags.Public))
            {
                var hasFormatterAttr = method.GetCustomAttributes <MorestachioFormatterAttribute>();
                foreach (var morestachioFormatterAttribute in hasFormatterAttr)
                {
                    if (morestachioFormatterAttribute == null)
                    {
                        continue;
                    }

                    service.Add(method, morestachioFormatterAttribute);
                }
            }
        }