小编Jam*_*ack的帖子

使用StructureMap注入工厂方法

我正在使用ASP.NET成员资格提供程序包装器,以便我可以使用更多松散耦合的库.我想使用StructureMap来提供真正的IoC,但是我在使用User-to-Profile工厂对象进行配置时遇到了麻烦,我正在使用它来在用户的上下文中实例化配置文件.这是相关的细节,首先是库中的接口和包装器:

// From ASP.Net MVC Membership Starter Kit
public interface IProfileService
{
    object this[string propertyName] { get; set; }
    void SetPropertyValue(string propertyName, object propertyValue);
    object GetPropertyValue(string propertyName);
    void Save();
}

public class AspNetProfileBaseWrapper : IProfileService
{
    public AspNetProfileBaseWrapper(string email) {}

    // ...
}
Run Code Online (Sandbox Code Playgroud)

接下来,用于与配置文件数据中的特定属性进行交互的存储库:

class UserDataRepository : IUserDataRepository
{
    Func<MembershipUser, IProfileService> _profileServiceFactory;

    // takes the factory as a ctor param 
            // to configure it to the context of the given user
    public UserDataRepository(
              Func<MembershipUser, IProfileService> profileServiceFactory) …
Run Code Online (Sandbox Code Playgroud)

.net c# structuremap

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

自定义EditorTemplate未在MVC4中用于DataType.Date

我正在使用Microsoft说明将MVC3应用程序升级到MVC4 .一切都进行得相当顺利 - 除了我的几个日期模型属性现在渲染方式不同.例如,其中一个属性在viewmodel中定义如下:

[Required(ErrorMessage = "Required")]
[DataType(DataType.Date)]
[RegularExpression(@"([1-9]|0[1-9]|1[012])...",
    ErrorMessage = "Format is mm/dd/yyyy")]
[FormatHint("mm/dd/yyyy")]
[InputSize("small")]
public string Date { get; set; }
Run Code Online (Sandbox Code Playgroud)

在升级到MVC4之前,这将通过调用来呈现,@Html.EditorFor(m => m.Date)这将使用自定义的EditorTemplate - String.cshtml模板(因为它是一个字符串!).我有一些格式化html的自定义数据注释,因此它在客户端使用了字段布局,jQueryUI和twitter Bootstrap.验证是通过jquery验证完成的,不引人注目.无论如何,这是它以前呈现的方式:

日期编辑

现在我正在使用MVC4,String.cshtml不再为此属性调用编辑器模板.它呈现如下(在Chrome中使用HTML5编辑器的东西,我假设):

日期编辑mvc4

input元素看起来几乎相同 - 所有的jQuery验证位都在那里 - 唯一的区别似乎是type属性现在type="date",之前的位置type="text".

我想继续使用String.cshtmlEditorTemplate来获取此数据类型.我想可能有一个数据注释,我可以放在ViewModel属性上为其提供TemplateHint @Html.EditorFor(...).如果不是这样,我想知道我可以编写的自定义EditorTemplate来劫持MVC4的格式(我已经尝试过了DateTime.cshtml- 它也没有被调用).如果不是其中任何一个,那么我愿意接受如何获得我以前的属性渲染的建议.

asp.net-mvc asp.net-mvc-4

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

strtok不接受:char*str

当使用char*str作为第一个参数(不是分隔符字符串)时,strtok将无法正常工作.

它是否与在该表示法中分配字符串的区域有关?(据我所知,这是一个只读区域).

提前致谢

例:

//char* str ="- This, a sample string.";   // <---doesn't work
char str[] ="- This, a sample string.";   // <---works
char delims[] = " ";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str,delims);
while (pch != NULL)
{
  printf ("%s\n",pch);
  pch = strtok (NULL, delims);
}
return 0;
Run Code Online (Sandbox Code Playgroud)

c string strtok

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

是否有任何内置API可用于解决复杂的数学问题,如集成和区分

