小编jav*_*iry的帖子

如何在C#中保存文件和在DB中插入记录之间创建一个Transactions望远镜

我有一个问题,用于保存文件并在TransactionScope中的DB中插入记录; 意味着保存文件和插入记录,必须依赖于=或两者兼有.有人能帮帮我吗?

c# file-io dependencies transactions insert

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

在不等待的情况下调用异步方法

我试图在不等待结果的情况下调用异步方法(在ASP.NET Web API 2应用程序中).我的意思是我希望主线程继续执行并且不等待被调用的方法来完成.我正在尝试这个片段:

// The async method:
private static async Task LogAsync(Exception exception, string ip, MethodBase method, object parameters) {
    // some stuff 
}

// The caller methods:
public static void Log1(Exception exception, object parameters) {
    LogAsync(exception, ip, method, parameters);
}
public static void Log2(Exception exception, object parameters) {
    Task.Factory.StartNew(() => LogAsync(exception, ip, method, parameters));
}
public static async void Log3(Exception exception, object parameters) {
    await LogAsync(exception, ip, method, parameters).ConfigureAwait(true);
}
public static async void Log4(Exception exception, object parameters) …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading asynchronous async-await

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

C#是可空的int可空小数的后代

我错误地发现了令我惊讶的事情.

我有这个方法

public static string PrintDecimal(decimal? input, string NumberFormat = null){ }
Run Code Online (Sandbox Code Playgroud)

我把这种方法称为这样

int? MaxFaltas = 0;
Label.Text = CustomConvert.PrintDecimal(MaxFaltas);
Run Code Online (Sandbox Code Playgroud)

为什么这是有效的,没有编译错误.我正在调用一个定义为接收a decimal?的方法int?

c# nullable decimal

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

从反射转向表达式树

List<>我有一个反射代码,用于创建(运行时已知的类型参数)的实例,并调用Add方法向其添加一些值。我的片段是这样的:

// here is my type parameter
var genericType = typeof(MyRunTimeType);
// here is a list of my values
MyRunTimeType[] values = MyRunTimeValuesOfTypeMyRunTimeType();

// creating instance of List<>
var listType = typeof(List<>);
var listGenericType = listType.MakeGenericType(genericType);
var listInstance = Activator.CreateInstance(listGenericType);

// getting Add method and call it
var addMethod = listGenericType.GetMethod("Add", genericType);
foreach (var value invalues)
    addMethod.Invoke(listInstance, new[] { value });
Run Code Online (Sandbox Code Playgroud)

那么,您建议如何将此反射片段转换为表达式树?

更新:

好吧,我写了这个片段,它似乎无法工作:

public static Func<IEnumerable<object>, object> GetAndFillListMethod(Type genericType) {

    var listType = typeof(List<>);
    var listGenericType …
Run Code Online (Sandbox Code Playgroud)

c# reflection lambda expression-trees

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

从JSON对象中删除特定属性

我有一个JSON:

{
    "scbs_currentstatus": "",
      "scbs_primaryissue": "",
      "_umb_id": "Test",
      "_umb_creator": "Admin",
      "_umb_createdate": "0001-01-01 00:00:00",
      "_umb_updatedate": "0001-01-01 00:00:00",
      "_umb_doctype": "Test",
      "_umb_login": "Test",
      "_umb_email": "Test",
      "_umb_password": {
        "newPassword": "Test",
        "oldPassword": null,
        "reset": null,
        "answer": null
      },
      "_umb_membergroup": {
        " User": false,
        "Line User": true,
        "Callback User": false,
        "Su User": false,
        },
      "umbracoMemberComments": "Test",
      "umbracoMemberFailedPasswordAttempts": ""

    }
Run Code Online (Sandbox Code Playgroud)

我试图删除所有属性以"umb_"开头.这可能在json.net中吗?

和输出将是:

{
        "scbs_currentstatus": "",
          "scbs_primaryissue": "",
           "umbracoMemberComments": "Test",
          "umbracoMemberFailedPasswordAttempts": ""
}
Run Code Online (Sandbox Code Playgroud)

使用删除我能够做到这一点,但不是所有的一次.

   result.Property("_umb_id").Remove();
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

c# json json.net c#-4.0

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

命名方法`get`会导致错误

看到这个简单的类和方法:

import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart';
import 'package:angular/angular.dart';

@Injectable()
class ApiClient {

  final Client _http;
  static final _headers = { 'Content-Type': 'application/json' };
  static final _encodedHeaders = { 'Content-Type': 'application/x-www-form-urlencoded' };

  ApiClient(this._http);

  Future<T> get<T>(String url, T f(dynamic e)) async {
    try {
      final response = await _http.get(url);
      var data = JSON.decode(response.body);
      print(data);
      if(data == null)return null;
      final ts = f(data);
      return ts;
    } catch (e) {
      _handleError(e);
      return null;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

它会导致此错误:

意外的标记'未来'.

Future get(String url,T f(dynamic e))async …

dart angular-dart

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

设计模式、架构模式、架构风格和架构之间有什么区别?

谁能描述一下设计模式、架构模式、架构风格和架构之间的区别?提前致谢。

architecture design-patterns architectural-patterns

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

openSuse 中的“dotnet new command”导致“找不到可用的 libssl 版本”错误

我正在尝试在 openSuse 中开发 .NET Core。我确实安装了 SDK 和教程中的所有内容。现在,当我尝试运行dotnet new console命令时,出现此错误:

找不到可用的 libssl 版本

中止(核心转储)

我找到了这个答案:(. NET Core 2.1 SDK Linux x64 没有找到可用的 libssl 版本),但没有得到我应该怎么做来解决问题。他们似乎是 deep-linuxer(我不是,我只是想学习 linux)。知道如何运行命令吗?

更新:系统信息:

openSUSE Leap 15.0

内核版本 4.12.14-lp150.12.22-default

操作系统类型:64-bit

linux opensuse libressl .net-core

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

如何在循环中只显示一次消息框

我是New C in,

我正在使用messagebox来显示该行.但是它处于一个循环中,所以消息框显示的次数我想只显示一次,并且下次不应显示消息框.

try{
    using (var sr = File.OpenText("test.txt")){
        string newone = 20110501;//date
        string line;
        while ((line = sr.ReadLine()) != null){
            if (three => one){
                MessageBox.Show("Buy : " + line);
                //Its Displaying more than 50 times i want to displayit only
                //onetime and should dispose for the next Time
            }
        }
    }
} catch { }
Run Code Online (Sandbox Code Playgroud)

提前致谢.

c# loops while-loop

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