- acf-52406.zip
- acfeditor
- AcfEditor.Domain
- acfeditor.sln
- acfeditor
- icons
- acf_project.ico
- images
- ApplicationProvider.bmp
- Control_TreeView.bmp
- Delete.bmp
- EditCode.bmp
- ErrorList.bmp
- NewDocument.bmp
- OpenFolder.bmp
- Option.bmp
- OptionContract.bmp
- OptionContracts.bmp
- Output.bmp
- Project.bmp
- Properties.bmp
- ReferencedAssemblies.bmp
- ReferencedAssembly.bmp
- Save.bmp
- SaveAll.bmp
- Status.bmp
- Referenced Assemblies
- CSParser.dll
- ICSharpCode.SharpZipLib.dll
- SunnyChen.Common.dll
- test
- AdaptiveConsole.sln
- AdaptiveConsole
- BuildProcessTemplates
- catool
- Catool.Contracts
- Catool.Provider
- catool.sln
- catool
- docs
- devman_enUS
- usrgde.doc
- usrgde.mht
- usrgde.pdf
- images
- acf.gif
- acf.psd
- banner.bmp
- banner.psd
- setup
- acfsetup.ism
- acfsetup
- Script Files
- Setup.dbg
- Setup.inx
- setup.isr
- Setup.map
- setup.obs
- Setup.rul
- String1033.txt
- support
- banner.bmp
- externior.bmp
- externior.jpg
- externior.psd
- license.rtf
- AdaptiveConsoleSetup.zip
- AdaptiveConsoleSetup.msi
- setup.exe
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AdaptiveConsole;
namespace Catool.Contracts
{
[
OptionContract(
Type=ContractType.Patternized,
Description="Performs arithmetic calculation",
Parameters=2)
]
public class CalculationContract : OptionContractBase
{
[
Option(
Name="/method;/m",
Type=OptionType.SingleValue,
Description="Specifies the calculation method\n"+
"\t\tadd: Performs an addition calculation\n"+
"\t\tsub: Performs a subtraction calculation\n"+
"\t\tmul: Performs a multiplication calculation\n"+
"\t\tdiv: Performs a division calculation",
Required=true)
]
public string Method { get; set; }
[
Option(
Name="/nologo",
Type=OptionType.Switch,
Description="Suppress the display of banner information")
]
public bool NoLogo { get; set; }
public override void Execute(
ConsoleApplicationBase consoleApplication,
IList<ArgumentInfo> args)
{
var integers = from arg in args
where arg.Category == ArgumentCategory.Parameter
select arg.Argument;
int num1, num2, result;
try
{
num1 = int.Parse(integers.ElementAt(0));
num2 = int.Parse(integers.ElementAt(1));
}
catch
{
consoleApplication.PrintHelpMessage();
return;
}
if (!this.NoLogo)
consoleApplication.PrintBanner();
try
{
switch (this.Method.ToUpper())
{
case "ADD":
result = num1 + num2;
break;
case "SUB":
result = num1 - num2;
break;
case "MUL":
result = num1 * num2;
break;
case "DIV":
result = num1 / num2;
break;
default:
consoleApplication.PrintHelpMessage();
return;
}
Console.WriteLine(result);
}
catch (DivideByZeroException)
{
Console.WriteLine("Divided by zero error caught.");
return;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have more than 13 years' experience in software development and more than 5 years' working experience in software industry. I'm the National Certified System Analyst and now I'm the consultant of China System Analyst Institution. I also got the MCP/MCAD certificate on .NET technology in the year 2004.
I'm very interested in system architect and analysis, and also interested in .NET technologies. For my blog please refer to
http://www.sunnychen.org.