小编use*_*174的帖子

如何将xml反序列化为对象

<StepList>
  <Step>
    <Name>Name1</Name>
    <Desc>Desc1</Desc>
  </Step>
  <Step>
    <Name>Name2</Name>
    <Desc>Desc2</Desc>
  </Step>
</StepList>
Run Code Online (Sandbox Code Playgroud)

我有这个XML,我应该如何建模类,以便我可以使用XmlSerializer对象反序列化它?

c# xml-deserialization

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

如何配置log4net以在调试模式下打印到控制台

有没有办法配置log4net以在调试期间将日志打印到控制台和文件?

我试图通过在日志发生时立即观察日志来找到一种有效调试软件的方法.

写入文件对我来说是有问题的,因为我不想等到文件被刷新到磁盘然后打开它.

因此我更喜欢它写入控制台.

你有什么建议?

我添加了app.config附加附加的文件,但我无法显示结果控制台.

以下是我的app.config配置:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IProviderService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8081/AP2" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IProviderService" contract="IProviderService" name="WSHttpBinding_IProviderService">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
   <log4net debug="true">
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> …
Run Code Online (Sandbox Code Playgroud)

c# debugging log4net log4net-configuration

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

如何更改Magento默认管理语言

我有Magento 1.7.0.2德国网站.如何将管理面板默认更改为英文?(我知道我可以从下拉列表中选择语言,但是我希望它默认设置为英语)

magento

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

如何通过c#读取PowerShell退出代码

System.Management.Automation.Runspaces用来执行PowerShell脚本.有没有一个选项我可以读取给定脚本的退出代码?

using System.IO;
using System.Management.Automation.Runspaces;
using System.Collections.ObjectModel;
using System.Management.Automation;

namespace PowerShell
{
    public class PowerShellExecuter
    {
        public Collection<PSObject> RunPsScript(string psScriptFile)
        {
            string psScript;
            if (File.Exists(psScriptFile))
            {
                psScript = File.ReadAllText(psScriptFile);
            }
            else
            {
                throw new FileNotFoundException("Wrong path for the script file");
            }
            Runspace runSpace = RunspaceFactory.CreateRunspace();
            runSpace.Open();

            RunspaceInvoke runSpaceInvoker = new RunspaceInvoke(runSpace);
            runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");

            Pipeline pipeLine = runSpace.CreatePipeline();
            pipeLine.Commands.AddScript(psScript);
            pipeLine.Commands.Add("Out-String");

            Collection<PSObject> returnObjects = pipeLine.Invoke();
            runSpace.Close();

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

c# powershell

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

如何将string []与字符串组合在一起,中间有空格

如何将string []解析为中间有空格的字符串如何重构此代码?

    internal string ConvertStringArrayToString(string[] array)
    {
        StringBuilder builder = new StringBuilder();
        builder.Append(array[0]);
        for (int i = 1; i < array.Length; i++)
        {
            builder.Append(' ');
            builder.Append(array[i]);
        }
        return builder.ToString();
    }
Run Code Online (Sandbox Code Playgroud)

c#

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

为什么将List <Term>的参数重构为IEnumerable <Term>?

我有一个看起来像这样的方法:

    public void UpdateTermInfo(List<Term> termInfoList)
    {
        foreach (Term termInfo in termInfoList)
        {
            UpdateTermInfo(termInfo);
        }
        m_xdoc.Save(FileName.FullName);
    }
Run Code Online (Sandbox Code Playgroud)

Resharper建议我改变方法签名IEnumerable<Term>而不是List<Term>.这样做有什么好处?

c# resharper refactoring interface

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

如何将异常显式传递给c#中的主线程

我很熟悉一个线程中抛出的异常通常无法在另一个线程中捕获的事实.我怎样才能将错误转移到主线程?

public static void Main()
{
   new Thread (Go).Start();
}

static void Go()
{
  try
  {
    // ...
    throw null;    // The NullReferenceException will get caught below
    // ...
  }
  catch (Exception ex)
  {
    // Typically log the exception, and/or signal another thread
    // that we've come unstuck
    // ...
  }
}
Run Code Online (Sandbox Code Playgroud)

c# multithreading

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

重构方法的最佳实践

我想知道重构代码的最佳实践是什么样的:

应该在哪里设置退出标准,以及最佳做法是什么

    private static bool Foo()
    {
        bool result = false;

        if (DoMehod1())
        {
            if (DoMehod2())
            {
                if (DoMethod3())
                {
                    result = true;
                }
                else
                {
                    Console.WriteLine("DoMethod3 Failed");
                }
            }
            else
            {
                Console.WriteLine("DoMethod2 Failed");
            }
        }
        else
        {
            Console.WriteLine("DoMethod1 Failed");
        }
        return result;
    }
Run Code Online (Sandbox Code Playgroud)

谢谢

.net c# refactoring

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

ASP.NET从JS AJAX调用非静态webmethod

可能重复:
从客户端调用服务器端的非静态方法(aspx.cs)使用javascript(aspx)

我有以下代码,工作正常

function getFooObj() {
    $.ajax({
        type: "POST",
        url: "Dummy.aspx/GetFooObj",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
           alert('good');
        }
    });
}

[WebMethod]
public static FooObj GetFooObj ()
{
    // some code that returns FooObj 
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果我希望我的WebMethod不是静态的,我怎么能从JS调用它?

[WebMethod]
public FooObj GetFooObj ()
{
    // some code that returns FooObj 
}
Run Code Online (Sandbox Code Playgroud)

javascript asp.net

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

解析字符串时,DateTime.Parse会抛出异常

我有一些客户端代码以下列格式发送日期 "1/31/2013 11:34:28 AM";

我试图将其转换为DateTime对象

string dateRequest = "1/31/2013 11:34:28 AM";
DateTime dateTime = DateTime.Parse(dateRequest);
Run Code Online (Sandbox Code Playgroud)

这个抛出

字符串未被识别为有效的DateTime.

我该如何施展它?

c#

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