小编bev*_*qua的帖子

循环依赖和动态程序集加载

这是在AssemblyA中

namespace AssemblyA
{
    public class ClassA
    {
        public static void Main(string[] args)
        {
            ClassB b = new ClassB();
            Console.WriteLine(b.MultiplyTheSumByFactor(2, 3, 4));
            Console.ReadKey();
        }

        public int Multiply(int left, int right)
        {
            return left * right;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是在AssemblyB中

namespace AssemblyB
{
    public class ClassB
    {
        public int Sum(int left, int right)
        {
            return left + right;
        }

        public int MultiplyTheSumByFactor(int left, int right, int factor)
        {
            // ClassA a = new ClassA(); // can't reference AssemblyA
            int sum = …
Run Code Online (Sandbox Code Playgroud)

c# dll assemblies circular-dependency

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

在ASP.NET MVC 3中GZipping内容文件

我使用以下属性来装饰我的BaseController类.

public class OutputCompressAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        string encodingsAccepted = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
        if (string.IsNullOrEmpty(encodingsAccepted))
            return;

        encodingsAccepted = encodingsAccepted.ToLowerInvariant();
        HttpResponseBase response = filterContext.HttpContext.Response;

        if (encodingsAccepted.Contains("gzip"))
        {
            response.AppendHeader("Content-encoding", "gzip");
            response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
        }
        else if (encodingsAccepted.Contains("deflate"))
        {
            response.AppendHeader("Content-encoding", "deflate");
            response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,即使这对视图和每个操作结果都很好,该属性也不适用于/Content项目文件夹中的内容.我想知道我是如何做到这一点,以便文件Content夹中的文件使用控制器,或以某种方式绑定或钩住允许我将这些过滤器附加到响应头的东西.

c# asp.net-mvc gzip asp.net-mvc-3

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

缩小媒体查询?

我有一个完全有效的CSS样式表,它可以工作,并且可以识别查询,但是当我使用SquishIt缩小(并连接)样式表时,媒体查询似乎停止工作,我无法弄清楚原因.

这是缩小的CSS,美化:

html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video {
border:0;
outline:0;
font-size:100%;
font:inherit;
vertical-align:baseline;
background:transparent;
color:inherit;
margin:0;
padding:0;
}

article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section {
display:block;
}

body {
line-height:1;
word-wrap:break-word;
overflow-x:hidden;
font-family:"Helvetica Neue","Lucida Grande","Segoe UI",Arial,Helvetica,Verdana,sans-serif;
}

ol,ul {
list-style:none;
margin-bottom:1em;
margin-left:30px;
}

blockquote,q {
quotes:none;
}

blockquote:before,blockquote:after,q:before,q:after {
content:none;
}

:focus {
outline:0;
}

table {
border-collapse:collapse;
border-spacing:0;
}

th {
text-align:left;
}

.layout-section {
width:93.75%;
text-align:left;
margin:0 auto;
}

header#layout-header {
margin-bottom:20px;
padding:12px 0;
}

header#layout-header h1 {
display:inline-block;
font-family:Calibri,Candara,Segoe,"Segoe UI",Optima,Arial,Helvetica,sans-serif;
font-weight:700;
font-size:2.4em;
margin:0 auto;
}

section#layout-content …
Run Code Online (Sandbox Code Playgroud)

css minify squishit media-queries

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

为什么Angular不会忽略后续的$ digest调用?

以下必须是Angular.js开发人员在某些时候进行故障排除时最常见的错误.

错误:$申请已在进行中

有时,$scope.$apply完全不需要呼叫,删除它可以解决问题.有些时候,它可能是需要的,因此开发人员采用以下模式.

if(!$scope.$$phase) {
    $scope.$apply();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,为什么Angular只是在调用循环或调用循环时只检查$scope.$$phasereturn不执行任何操作,而不是抱怨并抛出一个如此难以追踪的错误.$digest$scope.$apply

Angular是否只是$$phase在任何方法的入口点检查自己,这些方法触发$digest并保存消费者不必经历麻烦?

$scope.$apply除了不需要的手表射击之外,是否有任何影响可能会导致错误的呼叫,这些检查$$phase会阻止?

为什么不$$phase检查默认值,而不是奇怪?

背景

我从升级角度1.2.11.2.6当页面加载,所以我不知道从哪里它源自该异常被抛出.因此,问题是,为什么我们甚至不得不追查这种模糊不清的错误而不知道我们的代码在哪里寻找它?

javascript internals angularjs

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

Dragula放入多个div

我使用Dragula在我的应用程序上实现了拖放,但是我需要设置它以便我可以将我的元素放到多个div中.

我尝试使用一个类来实现它,但它只是激活我的第一个div.

HTML:

    <div role="presentation" class="table table-striped">
        <div class="files"  id="upload-file"></div>
    </div>
    <div class="col-md-4">
        <div class="drag-container">Test 1</div>
        <div class="drag-container">Test 2</div>
        <div class="drag-container">Test 3</div>
    </div>
Run Code Online (Sandbox Code Playgroud)

JS调用Dragula:

dragula([document.querySelector('#upload-file'), document.querySelector('.drag-container')]);
Run Code Online (Sandbox Code Playgroud)

如何将te项目丢弃到多个div?

html javascript jquery drag-and-drop dragula

4
推荐指数
3
解决办法
5798
查看次数

在C#中Foreach结构奇怪的编译错误

namespace MyNamespace
{
    public struct MyStruct
    {
        public string MyString;
        public int MyInt;
        public bool MyBool;
    }

    public class MyClass
    {
        private List<MyStruct> MyPrivateVariable;

        public List<MyStruct> MyVariable
        {
            get
            {
                if (MyPrivateVariable == null)
                {
                    MyPrivateVariable = new List<MyStruct>();

                    MyPrivateVariable.Add(new MyStruct());
                    MyPrivateVariable.Add(new MyStruct());
                }

                return MyPrivateVariable;
            }
        }

        public void MyLoop()
        {
            foreach (MyStruct ms in MyVariable)
            {
                // Doesn't compile, but it works if you execute it through the Immediate window, or in Quickwatch
                ms.MyBool = false;

                // Compiles, …
Run Code Online (Sandbox Code Playgroud)

c# compiler-construction generics foreach struct

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

尝试抓点终于阻止?

最后使用有什么区别

void ReadFile(int index)
{
    // To run this code, substitute a valid path from your local machine
    string path = @"c:\users\public\test.txt";
    System.IO.StreamReader file = new System.IO.StreamReader(path);
    char[] buffer = new char[10];
    try
    {
        file.ReadBlock(buffer, index, buffer.Length);
    }
    catch (System.IO.IOException e)
    {
        Console.WriteLine("Error reading from {0}. 
           Message = {1}", path, e.Message);
    }
    finally
    {
        if (file != null)
        {
            file.Close();
        }
    }
    // Do something with buffer...
}
Run Code Online (Sandbox Code Playgroud)

而不是使用它?

void ReadFile(int index)
{
    // To run this code, substitute a …
Run Code Online (Sandbox Code Playgroud)

c# try-catch try-catch-finally

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

StringBuilder真的比Aggreggate快吗?

        string c = tmpArr[0].Aggregate(string.Empty, (current, m) => current + (m.Name + " "));

        StringBuilder sb = new StringBuilder();

        foreach (Mobile m in tmpArr[0])
            sb.Append(m.Name + " ");

        sb.ToString();
Run Code Online (Sandbox Code Playgroud)

哪两个更快?聚合肯定是更干净,但它是快速还是与做的一样

foreach(Mobile m in tmpArr[0])
    c += m.Name + " ";
Run Code Online (Sandbox Code Playgroud)

我真正想做的事情就是这样string.Join(",",tmpArr[0]),但我不想让它连接他们的ToString值,只是他们的名字,我怎么能做到最好?

我没有使用的问题string.Join是我实际上必须做这样的事情:

        string separator = "";
        StringBuilder sb = new StringBuilder();

        foreach (Mobile m in tmpArr[0])
        {
            separator = ", ";
            sb.Append(separator + m.Name);
        }
Run Code Online (Sandbox Code Playgroud)

c# string

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

C#数学问题:2的最小幂大于X?

    public int CalcBrackets(int teamCount)
    {
        int positions = 1;

        while (positions < teamCount)
            positions *= 2;

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

我想要的最小数字是2的幂,大于或等于teamCount.这真的是最好的方法吗?肯定看起来很可怕:(

c# math

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

如何在EF中进行批量更新

我在WCF服务上有以下方法:

    /// <summary>
    /// Receives the result of a request processing
    /// </summary>
    /// <param name="results">The resulting statuses for the processed account requests</param>
    /// <returns>Whether the response was successfully handled</returns>
    public bool SendRequestProcessingResult(IEnumerable<RequestProcessingResult> results)
    {
        foreach (var result in results)
        {
            // update entity
        }
    }
Run Code Online (Sandbox Code Playgroud)

有没有办法一次更新所有实体?我应该只添加每个更新SaveChanges吗?在EF 4.1中进行这种"大规模"更新的最佳方法是什么?

c# wcf entity-framework

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