コード例 #1
0
        public void ExecuteWinRT()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\MetroDto\bin\x86\release\MetroDto.dll"
                                                                , "-o:MySerializer.dll", "-t:MySerializer" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
        }
コード例 #2
0
ファイル: SO11895998.cs プロジェクト: cash2one/HBNews
        public void ExecutePortable()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\SO11895998_Portable\bin\release\SO11895998_Portable.dll"
                                                                , "-o:SO11895998_PortableSerializer.dll", "-t:MySerializer" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
        }
コード例 #3
0
        public void ExecuteNet45WithInternalTypes()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\Net45Dto\bin\release\Net45Dto.dll"
                                                                , @"-o:..\..\..\Net45Dto\bin\release\Net45Serializer.dll", "-t:MySerializer" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
            PEVerify.AssertValid(@"..\..\..\Net45Dto\bin\release\Net45Serializer.dll");
        }
コード例 #4
0
ファイル: SO11639029.cs プロジェクト: cash2one/HBNews
        public void TestOverallUsage()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { "a.dll", "-o:out.dll", "-t:Type" }, out ctx), "TryParse");
            Assert.AreEqual("Type", ctx.TypeName);
            Assert.AreEqual("out.dll", ctx.AssemblyName);
            Assert.AreEqual(1, ctx.Inputs.Count);
            Assert.AreEqual("a.dll", ctx.Inputs[0]);
        }
コード例 #5
0
ファイル: SO11639029.cs プロジェクト: cash2one/HBNews
        public void TestHelpUsage()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { "-?" }, out ctx), "TryParse -?");
            Assert.IsTrue(ctx.Help, "Help -?");
            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { "-h" }, out ctx), "TryParse -h");
            Assert.IsTrue(ctx.Help, "Help -h");
            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { "-help" }, out ctx), "TryParse -help");
            Assert.IsTrue(ctx.Help, "Help -help");
        }
コード例 #6
0
ファイル: SO11639029.cs プロジェクト: cash2one/HBNews
        public void TestFullPath()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"c:\a.dll", "b.dll", "-o:out.dll", "-t:Type" }, out ctx), "TryParse");
            Assert.AreEqual("Type", ctx.TypeName);
            Assert.AreEqual("out.dll", ctx.AssemblyName);
            Assert.AreEqual(2, ctx.Inputs.Count);
            Assert.AreEqual(@"c:\a.dll", ctx.Inputs[0]);
            Assert.AreEqual("b.dll", ctx.Inputs[1]);
        }
コード例 #7
0
        public void ExecuteNet11()
        {
            PreCompileContext ctx;

            //string framework = Environment.ExpandEnvironmentVariables(@"%windir%\Microsoft.NET\Framework\v1.1.4322");
            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\Net11_Poco\bin\release\Net11_Poco.dll"
                                                                //, "-f:" + framework
                                                                , "-o:Net11Serializer.dll", "-t:MySerializer" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
        }
