小编Dan*_*inu的帖子

使用 Newtonsoft C# 从 json 转换为 Enum

我如何将 json 反序列化为 C# 中的枚举列表?

我写了以下代码:

  //json "types" : [ "hotel", "spa" ]

   public enum eType 
    {
      [Description("hotel")] 
      kHotel, 
      [Description("spa")]
      kSpa
    }

    public class HType 
    { 
       List<eType> m_types; 

        [JsonProperty("types")]
         public List<eType> HTypes { 
         get
          {
               return m_types;
          } 
           set
          {
             // i did this to try and decide in the setter
             // what enum value should be for each type
             // making use of the Description attribute
             // but throws an exception 
          }
Run Code Online (Sandbox Code Playgroud)

} }

       //other class 

               var hTypes = …
Run Code Online (Sandbox Code Playgroud)

c# json json.net

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

正则表达式 - >只有字母,以点结尾

我正在尝试选择仅包含字母或仅包含字母且以点结尾的所有标记.

有效单词示例:"abc", "abc."
无效"a.b" "a2"

我试过这个

string[] tokens = text.Split(' ');
var words = from token in tokens 
            where Regex.IsMatch(token,"^[a-zA-Z]+.?$")
            select token;
Run Code Online (Sandbox Code Playgroud)

^[a-zA-Z]+ - 只发信一次或多次,以字母开头

.?$=以0或1点结束?对此不确定

c# regex

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

GridView Column验证,显示错误信息不要松散焦点

我需要验证gridView列,例如列中所有元素的总和<= 100;

如果用户输入值并且总和超出限制,我想显示自定义错误消息.

