小编mat*_*ieu的帖子

如何确定web.config中的编译debug ="true"

我在这里画一个空白的东西应该很简单......

我想做的事情如下:

    <my:control runat="server" id="myid" Visible="<%= (is compilation debug mode?) %>" />
Run Code Online (Sandbox Code Playgroud)

c# asp.net debugging

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

什么是更好的,许多小型组件,或一个大型组件?

一切都在标题:)

目前,我们有一个VS2005解决方案,包含20多个项目.喜欢

MySolution
MySolution.Modules.Foo
MySolution.Modules.Bar
[insert many here]
MySolution.Modules.Baz
Run Code Online (Sandbox Code Playgroud)

在一个项目中"合并"MySolution.Modules.*会有害吗?将保留所有名称空间,因此这里没有问题.

但有什么我没想过的吗?

注意:目前,不能有循环引用:如果MySolution.Modules.Foo引用MySolution.Modules.Bar,MySolution.Modules.Bar不能引用MySolution.Modules.Foo.所以我们必须小心不要创造一些.

.net

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

动态,linq和Select()

考虑以下(无意义,但仅用于说明目的)测试类:

public class Test
{
    public IEnumerable<string> ToEnumerableStrsWontCompile(IEnumerable<dynamic> t)
    {
        return t.Select(x => ToStr(x));
    }

    public IEnumerable<string> ToEnumerableStrsWillCompile(IEnumerable<dynamic> t)
    {
        var res = new List<string>();

        foreach (var d in t)
        {
            res.Add(ToStr(d));
        }

        return res;
    }

    public string ToStr(dynamic d)
    {
        return new string(d.GetType());
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么不编译时出现以下错误t.Select(x => ToStr(x))

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<dynamic>' 
to 'System.Collections.Generic.IEnumerable<string>'. An explicit conversion 
exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)

第二种方法没有错误.

c# linq dynamic c#-4.0

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

NHibernate:映射到字段或属性?

创建映射文件时,是否将属性映射到字段或属性:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Foo" namespace="Foo.Bar" >
  <class name="Foo" table="FOOS" batch-size="100">
    [...]
    <property name="FooProperty1" access="field.camelcase" column="FOO_1" type="string" length="50" />
    <property name="FooProperty2" column="FOO_2" type="string" length="50" />
    [...]
  </class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)

当然,请解释原因:)

通常,我映射到属性,但映射到字段可以在属性的getter/setter中放置一些"逻辑".

映射到字段是否"糟糕"?有最好的做法吗?

.net nhibernate

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

从C#代码中避免在MSSQL Server上注入SQL的算法?

什么是避免在C#.net平台上进行SQL注入的最佳方法.

如果您有任何问题,请发布C#实现.

.net c# sql-server security

10
推荐指数
2
解决办法
8370
查看次数

通用IEqualityComparer <T>和GetHashCode

对于实现大量的IEqualityComparers有些懒惰,并且考虑到我无法轻松编辑被比较对象的类实现,我使用了以下内容,意味着与Distinct()和Except()扩展方法一起使用.:

public class GenericEqualityComparer<T> : IEqualityComparer<T>
{
    Func<T, T, bool> compareFunction;
    Func<T, int> hashFunction;

    public GenericEqualityComparer(Func<T, T, bool> compareFunction, Func<T, int> hashFunction)
    {
        this.compareFunction = compareFunction;
        this.hashFunction = hashFunction;
    }

    public bool Equals(T x, T y)
    {
        return compareFunction(x, y);
    }

    public int GetHashCode(T obj)
    {
        return hashFunction(obj);
    }
}
Run Code Online (Sandbox Code Playgroud)

看起来不错,但每次真的需要一个哈希函数?我知道哈希码用于将对象放入存储桶中.不同的桶,对象不相等,并且不调用相等.

如果GetHashCode返回相同的值,则调用equals.(来自:为什么在重写Equals方法时重写GetHashCode很重要?)

那么可能出现什么问题,例如(我听到很多程序员惊恐地尖叫),GetHashCode返回一个常量,强制调用Equal?

c# gethashcode

10
推荐指数
2
解决办法
6876
查看次数

流畅的nhibernate约定:设置多态模式

如果有一个连接子类,是否可以创建一个简单的约定来修改类的多态模式?

这样做:

