我想知道是否有任何简单的方法可以使用 XmlSerialier 用逗号小数分隔符反序列化十进制数?我正在从其他软件以 xml 格式导出数据,xml 文件中的所有数字(价格、数量、折扣等等)都以逗号作为小数点分隔符。
这是我尝试做的简化示例:
假设有带有名称和价格的产品类:
[Serializable]
public class Product
{
public string Name { get; set; }
public decimal Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有 xml ...
string xmlExample = "<Product><Name>Coca Cola, 2L</Name><Price>3,50</Price></Product>";
Run Code Online (Sandbox Code Playgroud)
当我试图反序列化那个 xml 时...
XmlSerializer serializer = new XmlSerializer(typeof(Product));
StringReader stringReader = new StringReader(xmlExample);
Product product = serializer.Deserialize(stringReader) as Product; //<-- Error here
Run Code Online (Sandbox Code Playgroud)
我收到错误XML 文档中有错误 (1, 57)。
当 xml 中的价格为 3.50 时,Everythig 工作正常。
我知道我可以将 Price 属性更改为 sting 和 TryParse 十进制,但也许有更好的解决方案(例如切换文化)?
任何建议,解决方案和意见表示赞赏。
更新: 忘记提及我当前的文化设置已经使用逗号作为十进制符号。
通过该代码捕获屏幕截图来保存.
Graphics Grf;
Bitmap Ekran = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppPArgb);
Grf = Graphics.FromImage(Ekran);
Grf.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
Ekran.Save("screen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
然后将此保存的屏幕截图作为电子邮件发送:
SmtpClient client = new SmtpClient();
MailMessage msg = new MailMessage();
msg.To.Add(kime);
if (dosya != null)
{
Attachment eklenecekdosya = new Attachment(dosya);
msg.Attachments.Add(eklenecekdosya);
}
msg.From = new MailAddress("aaaaa@xxxx.com", "Konu");
msg.Subject = konu;
msg.IsBodyHtml = true;
msg.Body = mesaj;
msg.BodyEncoding = System.Text.Encoding.GetEncoding(1254);
NetworkCredential guvenlikKarti = new NetworkCredential("bbbb@bbbb.com", "*****");
client.Credentials = guvenlikKarti;
client.Port = 587;
client.Host = "smtp.live.com";
client.EnableSsl = true; …Run Code Online (Sandbox Code Playgroud) 假设我有 test.proto 文件:
syntax = "proto3";
option java_package = "testing";
option java_outer_classname = "Test_v1";
import "google/protobuf/wrappers.proto";
message TestMessage {
.google.protobuf.Int32Value integerField = 1;
}
Run Code Online (Sandbox Code Playgroud)
如果我将它编译(使用 protoc v3.5.0)到 C# 代码,我将获得可为空的类型属性:
public int? IntegerField {
get { return integerField_; }
set { integerField_ = value; }
}
Run Code Online (Sandbox Code Playgroud)
但是如果我将它编译为 Java 代码,字段将是众所周知的类型:
public Builder setIntegerField(com.google.protobuf.Int32Value value) {
if (integerFieldBuilder_ == null) {
if (value == null) {
throw new NullPointerException();
}
integerField_ = value;
onChanged();
} else {
integerFieldBuilder_.setMessage(value);
}
Run Code Online (Sandbox Code Playgroud)
我正在将项目从 proto2 移至 proto3,因此我想避免使用众所周知的类型,因为更改相关代码需要大量工作。对于 …
When reading
How to: Create Pre-Computed Tasks
the example method DownloadStringAsync returns
Task.Run( async ()=> { return await new WebClient().DownloadStringTaskAsync(address)})
Run Code Online (Sandbox Code Playgroud)
I wonder why we need to wrap a async method in a Task.Run()? the WebClient().DownloadStringTaskAsync() method returns a Task itself.
我需要读取一个打开的文件,以便在程序的其他部分进行写入
const string fileName = "file.bin";
FileStream create = File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.Read);
FileStream openRead = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Run Code Online (Sandbox Code Playgroud)
最后一行引发IOException:
"The process cannot access the file because it is being used by another process"
Run Code Online (Sandbox Code Playgroud)
请帮助正确配置File.Open参数。
好的,这个问题更多的是关于理解问题是什么,因为我认为任何人都无法告诉我如何解决问题.
我正在写一个.net 4应用程序,我有一个我要引用的第三方DLL(hasp加密狗保护).
Visual Studio允许我创建引用,并在我的代码中使用dll中包含的类.
第一个问题发生在程序运行并且实际加载了dll时.然后我得到以下错误.
System.BadImageFormatException:无法加载文件或程序集"hasp_net_windows.dll"或其依赖项之一.不是有效的Win32应用程序
此网络链接说明如何修复此错误.Coud有人透露了问题是什么以及为什么我会得到它.
按照这个建议后,我将主项目构建设置为x86然后我得到另一个错误替换另一个.新错误是:
System.IO.FileLoadException:混合模式程序集是针对运行时的版本"v1.1.4322"构建的,如果没有其他配置信息,则无法在4.0运行时加载
这个weblink说明了如何修复错误,但是我的项目中没有app.config,并且想要尽可能避免使用app.config.如果有人能够再解释一下这个问题会有什么帮助呢?
如果您需要更多信息,请告诉我.
这是我在formview中的select语句的一部分,它在更新过程中一直运行,直到它达到空值.
(SELECT TOP 1 F.tel_id FROM TELEPHONE as F where F.tel_type_id = 3 AND F.client_id = @id
ORDER BY sort_no ) AS faxid
Run Code Online (Sandbox Code Playgroud)
所以我尝试以下列方式使用ISNULL函数,但它会抛出错误.怎么做到呢?
ISNULL((SELECT TOP 1 F.tel_id FROM TELEPHONE as F where F.tel_type_id = 3 AND F.client_id= @id ORDER BY sort_no ) AS faxid ,0) AS faxid
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以写这样的东西:
List<string> list;
string sub;
if( list.Contains( s=>s.Contains(sub) ) ) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
在代码中我想要的是查看是否list<string> list包含string s某个子字符串string sub,我之前将其设置为一个值
提前致谢
我正在研究C++和C#之间的dllexport和dllimport.
我已经阅读了这篇文章http://functionx.com/csharp2/libraries/cppcli.htm
我的C++库代码:
// Business.h
#pragma once
using namespace System;
namespace Business {
public ref class Finance
{
public:
double CalculateDiscount(double MarkedPrice,
double DiscountRate)
{
return MarkedPrice * DiscountRate / 100;
}
};
}
Run Code Online (Sandbox Code Playgroud)
这是C#代码:
using System;
using System.Runtime.InteropServices;
using Business;
namespace DepartmentStore
{
class Exercise
{
[DllImport("Business.dll")]
public static extern double CalculateDiscount(double price,
double discount)
static int Main()
{
Finance fin = new Finance();
double markedPrice = 275.50;
double discountRate = 25.00; // %
double discountAmount = fin.CalculateDiscount(markedPrice, …Run Code Online (Sandbox Code Playgroud) 在我的解决方案中,我有一个本地数据库和一个带有GetQuery函数的数据库连接类.此函数工作正常,但由于某种原因,它不会处理查询,如下所示.当我运行一个查询SELECT * FROM logs时,一切正常,但当我尝试使用此查询时
SELECT klantnr AS 'Klantnummer',
klantnaam AS 'Klantnaam',
vraag AS 'Vraag/probleem',
informatie AS 'Informatie/uitvoering',
antwoord AS 'Antwoord/oplossing',
datum AS 'Datum',
tijd AS 'Tijd'
FROM logs
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息: There was an error parsing the query. [ Token line number = 1,Token line offset = 21,Token in error = Klantnummer ]
我有以下格式的几个xml文件.
<!--?xml version="1.0" standalone="yes"?-->
<details>
<Classes>
<class>5</class>
<section>A</class>
</Classes>
<student>
<firstname>Avijeet</firstname>
<lastname>Roy</lastname>
<roll>01</roll>
</student>
<student>
<firstname>Saurav</firstname>
<lastname>Das</lastname>
<roll>02</roll>
</student>
<Classes>
<class>10</class>
<section>A</class>
</Classes>
<student>
<firstname>Saumitra</firstname>
<lastname>Bain</lastname>
<roll>10</roll>
</student>
<student>
<firstname>Tarun</firstname>
<lastname>Sing</lastname>
<roll>11</roll>
</student>
</details>
Run Code Online (Sandbox Code Playgroud)
现在我想要一个像我的asp.net页面一样的数据网格
Class Section fname lname roll
5 A Avijeet Roy 01
5 A Saurav Das 02
10 A Saumitra Bain 10
10 A Tarun Sing 11
Run Code Online (Sandbox Code Playgroud)
我搜索了很多,但找不到类似的东西.我是C#的新手