什么时候评估内插字符串?

When are interpolated string evaluated?

我有以下代码:

    internal class Constants
    {
        internal static string Source { get; set; }

        #region EvaluationRepository
        internal static string QUERY_001 = $@"
select
  e.*
from {Source} e
where
  e.id = @Id
";

        internal static string QUERY_002 = $@"
select
  e.*
from {Source} e
where
  e.statusid=@StatusId
  and e.begindate >= @FromDate
  and e.enddate <= @ToDate
";

        internal static string QUERY_003
        {
            get
            {
                return $@"
select
  d.statusid [StatusId],
  count(1) [Count]
from
  (select e.statusid
  from {Source} e
  where e.begindate >= @FromDate and e.enddate <= @ToDate) d
group by d.statusid
";
            }
        }
        #endregion
    }

唯一一次填充 {Source} 是在我将查询公开为 属性 时。 (QUERY_003)
当作为 字段 公开时,它不起作用。 (QUERY_001, QUERY_002)

谁能解释一下为什么?因为静态(不确定这是不是一个词)?

对于 SQL 的逐字插值噪音,我们深表歉意:)

它是在运行时完成的。它等效于(直到生成的 IL)使用 string.Format.

字段 未正确填充的原因是 Source 在最初执行时为空(当初始化静态 class 时)。