首页
\
问答
\
如何从SQL数据库中读取数据并将其存储到XML文件中?(How to read data from SQL database and store it into an XML file?)
如何从SQL数据库中读取数据并将其存储到XML文件中?(How to read data from SQL database and store it into an XML file?)
我有一个从XML文件读取其内容的Silverlight应用程序。
用户可以输入数据并将其存储在SQL数据库中。我如何从SQL数据库中读取数据并将其存储到XML文件中?
I have a Silverlight application that reads its content from an XML file.
The user can enter data and It'll be stored in SQL database.How can I read the data from SQL database and store it into an XML file?
原文:https://stackoverflow.com/questions/2644353
更新时间:2023-07-29 22:07
最满意答案
我不认为你可以。 我检查了moq源并通过它戳穿,它看起来不像来自城堡的代理截取器实际上是创建的,直到你调用
.Object
。 看看这个痕迹:public object Object { get { return this.GetObject(); } } private object GetObject() { var value = this.OnGetObject(); this.isInitialized = true; return value; }
其次是
protected override object OnGetObject() { if (this.instance == null) { this.InitializeInstance(); } return this.instance; }
这是什么:
private void InitializeInstance() { PexProtector.Invoke(() => { this.instance = proxyFactory.CreateProxy<T>( this.Interceptor, this.ImplementedInterfaces.ToArray(), this.constructorArguments); }); }
ProxyFactory实际上创建对象并将其包装在代理中
public T CreateProxy<T>(ICallInterceptor interceptor, Type[] interfaces, object[] arguments) { var mockType = typeof(T); if (mockType.IsInterface) { return (T)generator.CreateInterfaceProxyWithoutTarget(mockType, interfaces, new Interceptor(interceptor)); } try { return (T)generator.CreateClassProxy(mockType, interfaces, new ProxyGenerationOptions(), arguments, new Interceptor(interceptor)); } catch (TypeLoadException e) { throw new ArgumentException(Resources.InvalidMockClass, e); } catch (MissingMethodException e) { throw new ArgumentException(Resources.ConstructorNotFound, e); } }
I don't think you can. I checked out the moq source and poked through it and it doesn't look like the proxy intercepter from castle is actually created until you call
.Object
. Look at this trace:public object Object { get { return this.GetObject(); } } private object GetObject() { var value = this.OnGetObject(); this.isInitialized = true; return value; }
Followed by
protected override object OnGetObject() { if (this.instance == null) { this.InitializeInstance(); } return this.instance; }
Which does this:
private void InitializeInstance() { PexProtector.Invoke(() => { this.instance = proxyFactory.CreateProxy<T>( this.Interceptor, this.ImplementedInterfaces.ToArray(), this.constructorArguments); }); }
ProxyFactory actually creates the object and wraps it in a proxy
public T CreateProxy<T>(ICallInterceptor interceptor, Type[] interfaces, object[] arguments) { var mockType = typeof(T); if (mockType.IsInterface) { return (T)generator.CreateInterfaceProxyWithoutTarget(mockType, interfaces, new Interceptor(interceptor)); } try { return (T)generator.CreateClassProxy(mockType, interfaces, new ProxyGenerationOptions(), arguments, new Interceptor(interceptor)); } catch (TypeLoadException e) { throw new ArgumentException(Resources.InvalidMockClass, e); } catch (MissingMethodException e) { throw new ArgumentException(Resources.ConstructorNotFound, e); } }
相关问答
更多-
如何防止使用Moq调用基类构造函数?(How do you prevent the base class constructor from being called with Moq?)[2022-10-15]
无法阻止调用基类构造函数。 如果可以编辑基类,则应使用抽象(例如接口,抽象类或委托)替换固定的依赖项。 如果你不能编辑基类,并且你真的需要能够用测试友好的假法替换依赖项来编写单元测试,那么你需要做更多的工作(例如将有问题的基类包装在抽象中,然后使用组合而不是继承,并依赖于新的抽象)。 There is no way to prevent the base class constructor from being invoked. If you can edit the base class, you sho ... -
最后一行是给你一个真正的实例,因为你正在使用新的关键字,而不是嘲笑CustomerSyncEngine。 你应该使用Mock.Of
() Mocking Concrete类型的唯一问题是Moq需要一个公共的默认构造函数(没有参数),或者你需要使用构造函数arg规范创建Moq。 http://www.mockobjects.com/2007/04/test-smell-mocking-concrete-classes.html 最好的做法是右键点击你的课,选择Extrac ... -
请参阅Moq快速入门的高级功能部分 。 模拟另一个项目的内部类型:将以下程序集属性(通常是AssemblyInfo.cs)添加到包含内部类型的项目中: // This assembly is the default dynamic assembly generated Castle DynamicProxy, // used by Moq. Paste in a single line. [assembly:InternalsVisibleTo("DynamicProxyGenAssembly2,Pub ...
-
没有显式构造函数的类具有无参数构造函数。 另一方面,如果你实现了一个带参数和无参数构造函数的构造函数,那么你的类将不会在没有参数的情况下被实例化。 换一种说法: public abstract class A { public A(string x) { } } public class B : A { // If you don't add ": base(x)" // your code won't compile, because A has a ...
-
我不认为你可以。 我检查了moq源并通过它戳穿,它看起来不像来自城堡的代理截取器实际上是创建的,直到你调用.Object 。 看看这个痕迹: public object Object { get { return this.GetObject(); } } private object GetObject() { var value = this.OnGetObject(); this.isInitialized = true; return value; } 其次是 p ...
-
Moq的Verify方法有很多重载,如果没有注释,F#默认将你指定的表达式解析为Func
,其中'TResult是单位,这解释了运行时的失败。 你想要做的是显式使用Verify的重载,它接受一个Action 。 一种选择是使用Moq.FSharp.Extensions项目(作为Nuget上的包提供),其中包括增加2个扩展方法VerifyFunc和VerifyAction使得更容易将F#函数解析为Moq基于C#的Action或Func参数: open NUnit.Fram ... -
你的测试类必须有一个默认的C'tor。 将您的测试类更改为: [TestFixture] public class DonorManagementTests { private Mock
_mockValidation; private DonorManagement _donorManagement; [SetUp] public TestInit() { _mockValidation = new Mock 您收到该错误是因为ChannelFactory正在尝试为与其关联的非现有端点创建实际代理。 我的建议是将ChannelFactory隐藏/隔离在您控制的接口后面的客户端,这样您就可以更好地管理所需的API。 通过这种方式,您可以替换工厂,为客户端提供创建模拟而不是真实代理的工具。 public interface IMyChannelFactory { TChannel CreateChannel(); } ...以后可以包装ChannelFac ... moq:如何在生成的代理中设置构造函数的行为?(moq: How do I setup behaviour of constructor in generated proxy?)[2021-03-31]
我要把它放到床上:我得出结论,Moq不能这样做。 最后,我只是为了测试而定义了AbstractOutputter一些简单实现。 I'm going to put this to bed: I conclude that Moq cannot do this. In the end I just defined some simple implementations of AbstractOutputter for the purpose of testing. 如何强制我的子类构造函数不调用基类构造函数?(How to force my subclass constructor not to call base class constructor?)[2021-09-29]
这就是Java的工作原理阅读本页https://docs.oracle.com/javase/tutorial/java/IandI/super.html 更具体地说,这里注意: 注意:如果构造函数未显式调用超类构造函数,则Java编译器会自动插入对超类的无参数构造函数的调用。 如果超类没有无参数构造函数,则会出现编译时错误。 对象确实有这样的构造函数,因此如果Object是唯一的超类,则没有问题。 所以你可以看到这是预期的行为。 即使你有一个超级电话,它仍然会自动插入它。 关于第二个问题,即使你在超级构造 ...相关文章
更多- Becoming a data scientist
- 《Big Data Glossary》笔记
- 《Oracle Database 11g SQL开发指南》(Oracle Database 11g SQL )扫描版[PDF]
- HTML5 Web SQL Database 数据库
- 移动MM failed to find resource file{mmiap.xml}
- The Log: What every software engineer should know about real-time data's unifying abstraction
- 【HDFS】HADOOP DISTRIBUTED FILE SYSTEM
- Solr4:配置Data Import,从数据库直接创建索引
- 无法启动Hbase hbase-default.xml file seems to be for and old version of HBase
- MyBatis XML 配置详解
最新问答
更多- python的访问器方法有哪些
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。
- 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
- 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
- NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(box-shadow behaviour on elements) - Laravel检查是否存在记录(Laravel Checking If a Record Exists)
- 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
- 想学Linux 运维 深圳有哪个培训机构好一点
- 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
- 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
- AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
- 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
- 等待EC2实例重启(Wait for an EC2 instance to reboot)
- 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
- 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
- 江民杀毒软件的KSysnon.sys模块是什么东西?
- 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
- sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
- 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
- AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
- SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
- PerSession与PerCall(PerSession vs. PerCall)
- C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
- 平衡一个精灵(Balancing a sprite)
- n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
- Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
- 湖北京山哪里有修平板计算机的