我创建了IBinarySerialize
区域以便为我的用户定义聚合创建我的 CLR。我试图在 C# 中复制我的 XIRR 函数,只是为了学习如何使用 CLR。我将写入和读取的顺序相同,但是当我尝试构建时出现错误:
严重性代码描述项目文件行抑制状态
错误 CS1503 参数 1:无法从 'System.Data.SqlTypes.SqlDateTime' 转换为 'bool' CustomAggregates D:\Transfer\CustomSqlAggregates\CustomAggregates\XIRR.cs 255 活动
错误来自写入部分。
在我在示例中看到的一些示例之后,我似乎无法找到我在这种安排中缺少的内容。这是结构的获取/设置
[Serializable]
[SqlUserDefinedAggregate(
Format.Native,
IsInvariantToDuplicates = false, // Receiving the same value again changes the result
IsInvariantToNulls = false, // Receiving a NULL value changes the result
IsInvariantToOrder = true, // The order of the values affects the result
IsNullIfEmpty = true, // If no values are given the result is null
MaxByteSize = -1, // Maximum size of the aggregate instance. -1 represents a value larger than 8000 bytes, up to 2 gigabytes
Name = "XIRR" // Name of the aggregate
)]
public struct XIRR : IBinarySerialize
{
/// <summary>
/// Used to store the product
/// </summary>
public SqlDouble Result { get; private set; }
public SqlDouble Cashflow { get; private set; }
public SqlDateTime CashflowDateTime { get; private set; }
public bool HasValue { get; private set; }
public List<CashItem> CashFlows { get; private set;}
...
#region IBinarySerialize
/// <summary>
/// Writes the values to the stream in order to be stored
/// </summary>
/// <param name="write">The BinaryWriter stream</param>
public void Write(System.IO.BinaryWriter write)
{
write.Write(Result);
write.Write(Cashflow); //Line - 255
write.Write(CashflowDateTime);
write.Write(HasValue);
}
/// <summary>
/// Reads the values from the stream
/// </summary>
/// <param name="read">The BinaryReader stream</param>
public void Read(System.IO.BinaryReader read)
{
Result = new SqlDouble(read.ReadDouble());
Cashflow = new SqlDouble(read.ReadDouble());
CashflowDateTime = new SqlDateTime(Convert.ToDateTime(read.ReadString()));
HasValue = read.ReadBoolean();
}
#endregion IBinarySerialize
}
提前致谢。
如果您希望我提供更多信息,请告诉我。