我需要实现一个具有密集数学计算的算法.java中是否已经支持此了?或者是否有任何第三方供应商提供此支持?

java java-api

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

我应该在C#中为我的项目使用WPF或Windows Forms Application吗?

  1. 我正在开发基于客户端 - 服务器的应用程序,其中客户端应用程序将访问服务器数据库以存储计费信 它还将有报告生成设施.Windows Forms在文档打印方面很好,我在WPF中看不到这样的工具或控件.如果我错了,请纠正我.
  2. 我想要数据库安全性,我应该使用哪个DB,SQL Server,MySQL或Oracle.我想使用免费的数据库,但安全是我的首要任务.
  3. 请建议如何在C#中实现具有多个客户端的客户端 - 服务器架构?

谢谢极客!!!

c# wpf client-server winforms

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

如何将变量从一个PowerShell脚本加载到另一个?

我有一个正在调用其他几个脚本的主脚本,我需要将其他脚本中的变量加载到主脚本中,以便可以将它们转储到html文件中。我尝试点调用我正在调用的脚本,但是那没有用,或者我做错了。任何帮助,将不胜感激。

脚本的示例部分:

.\get-cluster.ps1

$MyReport += Get-CustomHeader "Clusters not in compliance : $($CapacityInfo.count) ($MyReport += Get-HTMLTable $capacityinfo
$MyReport += Get-CustomHeaderClose
Run Code Online (Sandbox Code Playgroud)

变量$capacityinfo存在于get-cluster.ps1脚本中

powershell

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

陷入困境

while (true)
{
    //read in the file
    StreamReader convert = new StreamReader("../../convert.txt");

    //define variables
    string line = convert.ReadLine();
    double conversion;
    int numberIn;
    double conversionFactor;

    //ask for the conversion information
    Console.WriteLine("Enter the conversion in the form (Amount, Convert from, Convert to)");
    String inputMeasurement = Console.ReadLine();
    string[] inputMeasurementArray = inputMeasurement.Split(',');


    //loop through the lines looking for a match
    while (line != null)
    {
        string[] fileMeasurementArray = line.Split(',');
        if (fileMeasurementArray[0] == inputMeasurementArray[1])
        {
            if (fileMeasurementArray[1] == inputMeasurementArray[2])
            {
                Console.WriteLine("The conversion factor for {0} …
Run Code Online (Sandbox Code Playgroud)

c#

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

在c#中,一个类的数组和两个连接的实例为什么呢?

我写了下面的代码:

1. MyClass[] origArr=new MyClass[3];  
2. MyClass[] arr1;
3. // filled the array with objects and did some work on it .  
4. dgv_1.DataSource=origArr;  
5. 
6. // Here is the problem :
7. arr1=origArr;  
8. // do some work on arr1 ...  
9. dgv_2.DataSource=arr1;  
Run Code Online (Sandbox Code Playgroud)

出于某种原因,当'arr1'中的数据发生变化时,'origArr'中的数据发生了变化......
我认为这可能是因为'origArr'和'arr1'是指向同一个对象的指针,所以我将第7行更改为:

7. origArr.CopyTo(arr1,0);
Run Code Online (Sandbox Code Playgroud)

但它不起作用......我该怎么做才能使指针指向不同的对象?

c# class

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

Jquery检查控件是否为空并显示!="none",为什么不起作用?

以下if语句.

emptyFields = false;
   $(".ClassNanme").each(function() {
      if(($.trim($(this).val()) == "") &amp;&amp; ($(this).css('display') != 'none' ) {
        emptyFields = true;
    return false; // break out of the each-loop
      }
   });
Run Code Online (Sandbox Code Playgroud)

但是不起作用,我不知道如何使用jquery检查css属性显示是否设置为none.

当其中一个对象为空或其css属性显示未设置为none时,应选择此if语句.

检查值是否为空是有效的,我所坚持的是检查对象是否隐藏(或显示:无).

谢谢.

塞萨尔.

css jquery

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