コード例 #1
0
        internal CommandOption Configure(CommandLineApplication app)
        {
            var opt = app.VersionOption(Template, Version);

            Configure(opt);
            return(opt);
        }
コード例 #2
0
        internal CommandOption Configure(CommandLineApplication app, Type type, Func <object> targetInstanceFactory)
        {
            Func <string>?shortFormGetter = null;
            Func <string>?longFormGetter  = null;

            if (MemberName != null)
            {
                var methods = ReflectionHelper.GetPropertyOrMethod(type, MemberName);

                if (methods.Length == 0)
                {
                    throw new InvalidOperationException(Strings.NoPropertyOrMethodFound(MemberName, type));
                }

                if (methods.Length > 1)
                {
                    throw new AmbiguousMatchException("Multiple properties or methods match the name " + MemberName);
                }

                shortFormGetter = () =>
                {
                    return((string)methods[0].Invoke(targetInstanceFactory.Invoke(), Util.EmptyArray <object>()));
                };
            }

            return(app.VersionOption(Template, shortFormGetter, longFormGetter));
        }
コード例 #3
0
        internal CommandOption Configure(CommandLineApplication app, Type type, object targetInstance)
        {
            Func<string> shortFormGetter = null;
            Func<string> longFormGetter = null;

            if (MemberName != null)
            {
                var methods = GetPropertyOrMethod(type, MemberName);

                if (methods.Length == 0)
                {
                    throw new InvalidOperationException($"Could not find a property or method named {MemberName} on type {type.FullName}");
                }

                if (methods.Length > 1)
                {
                    throw new AmbiguousMatchException("Multiple properties or methods match the name " + MemberName);
                }

                shortFormGetter = () =>
                {
                    return methods[0].Invoke(targetInstance, Constants.EmptyArray) as string;
                };
            }

            return app.VersionOption(Template, shortFormGetter, longFormGetter);
        }
コード例 #4
0
 /// <summary>
 /// Finds <see cref="AssemblyInformationalVersionAttribute"/> on <paramref name="assembly"/> and uses that
 /// to set <see cref="CommandLineApplication.OptionVersion"/>.
 /// <para>
 /// Uses the Version that is part of the <see cref="AssemblyName"/> of the specified assembly
 /// if no <see cref="AssemblyInformationalVersionAttribute"/> is applied.
 /// </para>
 /// </summary>
 /// <param name="app"></param>
 /// <param name="template"></param>
 /// <param name="assembly"></param>
 /// <exception cref="ArgumentNullException">Either <paramref name="app"/> or <paramref name="assembly"/> is <c>null</c>.</exception>
 public static CommandOption VersionOptionFromAssemblyAttributes(CommandLineApplication app, string template, Assembly assembly)
 => app.VersionOption(template, GetInformationalVersion(assembly));