我是否可以序列化可序列化对象的通用列表,而无需指定其类型.
像下面破坏的代码背后的意图:
List<ISerializable> serializableList = new List<ISerializable>();
XmlSerializer xmlSerializer = new XmlSerializer(serializableList.GetType());
serializableList.Add((ISerializable)PersonList);
using (StreamWriter streamWriter = System.IO.File.CreateText(fileName))
{
xmlSerializer.Serialize(streamWriter, serializableList);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
对于那些想要了解详细信息的人:当我尝试运行此代码时,它在XMLSerializer [...]行上出错:
无法序列化System.Runtime.Serialization.ISerializable接口.
如果我改变List<object>
我得到"There was an error generating the XML document."
.InnerException的细节是"{"The type System.Collections.Generic.List1[[Project1.Person, ConsoleFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] may not be used in this context."}"
person对象定义如下:
[XmlRoot("Person")]
public class Person
{
string _firstName = String.Empty;
string _lastName = String.Empty;
private Person()
{
}
public Person(string lastName, string firstName)
{
_lastName = lastName;
_firstName …
Run Code Online (Sandbox Code Playgroud) 我想要一个查询,它按名称返回数据库中所有(用户)存储过程的列表,每个存储过程的代码行数.
即
sp_name lines_of_code
-------- -------------
DoStuff1 120
DoStuff2 50
DoStuff3 30
Run Code Online (Sandbox Code Playgroud)
任何想法如何做到这一点?
有没有办法计算Regex.Replace调用的替换次数?
例如,Regex.Replace("aaa", "a", "b");
我想得到数字3(结果是"bbb"
); 因为Regex.Replace("aaa", "(?<test>aa?)", "${test}b");
我想得到数字2(结果是"aabab"
).
我能想到这样做的方式:
方法1和方法2需要手动解析$替换,方法3需要正则表达式匹配字符串两次.有没有更好的办法.
在Python中,我有一个字符串列表,其中一些可能是空字符串.获得第一个非空字符串的最佳方法是什么?
我正在使用SQL Server 2005.使用下面的查询(从我的真实查询简化):
select a,count(distinct b),sum(a) from
(select 1 a,1 b union all
select 2,2 union all
select 2,null union all
select 3,3 union all
select 3,null union all
select 3,null) a
group by a
Run Code Online (Sandbox Code Playgroud)
有什么方法可以在没有得到的情况下进行计数
"警告:聚合或其他SET操作消除了空值."
以下是我能想到的替代方案:
分成两个查询,一个是count distinct,一个是where子句来消除空值,一个是sum:
select t1.a, t1.countdistinctb, t2.suma from
(
select a,count(distinct b) countdistinctb from
(
select 1 a,1 b union all
select 2,2 union all
select 2,null union all
select 3,3 union all
select 3,null union all
select 3,null
) a
where …
Run Code Online (Sandbox Code Playgroud)一旦我在C#(VS2008)的即时窗口中创建了一个变量,有没有办法删除它,所以我可以创建一个具有相同名称但不同类型的新变量?除了重启程序之外.
原因是保持立即窗口的命名空间清洁,因为一旦它们滚动窗口的可见部分就很难跟踪变量声明.
如果文件系统任务(例如重命名)失败,例如文件不存在,则SSIS将其视为错误.这意味着整个包失败了.我可以通过使用脚本任务或将包的最大错误设置为多个来解决问题.将程序包的最大错误设置为多个错误的问题是,如果程序包中的其他位置发生错误,程序包将不会失败.
那么有没有办法以某种方式吞下错误,仍然能够根据文件系统任务的成功或失败进行分支?我尝试将文件任务粘贴到ForceExecutionResult设置为Success的序列容器中,但是程序包仍然无法说达到最大错误计数.