C#预处理器可以查看常量字符串值吗
本文关键字:常量 字符串 预处理 处理器 | 更新日期: 2023-09-27 18:26:21
我正在为一个正在辅导的孩子编写一个MadLib库。MadLib类具有以下内容:
// Finds fields
private static readonly Regex PromptValueRegex = new Regex("<([^>]+)>", RegexOptions.IgnoreCase);
// text of our story
private readonly string Story;
...
/// <summary>
/// Creates a new MadLib object with the given story text.
/// </summary>
/// <param name="story">The text of the story with blank field names denoted by <blank name>.</param>
public MadLib(string story)
{
if (story == null)
{
throw new ArgumentNullException("Story cannot be null.");
}
if (story.Trim() == string.Empty)
{
throw new EmptyStoryException();
}
Story = story;
SetupPromptDictionary();
}
这个故事通过正则表达式<([^>]+)>
找到"<blank name>"
来检测在过去MadLibs是空白的。
如果传递给构造函数的故事可以被确定为没有<
或>
字符,我想在编译时发出警告。这可能吗?
通过注释,这是不可能的。如果有可能,请告诉我!