BadScript 2
Loading...
Searching...
No Matches
ReadText.LocalizedDemo.LocalizableSentenceBuilder Class Reference
Inheritance diagram for ReadText.LocalizedDemo.LocalizableSentenceBuilder:
CommandLine.Text.SentenceBuilder

Properties

override Func< string > RequiredWord [get]
 
override Func< string > ErrorsHeadingText [get]
 
override Func< string > UsageHeadingText [get]
 
override Func< bool, string > HelpCommandText [get]
 
override Func< bool, string > VersionCommandText [get]
 
override Func< Error, string > FormatError [get]
 
override Func< IEnumerable< MutuallyExclusiveSetError >, string > FormatMutuallyExclusiveSetErrors [get]
 
- Properties inherited from CommandLine.Text.SentenceBuilder
static Func< SentenceBuilderFactory = () => new DefaultSentenceBuilder() [get, set]
 Factory to allow custom SentenceBuilder injection.
 
Func< string > RequiredWord [get]
 Gets a delegate that returns the word 'required'.
 
Func< string > OptionGroupWord [get]
 Gets a delegate that returns the word 'group'.
 
Func< string > ErrorsHeadingText [get]
 Gets a delegate that returns that errors block heading text.
 
Func< string > UsageHeadingText [get]
 Gets a delegate that returns usage text block heading text.
 
Func< bool, string > HelpCommandText [get]
 Get a delegate that returns the help text of help command. The delegates must accept a boolean that is equal truefor options; otherwise falsefor verbs.
 
Func< bool, string > VersionCommandText [get]
 Get a delegate that returns the help text of vesion command. The delegates must accept a boolean that is equal truefor options; otherwise falsefor verbs.
 
Func< Error, string > FormatError [get]
 Gets a delegate that handles singular error formatting. The delegates must accept an Error and returns a string.
 
Func< IEnumerable< MutuallyExclusiveSetError >, string > FormatMutuallyExclusiveSetErrors [get]
 Gets a delegate that handles mutually exclusive set errors formatting. The delegates must accept a sequence of MutuallyExclusiveSetError and returns a string.
 

Additional Inherited Members

- Static Public Member Functions inherited from CommandLine.Text.SentenceBuilder
static SentenceBuilder Create ()
 Create instance of CommandLine.Text.SentenceBuilder,.
 

Detailed Description

Definition at line 10 of file LocalizableSentenceBuilder.cs.

Property Documentation

◆ ErrorsHeadingText

override Func<string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.ErrorsHeadingText
get

Definition at line 17 of file LocalizableSentenceBuilder.cs.

18 {
19 // Cannot be pluralized
20 get { return () => Properties.Resources.SentenceErrorsHeadingText; }
21 }

◆ FormatError

override Func<Error, string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.FormatError
get

Definition at line 43 of file LocalizableSentenceBuilder.cs.

