小编Rui*_*mba的帖子

如何从配置文件加载统一设置?

我有一个统一配置文件(App.config)如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Unity.Configuration"/>
  </configSections>
  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <alias alias="IProductService" type="UnityExample.Service.IProductService, UnityExample.Service" />
    <containers>
      <container name="Service">
        <register type="IProductService" mapTo="ProductService"/>
      </container>
    </containers>
  </unity>
</configuration>
Run Code Online (Sandbox Code Playgroud)

现在我想从上面加载配置file

var container = new UnityContainer().LoadConfiguration("Service");
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

[ArgumentNullException:值不能为空。参数名称:section] Microsoft.Practices.Unity.Configuration.UnityContainerExtensions.LoadConfiguration(IUnityContainer容器,UnityConfigurationSection部分,String containerName)

.net c# dependency-injection unity-container

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

C#和Java应该是否包含彼此的语法?

我已经从C#跳到Java了很多,两者之间的"差异"有点令人烦恼.

是否有可能编写一组可以合并两种语言语法的扩展/插件.

我正在谈论添加IDE支持或使用语言结构,例如:

  1. 等效地对待这两行:

    System.out.println("Blah");

    Console.out.writeline("Blah");

  2. 自动发现,当你键入小号特林你的意思是小号特林

  3. 识别常见的API调用并在后台进行翻译.

最终目标是能够编写java/C#程序并在编译时选择您要定位的VM/Runtime.

如果你能做到这一点会是个好主意吗?

如果不是为什么不呢?

这两种语言非常相似,在某些方面很痛苦,但在其他方面它们确实不同.

我已经看到Code会将C#项目转换为Java,我假设可能有相反的情况,我建议的是中间地带,所以我们都可以"相处".

.net c# java language-agnostic

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

