是否可以使用以下格式的DataContractJsonSerializer将.Net Dictionary <Key,Value>序列化为JSON :
{
key0:value0,
key1:value1,
...
}
Run Code Online (Sandbox Code Playgroud)
我使用Dictionary <K,V>,因为没有预定义的输入结构.
我对DataContractJsonSerializer结果感兴趣!我已经找到了一个"Surrogate"示例,但输出中还有一个"数据",如果字典<K,String>,则转义也是假的.
我找到了解决方案,需要什么!首先,一个可序列化的"字典"类:(当然,这个示例只是以一种方式工作,但我不需要反序列化)
[Serializable]
public class MyJsonDictionary<K, V> : ISerializable {
Dictionary<K, V> dict = new Dictionary<K, V>();
public MyJsonDictionary() { }
protected MyJsonDictionary( SerializationInfo info, StreamingContext context ) {
throw new NotImplementedException();
}
public void GetObjectData( SerializationInfo info, StreamingContext context ) {
foreach( K key in dict.Keys ) {
info.AddValue( key.ToString(), dict[ key ] );
}
}
public void Add( K key, V value ) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
[DataContract]
class TestContract {
private String _Name;
private Int32 _Age;
[DataMember( Name = "Name" )]
public String Name {
get { return _Name; }
set { _Name = value; }
}
[DataMember( Name = "Age" )]
public Int32 Age {
get { return _Age; }
set { _Age = value; }
}
}
[Serializable]
public class DNCJsonDictionary<K, V> : ISerializable {
Dictionary<K, V> dict = new Dictionary<K, V>();
public DNCJsonDictionary() { }
protected DNCJsonDictionary( SerializationInfo info, StreamingContext context ) …Run Code Online (Sandbox Code Playgroud) 我有一个工作者服务 ind dotnet core 3.1:
程序.cs:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false)
.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
var configuration = builder.Build();
services.AddOptions();
// Version 1
services.Configure<A>(configuration);
// Version 2
//services.Configure<A>(o => configuration.GetSection("PollingSettings").Bind(o));
services.AddHostedService<Worker>();
})
.UseWindowsService();
}
Run Code Online (Sandbox Code Playgroud)
appsettings.Development.json:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"A": {
"option1": "value1_from_json",
"option2": -1, …Run Code Online (Sandbox Code Playgroud) 我正在寻找类似Action <T>("封装一个具有单个参数但不返回值的方法")和Func <T,TResult>("封装一个有一个参数并返回值的方法"之类的东西由TResult参数")指定的类型,但我必须封装一个没有参数和返回值的方法.有什么东西,或者我必须写一个?
我在书中看到了一个例外,但我无法弄清楚答案:
以下代码是否合法?如果没有,你怎么能让它合法?
int null = 0, *p = null;
当然,第二个不合法,你不能将int转换为int*.
主题是在该部分constexpr.
伙计们!这只是一个关于指针,consts和constexprs的练习!我想,你必须在没有cast和nullptr的情况下解决它.
我有一台配有英特尔GMA 3150显卡的华硕Eee PC,操作系统是Windows 7 Starter,安装了DirectX 11.
当我运行使用XNA 4.0的项目时,我得到以下异常graphics.ApplyChanges():
Microsoft.Xna.Framework.Graphics.NoSuitableGraphicsDeviceException was unhandled
Message=Could not find a Direct3D device that supports the XNA Framework HiDef profile.
Verify that a suitable graphics device is installed.
Make sure the desktop is not locked, and that no other application is running in full screen mode.
Avoid running under Remote Desktop or as a Windows service.
Check the display properties to make sure hardware acceleration is set to Full.
Source=Microsoft.Xna.Framework.Game
StackTrace:
at Microsoft.Xna.Framework.GraphicsDeviceManager.FindBestPlatformDevice(Boolean anySuitableDevice) …Run Code Online (Sandbox Code Playgroud) 我有以下网格:
<Grid Background="LightGray" x:Name="ProgrammPoolTextGrid">
<TextBlock x:Name="tbLeft"
Margin="0"
Text="PROGRAMMPOOL"
TextWrapping="NoWrap"
Width="100"
Height="94"
RenderTransformOrigin="0.5,0.5"
HorizontalAlignment="Left"
UseLayoutRounding="False"
d:LayoutRounding="Auto" >
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我只需要一个40像素宽的TextBlock,但如果我改变TextBlock或Grid的宽度,文本将会剪切.任何的想法?
为了
DateTime aDate = new DateTime(2000,1,1);
Console.WriteLine(aDate.ToString("d"));
Run Code Online (Sandbox Code Playgroud)
我期待1,但它写道1/1/2000。
MSDN说:
d 一个月中的第几天,从 1 到 31。
2009-06-01T13:45:30 -> 1
2009-06-15T13:45:30 -> 15
有什么解决方法吗?对于M.
任何人都可以告诉我,为什么直接将模型与MVC模式中的视图进行通信,为什么不直接通过控制器呢?
http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
c# ×4
.net-core ×2
.net ×1
c++ ×1
c++11 ×1
datacontract ×1
datetime ×1
dictionary ×1
function ×1
json ×1
reflection ×1
silverlight ×1
tostring ×1
transform ×1
xna ×1
xna-4.0 ×1