小编Chr*_*tle的帖子

无法将Newtonsoft.Json.Linq.JArray转换为Newtonsoft.Json.Linq.JToken.当我通过json时出错

我需要将检查过的复选框代码传递给JavaScript中的C#.我能够通过JSON发送代码.我的JSON值是JArray.我在标题中得到了例外.

JSON:

{
  "Items": [
    "100066",
    "100067"
  ]
}
Run Code Online (Sandbox Code Playgroud)

C#:

public ActionResult UpdateTransportRequests()       
{
    string json;
    using (var reader = new StreamReader(Request.InputStream))
    {
        json = reader.ReadToEnd();
    }

    JObject jo = (JObject)JsonConvert.DeserializeObject(json);

    string lineItems = jo.Value<string>("Items");

    RequestDataAccess rda = new RequestDataAccess();
    decimal reqId = decimal.Parse(lineItems);
    rda.ApproveReject_Request(reqId, "A", "");

    return Json(new { result = "success" });
}
Run Code Online (Sandbox Code Playgroud)

客户端:

function approveAll(requestid) {
    var items = [];

    $('#grid tbody').find('input:checkbox:checked').each(function (index, item) {
        var rowIndex = $(this).closest('tr').index();
        items.push($('#grid tbody').find('tr:eq(' + rowIndex + ')').find('td:eq(1)').text().replace('TR-', ''));

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

c# json json.net

9
推荐指数
2
解决办法
4万
查看次数

C#中的Point类

我对C#很陌生,我正在尝试做一些事情,但没有取得多大成功.我正在尝试使用该类Point(带坐标的那个).

这是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace app2{
    class Program{
        static void Main(string[] args){

            Point p1 = new Point();
            p1.X = 7;
            p1.Y = 6;

            Console.WriteLine(p1.X);
            Console.WriteLine(p1.Y);

            Console.ReadLine();
        }     
    }
}
Run Code Online (Sandbox Code Playgroud)

错误是:

找不到类型或命名空间Point

我一直在Java中以非常类似的方式使用这个类,我应该声明我自己的Point类/函数返回X和Y坐标吗?

c#

8
推荐指数
1
解决办法
5万
查看次数

是否可以将Expression <Func <T,bool >>转换为Expression <Func <MyType,bool >>?

我有一个包含一些泛型方法的存储库类.一个是

public IEnumerable<T> FindAll<T>(Expression<Func<T, bool>> predicate) where T : class
{
    return GetDbSet<T>().Where(predicate);
}
Run Code Online (Sandbox Code Playgroud)

对于单元测试,我有一个TestRepository使用内存中对象而不是数据库.该TestRepository覆盖的FindAll方法,我想控制返回什么.所以我希望能够做到这样的事情:

public override IEnumerable<T> FindAll<T>(Expression<Func<T, bool>> predicate)
{
    return MyEntities.Where(predicate).Cast<T>();
}
Run Code Online (Sandbox Code Playgroud)

MyEntities.Where()只接受一个Expression<Func<MyEntity, bool>>.

如何将通用表达式转换/转换为强类型表达式?

c# lambda unit-testing

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

如何在单元测试asp.net mvc应用程序中模拟Request对象

我正在开发一个asp.net mvc 3.0应用程序.在单元测试我的控制器中的一个动作方法时,我收到了一个错误.

如何模拟: Request.Params["FieldName"]

我已经包含了Moq框架,但不确定如何传递价值

这是我的代码...请建议......

 var request = new Mock<System.Web.HttpRequestBase>();

 request
     .SetupGet(x => x.Headers)
     .Returns(
         new System.Net.WebHeaderCollection
         {
             {"X-Requested-With", "XMLHttpRequest"}
         });

 var context = new Mock<System.Web.HttpContextBase>();

 context.SetupGet(x => x.Request).Returns(request.Object);

 ValidCodeController target = new ValidCodeController();

 target.ControllerContext =
     new ControllerContext(context.Object, new RouteData(), target);
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc unit-testing moq request

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

Double.Parse在德语语言环境中失败

我有一个覆盆子pi,系统语言设置为"de_DE.UTF-8",单声道版本3.28安装.我的程序需要转换StringsDoubles,但我遇到了一些问题:

Double.Parse("500", NumberStyles.Float, CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

工作得很好.

Double.Parse("500.123", NumberStyles.Float, CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

抛出FormatException,奇怪的是什么.

Double.Parse("500,123", NumberStyles.Float, CultureInfo.GetCultureInfo("de-DE"));
Run Code Online (Sandbox Code Playgroud)

也投掷FormatException;

有趣的是,如果我将系统语言(sudo raspi-config)更改为"en-GB.UTF-8",则所有功能都按预期工作.任何人都知道如何解决这个问题作为德国用户我想使用德国系统设置.

c# mono

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

如何加快ListBox渲染和ListCollectionView过滤?

这里有一个双管齐下的问题,但我认为这两个主题交织在一起足以保证它们包含在一起.

在我们的应用程序中,我们有一个ListBox,其中填充了大量的项目.这些项目中的每一项都显示有相当复杂的项目模板.它必然相当复杂,虽然它可能会被削减一点,但我可能不会花费很多钱.在项目ListBox来自ListCollectionView其被构造从ObservableCollection<>所述对象的显示量.

我们有两个问题.

第一个是当我们重新配置过滤器ListCollectionView并调用Refresh它时,在UI被拆除并重新创建时,在UI中有一个非常明显的锁定几秒钟,并且ListBox重新填充.这种锁定的持续时间似乎与包含在其中的元素数量有关ListBox,并且在ListBox客户区域充满项目时最长.我们非常肯定锁定是由重新创建的项目模板引起的.我尝试过打开虚拟化,但这对减少或消除减速没有任何影响.我还在研究其他一些优化,比如检查我们的绑定和修改布局.是否有任何方法可以避免这个特定问题,加快速度,或将其移动到不同的线程?(我知道最后一个是不太可能的,因为渲染都是单线程的,但也许有一些解决方法...)

第二个涉及过滤ListCollectionView.虽然目前这不是一个问题,但我们认为过滤有可能成为一个问题并导致UI线程明显锁定.我正在努力减少过滤开销,但我想知道是否有一种方法将on ListCollectionView上的Refresh调用移动到另一个线程?到目前为止,我的尝试都没有成功,似乎是因为ListCollectionView它不会自动将某些事件编组到正确的线程上.

指出或解释这两个问题的任何已知或潜在解决方案将非常有帮助.

c# wpf optimization xaml filtering

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

为什么POJO类需要实现Serializable接口?

为什么POJO Java类必须实现Serializable接口?如果我不执行Serializable会怎么样?

@Entity
@Table(name="Customer")
public class Customer implements Serializable {

    private static final long serialVersionUID = -5294188737237640015L;
    /**
     * Holds Customer id of the customer
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "cust_id")
    private int Custid;

    /** Holds first Name of the customer*/
    @Column(name = "first_name")
    private String firstName;

    /** Holds last Name of the customer */
    @Column(name = "last_name")
    private String lastName;

    /** Holds Customer mobile number of customer*/
    @Column(name = "cust_mobile")
    private long MobileNo; …
Run Code Online (Sandbox Code Playgroud)

java

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

ElasticSearch.NET连接/客户端管理生命周期

当我使用ElasticSearch.NET建立与ElasticSearch集群的连接时,我使用的代码块如下:

var uris = settingsProvider.ElasticSearchUri.Split(';').Select(x => new Uri(x));
var sniffingConnectionPool = new SniffingConnectionPool(uris);
var connectionConfiguration =
    new ConnectionConfiguration(sniffingConnectionPool)
        .SniffOnConnectionFault()
        .SniffOnStartup();
var client = new ElasticsearchClient(settings: connectionConfiguration);
Run Code Online (Sandbox Code Playgroud)

难道建议我memoize的/让静态/做一个单包装的ElasticsearchClient,对ConnectionConfiguration,或者SniffingConnectionPool使他们不必每次都让我搜到重建?

.net object-lifetime elasticsearch

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

在某些方法中,编译在固定块之后省略代码

我们在其中一个项目中的类中有以下方法:

private unsafe void SomeMethod()
{
    // Beginning of the method omitted for brevity

    var nv = new Vector4[x];

    fixed (Vector4* vp = nv)
    {
        fixed (float* tp = /* Source float ptr */)
        {
            fixed (double* ap = /* Source double ptr */)
            {
                for (var i = atlArray.Length - 1; i >= 0; --i)
                {
                    vp[((i + 1) << 3) - 2] = new Vector4(tp[i], btt, 0.0f, 1.0f);
                    // Additional Vector4 construction omitted for brevity

                    nttp[i] = new …
Run Code Online (Sandbox Code Playgroud)

c# il visual-studio-2013

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

使用Reactive Extensions(RX)如何解决编译错误"无法从'方法组'转换为'System.IObserver"

使用时IObservable,此行不会编译:

var x = receiver.Updates().Subscribe(OnNewMessage);
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error   3   Argument 1: cannot convert from 'method group' to 'System.IObserver<IMyClass>'      
Run Code Online (Sandbox Code Playgroud)

而这个错误:

Error   2   The best overloaded method match for 'System.IObservable<IMyClass>.Subscribe(System.IObserver<IMyClass>)' has some invalid arguments    
Run Code Online (Sandbox Code Playgroud)

源代码使用IObservable.

c# system.reactive

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