我已尝试在列的repositoryedit上使用此事件:

 void pinEditRepositoryItem_Validating(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = true;
        gridview1.SetColumnError(m_imixGridView.Columns["MyColumn"], "ColumnSum must be <= 100", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
    }
Run Code Online (Sandbox Code Playgroud)

但是,在设置时

              e.Cancel = true;
Run Code Online (Sandbox Code Playgroud)

我收到默认消息"无效值".

如果我使用

       gridview1.SetColumnError(m_imixGridView.Columns["MyColumn"], "ColumnSum must be <= 100", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
Run Code Online (Sandbox Code Playgroud)

只有,错误信息是正确的,但如果我点击外面焦点丢失.

我已经看到有多种方法可以验证行,但是没有找到最适合这种情况的解决方案.

如果验证失败,是否可以禁用单元格上的"非聚焦"?

非常感谢!

c# gridview devexpress winforms

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

Google Play应用副本保护,许可.这可以在以后添加吗?

我知道这个话题已在这里多次讨论过了.

这是我第一次将应用上传到Google Play.该应用程序是免费的.我阅读谷歌的许可支持网页,但我真的很困惑.根据我的理解,许可应该用于付费应用程序,以防止将应用程序从一个设备复制到另一个设备.

我的应用程序将是免费的.我需要实施许可吗?我想这只能帮助我防止应用程序从一台设备复制到另一台设备(可能不会是这样的,因为它是免费的)但是,如果我使用它,我可能会跟踪正确的下载次数.这会以不同的方式帮助我吗?

我读到,当您上传应用时,应该有一些复选框"复制保护"您的应用.它仍然存在且可用吗?

将来我计划在应用程序中添加一些付费模块.是否可以在即将发布的版本中添加许可?

非常感谢,Dan

android android-lvl

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

装配未加载c#

我有一个Common包含log4net CustomAppender 的项目.我在所有其他项目中引用该项目并在其中配置log4net appender app.config.除了在尝试实例化Appender时失败的一个项目,一切都顺利进行.

输出显示以下错误:

System.TypeLoadException: Could not load type [Common.Appenders.MyCustomAppender].
Tried assembly [log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a]
and all loaded assemblies
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR Appender named [MyCustomAppender] not found.

所有项目的log4net配置都相同.app.config包含:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
    <appender name="MyCustomAppender" type="Common.Appenders.MyCustomAppender">
      <file value="log.txt" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] …
Run Code Online (Sandbox Code Playgroud)

.net c# log4net

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

c#将var声明为接口.为什么这可能?

我无法真正理解这个概念.

假设我有这个界面:

    public interface IValidate 
    {
       Dictionary<eValidationErrors, List<string>> ValidationMessages { get; }
     }
Run Code Online (Sandbox Code Playgroud)

当我说:

          var Validator = control as IValidate;
          Validator.ValidationMessages.Add(key,list);
Run Code Online (Sandbox Code Playgroud)

什么是验证者?为什么我可以这样使用界面?

谢谢

c# interface

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

用于优化

我正在尝试优化此代码:

   foreach (string id in ids)
   {
     MyClass x = myDictionary[id];
     foreach (var map in Maps)
     {
       if ( x.id == map.SourceId || x.id == map.DestionationId)
       {
           //add id to a hashset
       }
     }
   }
Run Code Online (Sandbox Code Playgroud)

如果ids.count为1600且Maps.Count为300 000,则需要大约10分钟才能处理.

我试过LINQ,但结果不是很好:

   var allIds = Maps.select(map => map.SourceId).Union(Maps.select(map => map.DestinationID)).Distinct();
   var toAdd = from id in Ids
               join mapId in AllIds on id equals mapid
               select id;
  //create hashset based on  toAdd collection.
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出我更好的解决方案,如果可能解释为什么linq在这种情况下不是更快?

谢谢

c# linq optimization time-complexity

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

是否有可能从转储中获取从中抛出异常的行?

我有一个转储文件,并用WinDbg加载它.

我使用了!pe(打印异常)来查看异常(空引用异常).但是,它指出了一个包含~100行的方法.

是否有可能找到抛弃异常的行?

    0:000> !pe
   Exception object: 00000000822e7e28
    Exception type:   System.NullReferenceException
    Message:          Object reference not set to an instance of an object.
    InnerException:   <none>
    StackTrace (generated):
SP               IP               Function
00000000001FBDC0 000007FF06468F6B Utils.Page.OnActivate()+0x6db
Run Code Online (Sandbox Code Playgroud)

+ 0x6db是什么意思?

非常感谢,Dan

编辑:

我有源文件,但我不能重现这个问题.这就是我想找出确切线的原因

EDIT2 :(在Brian建议使用!u命令之后)

这是使用!u命令后的快照

    0:000> !u 000007ff03af9a38
   Normal JIT generated code
  Page.OnActivate()
  Begin 000007ff06468890, size 84b
  000007ff`06468890 53              push    rbx
  000007ff`06468891 55              push    rbp
  000007ff`06468892 56              push    rsi
  000007ff`06468893 57              push    rdi
  000007ff`06468894 4883ec78        sub     rsp,78h
  000007ff`06468898 488d6c2430      lea     rbp,[rsp+30h]
  000007ff`0646889d 488bf2          mov     rsi,rdx …
Run Code Online (Sandbox Code Playgroud)

.net debugging windbg

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

在不阻塞当前线程的情况下显示表单(对话框)(进度条示例)

我正在尝试创建一个ProgressBar表单,该表单使用BackgroundWorker在显示进度条的同时在不同的线程上执行操作.

目前,我的ProgressBar类包含一个ProgressBarControl,下面是代码的样子:

public partial class QTProgressBar : DevExpress.XtraEditors.XtraForm
{
    private BackgroundWorker m_backgroundWorker;
    private AutoResetEvent m_resetEvent;

    public QTProgressBar()
    {
        InitializeComponent();

        InitializeProgressBar();

        m_backgroundWorker = new BackgroundWorker();
        m_backgroundWorker.WorkerReportsProgress = true;
        m_backgroundWorker.WorkerSupportsCancellation = true;
        m_backgroundWorker.DoWork += new DoWorkEventHandler(m_backgroundWorker_DoWork);
        m_backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(m_backgroundWorker_ProgressChanged);
        m_backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_backgroundWorker_RunWorkerCompleted);
        m_resetEvent = new AutoResetEvent(false);
    }

    void m_backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        m_resetEvent.Reset();

        CloseProgressBar();
    }

    void CloseProgressBar()
    {
        if (InvokeRequired)
        {
            Invoke( new MethodInvoker(CloseProgressBar));
            return;
        }
        this.Close();
    }

    void m_backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        Action operation = …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading devexpress

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

#define Square(x)(x*(x))

可能重复:
使用#define定义的数字的平方

你能解释为什么以下代码输出"29"?

#define Square(x) (x*(x))

void main()
{
    int x = 5;
    printf("%d", Square(x+3));
}
Run Code Online (Sandbox Code Playgroud)

c c-preprocessor

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