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"); }
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"); }
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"); }
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]); }
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"); }
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]); }
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"); }
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"); }
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); } } }
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); }
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); }
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); }
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); } } } } } }
private static string GetLocalizedDescription(CommandLineAttribute attribute, LocalizableStrings resourceManager) => attribute.LocalizableDescription != null && !string.IsNullOrWhiteSpace(attribute.LocalizableDescription) ? resourceManager.GetString(attribute.LocalizableDescription, CultureInfo.CurrentUICulture) ?? "" : attribute.Description ?? "";