如何覆盖泛型方法?(C#)

我正在创建一个名为TetraQueue继承System.Collections.Generic.Queue类重写Dequeue方法的类,这里是代码:

public class TetraQueue : Queue<Tetrablock>
{
   public override Tetrablock Dequeue()
   {
       return base.Dequeue();
   }
 }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译这个时,我得到:

错误TetraQueue.Dequeue()':找不到合适的方法来覆盖TetraQueue.cs

提前致谢.

我怎么知道方法是否是虚拟的(避免这种情况)?

.net c# collections

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

"集合初始化程序的最佳重载Add方法'System.Collections.Generic.List.Add(System.Guid)'具有一些无效参数"

List<PageInfo> subPages = new List<PageInfo>();
// ...
// some code to populate subPages here...
// ...
List<Guid> subPageGuids = new List<Guid> {from x in subPages select x.Id}; //doesn't work
Run Code Online (Sandbox Code Playgroud)

PageInfo有一个ID字段,类型为Guid.所以x.Id是一个System.Guid.

上面第二行代码不起作用......我收到错误:

集合初始化程序的最佳重载Add方法'System.Collections.Generic.List.Add(System.Guid)'有一些无效的参数

参数'1':无法从'System.Collections.Generic.IEnumerable'转换为'System.Guid'

我只用C#编写了大约一个星期,但我之前做过类似的模式,从来没有遇到过这个问题.

.net c# linq

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

在文档准备好之前隐藏元素?

我有一个需要默认隐藏的div.然后可以通过按钮切换:

    <script type="text/javascript">
        function toggle() {
            text = document.getElementById('add_view');
            var isHidden = text.style.display == 'none';
            text.style.display = isHidden ? 'block' : 'none';
        }


        $(document).ready
    (

              function () {
                  toggle();
                  $("#add_view, #btnToggle").click(function (e) {
                      e.stopPropagation();
                  });
                  $(document).click(function () {
                      toggle();
                  });
              }
    );


</script>
Run Code Online (Sandbox Code Playgroud)

它工作正常.唯一的问题是,当我刷新页面时,我会在隐藏之前暂时看到div.

我该怎么做才能防止这种情况发生?

谢谢

html javascript c# asp.net jquery

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

wcf单向非阻塞操作

我需要这样的场景:客户端向服务器发送消息,而不是等待响应,如果消息发送正确,则不关心.

using(host.RemoteService client = new host.RemoteService())
{
client.Open();

cliend.SendMessage("msg");
}
Run Code Online (Sandbox Code Playgroud)

在防火墙打开或没有连接到Internet的情况下,客户端在"SendMessage"处死亡.我的意思是程序停止响应.我希望程序不关心结果.我的意思是如果没有连接,我希望程序更进一步,省略"SendMessage"或者像那样.

我该怎么办,有非阻塞方法的解决方案吗?

.net c# wcf web-services wcf-endpoint

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

验证两个属性的唯一性

我有一个名为"汽车"的模型

我想知道如何在模型中声明,这样当两个属性相互匹配时,只能存在一条记录.例如,在汽车模型中

:owner_id, :driver_id
Run Code Online (Sandbox Code Playgroud)

假设存在一条记录:

:id => "1", :owner_id => "22", :driver_id => "23", :state => "parked"
Run Code Online (Sandbox Code Playgroud)

如果我尝试创建另一条记录,它也具有相同owner_iddriver_id相互匹配的记录,则记录将无法创建自己.我正在尝试建立一个关系模型,在匹配时为每个所有者和驱动程序创建一条记录.

activerecord ruby-on-rails rails-activerecord

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

练习web.config并收到错误

当我复制并粘贴以下代码时,我正在web.config此处实现文件:

<configSections>
  <section name ="ProductSection" type ="<ProductSection" />
</configSections>

<ProductSection>
<gridSettings title ="Latest Products" count ="20"></gridSettings>
<color background="FFFFCC" foreground="FFFFFF"></color>
</ProductSection>
Run Code Online (Sandbox Code Playgroud)

我有几个错误,如:

  • 标签未在第二行关闭.
  • </section> 不见了.
  • 命名空间'section'不能包含子元素.

如何删除这些错误并顺利运行它.

.net c# asp.net

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

C#Distinct以逗号分隔的值不起作用

我试图从逗号分隔的字符串中删除重复的值,并且结果不一致.例如,

如果我通过:

STA27,STA27,STA27B,STA27A,STA27B,

我明白了:

STA27,STA27,STA27B,STA27A,

或者,如果我通过:

STA24,STA24,STA24,STA24,

我明白了:

STA24,STA24,

我已经尝试了几种方法来最终摆脱逗号,但似乎没有任何工作.我不明白为什么Distinct也不起作用.我认为它与字符串终止的方式有关,但在第一个例子中,我得到前两个条目的重复,所以它似乎不是一个位置问题.

有什么想法吗?

 public string FindDistinctBeats(String Beats)
    // Accept comma-separated string, return distinct values
    {
        string result = string.Empty;

        try
        {
            result = string.Join(",", Beats.Split(',').Distinct().ToArray());
            result = result.TrimEnd(',');

            if (String.IsNullOrEmpty(result))
            {
                return result;
            }
            else
            {
                return result.TrimEnd(result[result.Length - 1]);
            }

        }
        catch (Exception e)
        {
            return e.ToString();
        }
    }
Run Code Online (Sandbox Code Playgroud)

.net c# string distinct-values

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

使用公共接口和内部类型参数的泛型

我有以下情况:

// A public interface of some kind   
public interface IMyInterface {   
    int Something { get; set; }   
}   

// An internal class that implements the public interface.   
// Despite the internal/public mismatch, this works.   
internal class MyInternalConcrete : IMyInterface {   
    public int Something { get; set; }   
}   

// A generic class with an interface-restricted type parameter.
// Note that the constraint on T uses the *public* interface.
// The instance is *never* exposed as a public, or even …
Run Code Online (Sandbox Code Playgroud)

.net c# generics interface

0
推荐指数
2
解决办法
3383
查看次数