44 {
45 get
46 {
47 return error =>
48 {
49 switch (error.Tag)
50 {
51 case ErrorType.BadFormatTokenError:
52 return String.Format(Properties.Resources.SentenceBadFormatTokenError, ((BadFormatTokenError)error).Token);
53 case ErrorType.MissingValueOptionError:
54 return String.Format(Properties.Resources.SentenceMissingValueOptionError, ((MissingValueOptionError)error).NameInfo.NameText);
55 case ErrorType.UnknownOptionError:
56 return String.Format(Properties.Resources.SentenceUnknownOptionError, ((UnknownOptionError)error).Token);
57 case ErrorType.MissingRequiredOptionError:
58 var errMisssing = ((MissingRequiredOptionError)error);
59 return errMisssing.NameInfo.Equals(NameInfo.EmptyName)
60 ? Properties.Resources.SentenceMissingRequiredOptionError
61 : String.Format(Properties.Resources.SentenceMissingRequiredOptionError, errMisssing.NameInfo.NameText);
62 case ErrorType.BadFormatConversionError:
63 var badFormat = ((BadFormatConversionError)error);
64 return badFormat.NameInfo.Equals(NameInfo.EmptyName)
65 ? Properties.Resources.SentenceBadFormatConversionErrorValue
66 : String.Format(Properties.Resources.SentenceBadFormatConversionErrorOption, badFormat.NameInfo.NameText);
67 case ErrorType.SequenceOutOfRangeError:
68 var seqOutRange = ((SequenceOutOfRangeError)error);
69 return seqOutRange.NameInfo.Equals(NameInfo.EmptyName)
70 ? Properties.Resources.SentenceSequenceOutOfRangeErrorValue
71 : String.Format(Properties.Resources.SentenceSequenceOutOfRangeErrorOption,
72 seqOutRange.NameInfo.NameText);
73 case ErrorType.BadVerbSelectedError:
74 return String.Format(Properties.Resources.SentenceBadVerbSelectedError, ((BadVerbSelectedError)error).Token);
75 case ErrorType.NoVerbSelectedError:
76 return Properties.Resources.SentenceNoVerbSelectedError;
77 case ErrorType.RepeatedOptionError:
78 return String.Format(Properties.Resources.SentenceRepeatedOptionError, ((RepeatedOptionError)error).NameInfo.NameText);
79 case ErrorType.SetValueExceptionError:
80 var setValueError = (SetValueExceptionError)error;
81 return String.Format(Properties.Resources.SentenceSetValueExceptionError, setValueError.NameInfo.NameText, setValueError.Exception.Message);
82 }
83 throw new InvalidOperationException();
84 };
85 }
86 }
Models an error generated when a value conversion fails.
Definition Error.cs:418
Models an error generated when an invalid token is detected.
Definition Error.cs:286
Models an error generated when an unknown verb is detected.
Definition Error.cs:445
Models an error generated when a required option is required.
Definition Error.cs:392
Models an error generated when an option lacks its value.
Definition Error.cs:374
Models name information, used in CommandLine.Error instances.
Definition NameInfo.cs:11
string NameText
Gets a formatted text with unified name information.
Definition NameInfo.cs:47
static readonly NameInfo EmptyName
Represents an empty name information. Used when CommandLine.Error are tied to values,...
Definition NameInfo.cs:16
Models an error generated when an option is repeated two or more times.
Definition Error.cs:436
Models an error generated when a sequence value lacks elements.
Definition Error.cs:427
Models as error generated when exception is thrown at Property.SetValue.
Definition Error.cs:513
Models an error generated when an unknown option is detected.
Definition Error.cs:383
ErrorType
Discriminator enumeration of CommandLine.Error derivates.
Definition Error.cs:13

◆ FormatMutuallyExclusiveSetErrors

override Func<IEnumerable<MutuallyExclusiveSetError>, string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.FormatMutuallyExclusiveSetErrors
get

Definition at line 88 of file LocalizableSentenceBuilder.cs.

89 {
90 get
91 {
92 return errors =>
93 {
94 var bySet = from e in errors
95 group e by e.SetName into g
96 select new { SetName = g.Key, Errors = g.ToList() };
97
98 var msgs = bySet.Select(
99 set =>
100 {
101 var names = String.Join(
102 String.Empty,
103 (from e in set.Errors select String.Format("'{0}', ", e.NameInfo.NameText)).ToArray());
104 var namesCount = set.Errors.Count();
105
106 var incompat = String.Join(
107 String.Empty,
108 (from x in
109 (from s in bySet where !s.SetName.Equals(set.SetName) from e in s.Errors select e)
110 .Distinct()
111 select String.Format("'{0}', ", x.NameInfo.NameText)).ToArray());
112 //TODO: Pluralize by namesCount
113 return
114 String.Format(Properties.Resources.SentenceMutuallyExclusiveSetErrors,
115 names.Substring(0, names.Length - 2), incompat.Substring(0, incompat.Length - 2));
116 }).ToArray();
117 return string.Join(Environment.NewLine, msgs);
118 };
119 }
120 }

◆ HelpCommandText

override Func<bool, string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.HelpCommandText
get

Definition at line 28 of file LocalizableSentenceBuilder.cs.

29 {
30 get
31 {
32 return isOption => isOption
33 ? Properties.Resources.SentenceHelpCommandTextOption
34 : Properties.Resources.SentenceHelpCommandTextVerb;
35 }
36 }

◆ RequiredWord

override Func<string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.RequiredWord
get

Definition at line 12 of file LocalizableSentenceBuilder.cs.

13 {
14 get { return () => Properties.Resources.SentenceRequiredWord; }
15 }

◆ UsageHeadingText

override Func<string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.UsageHeadingText
get

Definition at line 23 of file LocalizableSentenceBuilder.cs.

24 {
25 get { return () => Properties.Resources.SentenceUsageHeadingText; }
26 }

◆ VersionCommandText

override Func<bool, string> ReadText.LocalizedDemo.LocalizableSentenceBuilder.VersionCommandText
get

Definition at line 38 of file LocalizableSentenceBuilder.cs.

39 {
40 get { return _ => Properties.Resources.SentenceVersionCommandText; }
41 }

The documentation for this class was generated from the following file: