小编Ori*_*aev的帖子

在 MessagePack 中使用接口作为属性类型序列化对象

我正在尝试使用 MessagePack 来序列化具有接口类型属性的对象。当我调用时Pack,它抛出SerializationException说没有为接口定义序列化程序。

代码示例:

namespace ConsoleApplication1
{
  // interfaces and classes declaration

  public interface IDummyInterface { }

  public class DummyObject : IDummyInterface
  {
    public string Value { get; set; }
  }

  public class SmartObject
  {
    public string Name { get; set; }

    IDummyInterface DummyOne { get; set; }
  }

  // in main
  var mySmartObject = new SmartObject() { Name = "Yosy", DummyOne = new DummyObject() { Value = "Value"} };

  using(var stream = new MemoryStream())
  { …
Run Code Online (Sandbox Code Playgroud)

c# serialization msgpack

6
推荐指数
1
解决办法
1415
查看次数

如何验证tinyMCE弹出文本框值

请任何人帮助我.我需要tinyMCE弹出文本框验证.单击确定时如何验证文本框这里我使用下面的代码.

tinymce.PluginManager.add('weblink', function(editor, url) {
    editor.addButton('weblink', {
        text: 'Web Link',
        icon: false,        
        onclick: function() {
            editor.windowManager.open({
                title: 'Web Link',
                body: [
                {type: 'textbox', name: 'caption', label: 'Enter Your Caption',maxLength:20},
                {type: 'textbox', name: 'weburl', label: 'Enter Your Web URL',maxLength:32}
                ],
                onsubmit: function(e){
                    var weblinkTxt  =   "href='"+e.data.weburl+"'";

                        if(hyperlink!='' && (hyperlink==1 || hyperlink =='1'))
                        {
                            editor.insertContent("<a "+weblinkTxt+">"+ e.data.caption+"</a>")
                        }
                        else
                        {
                            editor.insertContent("<img src='"+emailImg+"'>"+ e.data.caption+" "+e.data.weburl)
                        }

                }
            });
        }
    });  
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery tinymce

3
推荐指数
1
解决办法
801
查看次数

MVC HttpContext.Response.Write()vs Content()

我已经看到这两种方式将xml作为客户端响应发送.

选项1:

var context = System.Web.HttpContext.Current;
            context.Response.Clear();
            context.Response.Write(sw.ToString());
            context.Response.ContentType = "text/xml";
            context.Response.End();
Run Code Online (Sandbox Code Playgroud)

选项2:

return Content(sw.ToString(), "text/xml");

选项2更方便,但是在性能,安全性等方面有一个优势吗?哪个是首选(最佳做法)?

asp.net-mvc

2
推荐指数
1
解决办法
2864
查看次数

本地函数受益于异步方法

根据微软文档

本地函数有两种常见的用例:公共迭代器方法和公共异步方法。这两种类型的方法生成的代码报告错误的时间比程序员预期的要晚。...该技术可以与异步方法一起使用,以确保在异步工作开始之前抛出参数验证引起的异常

public Task<string> PerformLongRunningWork(string address, int index, string name)
{
    if (string.IsNullOrWhiteSpace(address))
        throw new ArgumentException(message: "An address is required", paramName: nameof(address));
    if (index < 0)
        throw new ArgumentOutOfRangeException(paramName: nameof(index), message: "The index must be non-negative");
    if (string.IsNullOrWhiteSpace(name))
        throw new ArgumentException(message: "You must supply a name", paramName: nameof(name));

    return longRunningWorkImplementation();

    async Task<string> longRunningWorkImplementation()
    {
        var interimResult = await FirstWork(address);
        var secondResult = await SecondStep(index, name);
        return $"The results are {interimResult} and {secondResult}. Enjoy."; …
Run Code Online (Sandbox Code Playgroud)

.net c# async-await c#-7.0

1
推荐指数
1
解决办法
1046
查看次数