コード例 #8
0
        public void ExecuteSigned()
        {
            PreCompileContext ctx;

            Assert.IsTrue(CommandLineAttribute.TryParse(new[] { @"..\..\..\SignedDto\bin\release\SignedDto.dll"
                                                                , @"-o:..\..\..\SignedDto\bin\release\SignedSerializer.dll",
                                                                "-t:MySignedSerializer",
                                                                @"-keyfile:..\..\..\AqlaSerializer2Key.snk" }, out ctx), "TryParse");
            Assert.IsTrue(ctx.SanityCheck(), "SanityCheck");
            Assert.IsTrue(ctx.Execute(), "Execute");
            PEVerify.AssertValid(@"..\..\..\SignedDto\bin\release\SignedSerializer.dll");
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: KazeEternal/Lottery
        public static void DisplayHelpInfo()
        {
            Type type = typeof(Program);

            PropertyInfo[] programProperties = type.GetProperties();

            System.Console.WriteLine("Help for Lottery CommandLine Tool:\n");

            foreach (PropertyInfo pInfo in programProperties)
            {
                CommandLineAttribute cla = (CommandLineAttribute)pInfo.GetCustomAttribute(typeof(CommandLineAttribute));
                if (cla != null)
                {
                    System.Console.WriteLine("-{0}\t\t{1}", cla.Flag, cla.Help);
                }
            }
        }
コード例 #10
0
        public static CommandLineAttribute CommandLineOptions(this MemberInfo memberInfo)
        {
            var found = Attribute.GetCustomAttributes(memberInfo).OfType <CommandLineAttribute>().FirstOrDefault();

            if (found == null)
            {
                found = new CommandLineAttribute();
            }
            if (string.IsNullOrWhiteSpace(found.MetaName))
            {
                found.MetaName = memberInfo.Name;
            }
            if (string.IsNullOrWhiteSpace(found.Description))
            {
                found.Description = $"Undocumented argument in {memberInfo.DeclaringType?.Name}";
            }
            return(found);
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: KazeEternal/Lottery
        private static bool CmdLineParsing(string[] args)
        {
            bool isSuccessRetVal = true;
            Type type            = typeof(Program);

            PropertyInfo[] programProperties = type.GetProperties();

            for (int i = 0; i < args.Length; ++i)
            {
                if (args[i].StartsWith("-"))
                {
                    bool isFound = false;
                    foreach (PropertyInfo pInfo in programProperties)
                    {
                        CommandLineAttribute cla = (CommandLineAttribute)pInfo.GetCustomAttribute(typeof(CommandLineAttribute));
                        if (cla != null && cla.Flag.ToLower().Equals(args[i].Substring(1)))
                        {
                            pInfo.SetValue(null, args[i + 1]);
                            i++;
                            isFound = true;
                        }
                    }

                    if (!isFound)
                    {
                        isSuccessRetVal = false;
                        System.Console.WriteLine("Arg not Found! " + args[i]);
                        break;
                    }
                }
                else if (args[i].StartsWith("-help") || args[i].StartsWith("-h") || args[i].StartsWith("-?"))
                {
                    DisplayHelp = true;
                    break;
                }
                else
                {
                    return(false);
                }
            }
            return(isSuccessRetVal);
        }
コード例 #12
0
ファイル: ConsoleService.cs プロジェクト: lovecpus/mineral
        public override void OnHelp(string[] parameters)
        {
            string message =
                Config.Instance.GetVersion()

                + "\n"
                + "\n" + "".PadLeft(0) + "COMMAND : ";

            message += ""
                       + "\n"
                       + "\n" + "".PadLeft(1) + "WALLET COMMAND :"
            ;
            foreach (FieldInfo info in typeof(RpcCommand.Wallet).GetFields())
            {
                CommandLineAttribute attr = (CommandLineAttribute)info.GetCustomAttribute(typeof(CommandLineAttribute));
                if (attr != null)
                {
                    message += "\n" + "".PadLeft(4);
                    message += string.Format("{0,-25} {1}", attr.Name, attr.Description);
                }
            }

            message += ""
                       + "\n"
                       + "\n" + "".PadLeft(1) + "BLOCK COMMAND :"
            ;
            foreach (FieldInfo info in typeof(RpcCommand.Block).GetFields())
            {
                CommandLineAttribute attr = (CommandLineAttribute)info.GetCustomAttribute(typeof(CommandLineAttribute));
                if (attr != null)
                {
                    message += "\n" + "".PadLeft(4);
                    message += string.Format("{0,-25} {1}", attr.Name, attr.Description);
                }
            }

            message += ""
                       + "\n"
                       + "\n" + "".PadLeft(1) + "TRANSACTION COMMAND :"
            ;
            foreach (FieldInfo info in typeof(RpcCommand.Transaction).GetFields())
            {
                CommandLineAttribute attr = (CommandLineAttribute)info.GetCustomAttribute(typeof(CommandLineAttribute));
                if (attr != null)
                {
                    message += "\n" + "".PadLeft(4);
                    message += string.Format("{0,-25} {1}", attr.Name, attr.Description);
                }
            }

            message += ""
                       + "\n"
                       + "\n" + "".PadLeft(1) + "ASSETISSUE COMMAND :"
            ;
            foreach (FieldInfo info in typeof(RpcCommand.AssetIssue).GetFields())
            {
                CommandLineAttribute attr = (CommandLineAttribute)info.GetCustomAttribute(typeof(CommandLineAttribute));
                if (attr != null)
                {
                    message += "\n" + "".PadLeft(4);
                    message += string.Format("{0,-25} {1}", attr.Name, attr.Description);
                }
            }

            message += ""
                       + "\n"
                       + "\n" + "".PadLeft(0) + "MISC OPTION :"
                       + "\n" + "".PadLeft(4) + BaseCommand.HelpCommandOption.Help;


            Console.WriteLine(message);
        }
コード例 #13
0
    private static void GatherMethodsFromAssembly(Assembly assembly)
    {
        Type[] assemblyTypes = assembly.GetTypes();

        for (int i = 0; i < assemblyTypes.Length; i++)
        {
            MethodInfo[] methods = assemblyTypes[i].GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            FieldInfo[]  fields  = assemblyTypes[i].GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            for (int j = 0; j < methods.Length; j++)
            {
                object[] customAttributes = methods[j].GetCustomAttributes(typeof(CommandLineAttribute), true);
                if (customAttributes.Length > 0)
                {
                    for (int attributeIndex = 0; attributeIndex < customAttributes.Length; attributeIndex++)
                    {
                        CommandLineAttribute line = (CommandLineAttribute)customAttributes[attributeIndex];
                        if (line != null)
                        {
                            ParameterInfo[] parameters = methods[j].GetParameters();
                            object[]        args       = new object[parameters.Length];
                            for (int parameterIndex = 0; parameterIndex < parameters.Length; parameterIndex++)
                            {
                                if (line.m_Arguments != null && parameterIndex < line.m_Arguments.Length)
                                {
                                    if (line.m_Arguments[parameterIndex] == null)
                                    {
                                        args[parameterIndex] = parameters[parameterIndex].DefaultValue;
                                    }
                                    else
                                    {
                                        args[parameterIndex] = line.m_Arguments[parameterIndex];
                                    }
                                }
                                else
                                {
                                    args[parameterIndex] = parameters[parameterIndex].DefaultValue;
                                }
                            }

                            CommandLineData newLine = new CommandLineData(line.CommandLine, methods[j], args, line.m_HelpText);
                            m_CommandLines.Add(line.CommandLine, newLine);
                        }
                    }
                }
            }

            for (int j = 0; j < fields.Length; j++)
            {
                object[] customAttributes = fields[j].GetCustomAttributes(typeof(CommandLineAttribute), true);
                if (customAttributes.Length > 0)
                {
                    for (int attributeIndex = 0; attributeIndex < customAttributes.Length; attributeIndex++)
                    {
                        CommandLineAttribute line = (CommandLineAttribute)customAttributes[attributeIndex];
                        if (line != null)
                        {
                            object value = null;
                            if (line.m_Arguments != null && line.m_Arguments.Length > 0 && line.m_Arguments[0].GetType().Equals(fields[j].FieldType))
                            {
                                value = line.m_Arguments[0];
                            }

                            CommandLineData newLine = new CommandLineData(line.CommandLine, fields[j], value, line.m_HelpText);
                            m_CommandLines.Add(line.CommandLine, newLine);
                        }
                    }
                }
            }
        }
    }
コード例 #14
0
 private static string GetLocalizedDescription(CommandLineAttribute attribute, LocalizableStrings resourceManager)
 => attribute.LocalizableDescription != null && !string.IsNullOrWhiteSpace(attribute.LocalizableDescription)
         ? resourceManager.GetString(attribute.LocalizableDescription, CultureInfo.CurrentUICulture) ?? ""
         : attribute.Description ?? "";