public class EntityMap : ClassMap<EntityBase>
{
    public EntityMap()
    {
        Polymorphism.Explicit();
    }
}
Run Code Online (Sandbox Code Playgroud)

但在一个公约内.使用IClassConvention不起作用,因为Polymorphism属性是只读的:

public class TestConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        // read only property !
        instance.Polymorphism = Polymorphism.Explicit;
    }
}
Run Code Online (Sandbox Code Playgroud)

fluent-nhibernate

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

ASP.NET性能:没有预编译的Web应用程序

目前我们正在使用Web应用程序项目,因此我们可以通过编译获得收益.但据我所知,aspx页面仍在第一页上编译.那么预编译会带来明显的性能提升吗?(第一次被击中).

什么类型的网站(点击数/秒,用户数)将从中受益?

asp.net performance

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

绑定到Date() - 对象时如何格式化input [time]的值

我将变量绑定到time类型的输入字段,但显示的格式是错误的.

它显示的时间如下:08:54:30,088 我真正需要的是这样的格式:08:54.

我尝试使用filter(value={{ datetime.date | date : 'HH:mm' }})设置输入字段的值,但我的编辑说我这样做的方式是错误的.有任何想法吗?

这里的compltete代码:

HTML

 <input id="rep_time" class="form-control" type="time" ng-model="datetime.time" value={{ datetime.date | date : 'HH:mm' }}>
Run Code Online (Sandbox Code Playgroud)

JS

 app.controller( 'newCtrl', function( $scope ) {  

     $scope.datetime = {
         date: new Date(),
         time: new Date()
       };
 } );
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

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

WPF列表框分组,没有组的项目

是否可以将一个列表框(或具有SelectedItem的其他控件)绑定到ICollectionView,显示如下所示的项:

  • Item1Name
  • Item2Name
  • ParentName1
    • Item3Name
    • Item4Name
  • ParentName2
    • Item5Name
    • Item6Name

该类用作CollectionViewSource视图的源:

public class Item
{
    public string Name { get; set; }
    public string Parent { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

Item1和Item2将ParentName属性设置为null,Item3和Item4将"ParentName1"设置为ParentName属性,依此类推.

我非常喜欢列表框方法,因为只能选择项目,不能选择组.但我可能走错了路.

wpf

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

StructureMap,扫描组件和范围

如何在扫描程序集时添加一些作用域?谷歌似乎对"结构图扫描缓存"感到满意:/ /

ObjectFactory.Configure(registry =>
{
    registry.Scan(x =>
    {
        x.AssemblyContainingType(typeof(IRepository<>));
        x.With<DefaultConventionScanner>();
    });
}
Run Code Online (Sandbox Code Playgroud)

.net c# structuremap

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

是否有任何方法可以在C#ctrl + alt + del中禁用注销,锁定和任务管理器

在运行我的窗口应用程序.如果用户按ctrl + alt + del我需要禁用这些按钮..有任何方法

c# winforms

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

使用CommandParameter在树视图项上进行键绑定

我正在尝试使用带有KeyBinding的TreeViewItem和MenuContext来执行位于我的ViewModel上的命令.

目前,使用上下文菜单,在正确的ViewModel实例上调用该命令.但是,当我选择TreeViewItem并按"C"键时,将在"根"ViewModel上调用该命令.

我也尝试扩展KeyBinding类(Keybinding一个RelayCommand),没有运气.

也许我会走错路:我只想显示正确的MessageBox,如果我使用上下文菜单或键.

名为WpfTest的WPF项目的代码示例.

MainWindow.xaml

<Window x:Class="WpfTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="clr-namespace:WpfTest"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <TreeView ItemsSource="{Binding}">
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Child}" DataType="{x:Type vm:ViewModel}">
                    <TextBlock Text="{Binding Name}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="ContextMenu">
                        <Setter.Value>
                            <ContextMenu>
                                <MenuItem Header="{Binding Name}" Command="{Binding SomeCommand}" CommandParameter="{Binding}"/>
                            </ContextMenu>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="vm:MyAttached.InputBindings">
                        <Setter.Value>
                            <InputBindingCollection>
                                <KeyBinding Key="C" Command="{Binding SomeCommand}" CommandParameter="{Binding}"/>
                            </InputBindingCollection>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

MainWindow.xaml.cs:

namespace WpfTest
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Windows;
    using System.Windows.Input;

    public …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml mvvm

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