我的意思是,我想转换这个:
string a = "40.00";
Convert.ChangeType(a, typeof(decimal))
Run Code Online (Sandbox Code Playgroud)
结果是十进制值"4000"
问题是转换调用是在xmlToObject转换器中的一个非常抽象的泛型方法.我不想以编程方式添加许多不同的异常来正确转换.
对克里斯说
如何通过在C#中反映COM对象来读出所有属性名称?如果我知道名字,我知道如何获得财产.
comObject.GetType().InvokeMember("PropertyName", System.Reflection.BindingFlags.GetProperty, null, comObject, null);
Run Code Online (Sandbox Code Playgroud)
但什么时候我想转储所有属性?
PropertyInfo[] properties = t.GetProperties();
Run Code Online (Sandbox Code Playgroud)
这种方式不适用于Com-Objects.如果我做一个GetMembers()我得到这些成员:
Name: GetLifetimeService
Name: InitializeLifetimeService
Name: CreateObjRef
Name: ToString
Name: Equals
Name: GetHashCode
Name: GetType
Run Code Online (Sandbox Code Playgroud)
对克里斯说
我知道有很多这样的问题.
但我不想使用Windows媒体编码器9,因为获取一个是一个问题,然后它不再受支持.
我知道,一种可能性是捕获大量屏幕截图并创建视频,ffmpeg但我不想使用第三方可执行文件.
有.net唯一的解决方案吗?
我试图读出一个示例Northwind sqlite数据库,但在一些具有日期时间的表上得到错误.这是数据库还是System.Data.SQLite的问题?Exception有点像:"字符串不是有效的DateTime"
http://system.data.sqlite.org/
对于cource,我可以通过正确转换datetime来自己读出数据,但这并不像通过简单的dt.Load()读取它那样高效.
SQLiteCommand dbCommand = myConnector.CreateCommand();
dbCommand.CommandText = "SELECT * FROM " + tablename;
SQLiteDataReader executeReader = dbCommand.ExecuteReader(CommandBehavior.SingleResult);
DataTable dt = new DataTable();
dt.Load(executeReader); // <-- FormatException
Run Code Online (Sandbox Code Playgroud)
"bei System.DateTimeParse.ParseExactMultiple(String s,String [] formats,DateTimeFormatInfo dtfi,DateTimeStyles style)\ r \n bei System.DateTime.ParseExact(String s,String [] formats,IFormatProvider provider,DateTimeStyles style)\ r \n bei System.Data.SQLite.SQLiteConvert.ToDateTime(String dateText,SQLiteDateFormats format,DateTimeKind kind),位于c:\ dev\sqlite\dotnet\System.Data.SQLite\SQLiteConvert.cs:Zeile 322."
我需要一个很好的帮助来改进当前的代码.
我慢慢地过度工作......
我有一个庞大的应用程序,包括线程,计时器,调用(不是BeginInvoke,因此它是同步的)和Application.DoEvents.
在这里发帖太多了,我不知道问题究竟在哪里.
我的每一种方法都在尝试捕获.记录每个渔获量.
如果我从Visual Studio(F5)启动应用程序或通过Ants进行性能分析,则没有问题.应用程序运行了几天.但是,只要我通过Windows资源管理器启动相同的调试版本,它就会每隔几个小时冻结一次.它会毫无例外地冻结.如果我将visual studio附加到此应用程序并将其分解,它将在Application.Run上停止(new Form1());
我真的很困惑,也不知道要修复它.
这是一个.net 3.5 winforms应用程序
它看起来像一个线程挂在这里:
if (grabber.InvokeRequired)
{
Console.WriteLine("grabber.InvokeRequired");
this.Invoke((MethodInvoker) delegate { grabber.Navigate("http://www.google.de"); }); // <-- hang
}
else
{
grabber.Navigate(ig.StartUrl);
}
Run Code Online (Sandbox Code Playgroud)
此片段是计时器事件的一部分
_timeout = new System.Timers.Timer(10000);
_timeout.Elapsed += new ElapsedEventHandler(OnWatchDogBark);
Run Code Online (Sandbox Code Playgroud)
编辑
DoEvents()的示例.这是在lock()和调用中
grabber.DocumentCompleted -= grabber_DocumentCompleted;
grabber.Navigate("http://www.google.de");
while (grabber.ReadyState != WebBrowserReadyState.Complete)
{
timeout--;
Application.DoEvents();
Thread.Sleep(200);
if (timeout < 0)
{
timeout = 50;
grabber.Navigate("http://www.google.de");
}
}
Run Code Online (Sandbox Code Playgroud)
目前我使用System.Windows.Forms.Timer和一些锁,但没有任何改进.
好吧,我使用WinDbg来获取一些信息
!线程
PreEmptive GC Alloc Lock
ID OSID ThreadOBJ State GC Context Domain Count …Run Code Online (Sandbox Code Playgroud) 是否有一个MigrationSqlGenerator供SQLite用于实体框架?我只找到了一个来自devart的商业广告.
没有为提供程序'System.Data.SQLite'找到MigrationSqlGenerator.使用目标迁移配置类中的SetSqlGenerator方法注册其他SQL生成器.
我想要一个TestMethod用于多个异常.问题是Testmethod在第一次抛出异常后停止.
我知道我可以这样做:
try
{
sAbc.ToInteger();
Assert.Fail(); // If it gets to this line, no exception was thrown
}
catch (ArgumentException) { }
Run Code Online (Sandbox Code Playgroud)
但我想使用以下代码库:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger(); // throws an exception and stops here
sDecimal.ToInteger(); // throws theoretically a exception too...
}
Run Code Online (Sandbox Code Playgroud)
而且我不想为每个可能的异常创建一个testmethod:
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sAbc.ToInteger();
}
[TestMethod, ExpectedException(typeof(ArgumentException), "...")]
public void StringToIntException()
{
sDecimal.ToInteger();
}
Run Code Online (Sandbox Code Playgroud)
编辑2018-11-09:
今天,这将基于Jan David Narkiewicz的建议.但正如我已经提到的那样.从我今天的观点来看,这对于测试来说是一个糟糕的设计.例:
[TestMethod]
public void ExceptionTest()
{
Assert.ThrowsException <FormatException> (() =>
{
int.Parse("abc"); …Run Code Online (Sandbox Code Playgroud) 错误
引起:java.lang.IllegalStateException:必须从blob上传回调请求中调用.在com.google.appengine.api.blobstore.BlobstoreServiceImpl.getUploads(BlobstoreServiceImpl.java:169)
码
public class UserUploadProfilePictureResource extends ServerResource {
@Post
public void handleBlobstoreUpload(Representation entity) {
Representation rep =null;
if (entity !=null) {
if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
Request restletRequest = getRequest();
HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(servletRequest);
Run Code Online (Sandbox Code Playgroud)
可能的解决方案(但我不想要)
第一.我不想调用第二个HttpServlet.
第二.关于这篇文章,有手动编写文件的解决方案:
谷歌说:
不推荐使用:此处用于将文件写入Blobstore的文件API功能将在将来的某个时间删除,有利于将文件写入Google云端存储并使用Blobstore为其提供服务.
可能的解决方案2(但只是解决方法的概念)
http://www.cloudave.com/1055/the-new-google-app-engine-blobstore-api-first-thoughts/
Bret Slatkin指出,当API制作用于上传文件的POST URL时,它会创建一个唯一的一次性URL,以减轻任何可能的嗅探.
这非常适合用于呈现用户提交的Web表单的情况.但是,如果您尝试提供允许上传文件的REST API(例如,想想像TwitPic这样的东西)会让事情变得更难.在这种情况下,您将必须编写自己的渲染,模拟Web表单将执行的操作(获取文件,创建随机POST URL,调用它,...)
题
在Google应用引擎中存储图片的最佳方法是什么?有没有比blobstore更好的方法?如何在blobstore中存储图像?
我正在寻找在层之间进行异步通信的最佳实践.我正在使用mvvm light工具包
目前我在模型中使用了backgroundworker,因为我在自动生成的代码中看到了这一点.不是背景工作者而是异步调用.
public void GetConfig(Action<Config, Exception> callback)
{
BackgroundWorker backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += (backgroundWorkerSender, backgroundWorkerArgs) =>
{
try
{
backgroundWorkerArgs.Result = AppEnvironment.Instance.Config;
}
catch (Exception exception)
{
backgroundWorkerArgs.Result = null;
}
};
backgroundWorker.RunWorkerCompleted += (backgroundWorkerSender, backgroundWorkerArgs) =>
{
if (backgroundWorkerArgs.Result != null)
{
callback((Config) backgroundWorkerArgs.Result, null);
}
else
{
/* ToDo: exceptionhandling */
}
};
backgroundWorker.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud)
现在我找到了AsyncDelegateCommand,它实现了ViewModel中的异步部分.
private ICommand _refreshObjectDefinitionCommand;
public ICommand RefreshObjectDefinitionCommand
{
get
{
return _refreshObjectDefinitionCommand
?? (_refreshObjectDefinitionCommand = …Run Code Online (Sandbox Code Playgroud) 我正在寻找一个好的图表控件,并找到了" 适用于Windows 8,WPF,Silverlight的现代UI(Metro)图表 "这个控件看起来非常好,但我需要这个用于Visual Studio 2010和4.0.原始源代码是用Visual Studio 2012和4.5编写的,所以我尝试用类文件创建一个新项目.一切都很好.我可以编译类并通过调试.但结果是一个空窗口.我不知道错误在哪里.这些文件没有变化,这就是我发布一些图片的原因:
工作样本

复制4.0样本

工作样本Snoop

复制4.0样本Snoop

我正在使用这个exe com服务器:
https://cfx.svn.codeplex.com/svn/Visual%20Studio%202008/CSExeCOMServer/ExeCOMServer.cs
void Init(AppsScriptRunningContext rc);无法将"AppsScriptLib.AppsScriptRunningContextClass"类型的COM对象强制转换为接口类型"AppsScriptLib.IAppsScriptRunningContext".此操作失败,因为对IID为"{4D2E5723-87C2-49C1-AA28-ED2D88275100}"的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口(HRESULT异常:0x80004002(E_NOINTERFACE))
如果我的应用程序不是com服务器而是普通的com应用程序,则没有错误.这就是为什么我认为错误是由exe com服务器产生的.
https://cfx.svn.codeplex.com/svn/Visual%20Studio%202008/CSExeCOMServer/ExeCOMServer.cs
问候,克里斯
是否有一种简单的方法可以对旋转木马进行以下更改?
c# ×10
.net ×5
com ×2
sqlite ×2
wpf ×2
blobstore ×1
casting ×1
charts ×1
css ×1
decimal ×1
exception ×1
file ×1
file-upload ×1
freeze ×1
generics ×1
interface ×1
java ×1
javascript ×1
less ×1
migration ×1
mvvm ×1
mvvm-light ×1
properties ×1
reflection ×1
sql ×1
unit-testing ×1
xaml ×1