我正在尝试编写一个Linq(针对对象)查询,将结果转换为接口,如下所示:
var data = (from row in CicApplication.Vaporizer473Cache
where row.Coater == coater
select row).Cast<IVaporizerData>();
这似乎是唯一的方法,因为我无法在select中创建接口实例。 我有两个问题:
强制转换实际上是如何完成的? 它会在源中找到每个属性,并将其值复制到具有相同名称的接口属性中吗?
我在我的接口中有一个属性未包含在源中,但我想在此操作期间以某种方式设置其值。 这可能吗? 还是我需要在查询之后,在for each语句中执行它?
如果有帮助的话,数据源(Vaporizer473Cache)的类定义如下。 接口非常相似。
internal class Vaporizer473
{
/// <summary>
/// Gets or sets the Coater property
/// </summary>
public string Coater { get; set; }
/// <summary>
/// Gets or sets the CoaterTime property
/// </summary>
public DateTime? CoaterTime { get; set; }
/// <summary>
/// Gets or sets the TemperatureLeftTubeA property
/// </summary>
public double? TemperatureLeftTubeA { get; set; }
/// <summary>
/// Gets or sets the TemperatureLeftTubeB property
/// </summary>
public double? TemperatureLeftTubeB { get; set; }
/// <summary>
/// Gets or sets the TemperatureRightTubeA property
/// </summary>
public double? TemperatureRightTubeA { get; set; }
/// <summary>
/// Gets or sets the TemperatureRightTubeB property
/// </summary>
public double? TemperatureRightTubeB { get; set; }
}