我在这里画一个空白的东西应该很简单......
我想做的事情如下:
<my:control runat="server" id="myid" Visible="<%= (is compilation debug mode?) %>" />
Run Code Online (Sandbox Code Playgroud) 一切都在标题:)
目前,我们有一个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.所以我们必须小心不要创造一些.
考虑以下(无意义,但仅用于说明目的)测试类:
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)
第二种方法没有错误.
创建映射文件时,是否将属性映射到字段或属性:
<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中放置一些"逻辑".
映射到字段是否"糟糕"?有最好的做法吗?
什么是避免在C#.net平台上进行SQL注入的最佳方法.
如果您有任何问题,请发布C#实现.
对于实现大量的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?
如果有一个连接子类,是否可以创建一个简单的约定来修改类的多态模式?
这样做:
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) 目前我们正在使用Web应用程序项目,因此我们可以通过编译获得收益.但据我所知,aspx页面仍在第一页上编译.那么预编译会带来明显的性能提升吗?(第一次被击中).
什么类型的网站(点击数/秒,用户数)将从中受益?
我将变量绑定到time类型的输入字段,但显示的格式是错误的.
它显示的时间如下:08:54:30,088
我真正需要的是这样的格式:08:54.
我尝试使用filter(value={{ datetime.date | date : 'HH:mm' }})设置输入字段的值,但我的编辑说我这样做的方式是错误的.有任何想法吗?
这里的compltete代码:
<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)
app.controller( 'newCtrl', function( $scope ) {
$scope.datetime = {
date: new Date(),
time: new Date()
};
} );
Run Code Online (Sandbox Code Playgroud) 是否可以将一个列表框(或具有SelectedItem的其他控件)绑定到ICollectionView,显示如下所示的项:
该类用作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属性,依此类推.
我非常喜欢列表框方法,因为只能选择项目,不能选择组.但我可能走错了路.
如何在扫描程序集时添加一些作用域?谷歌似乎对"结构图扫描缓存"感到满意:/ /
ObjectFactory.Configure(registry =>
{
registry.Scan(x =>
{
x.AssemblyContainingType(typeof(IRepository<>));
x.With<DefaultConventionScanner>();
});
}
Run Code Online (Sandbox Code Playgroud) 在运行我的窗口应用程序.如果用户按ctrl + alt + del我需要禁用这些按钮..有任何方法
我正在尝试使用带有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) c# ×7
.net ×5
asp.net ×2
wpf ×2
angularjs ×1
c#-4.0 ×1
debugging ×1
dynamic ×1
gethashcode ×1
javascript ×1
linq ×1
mvvm ×1
nhibernate ×1
performance ×1
security ×1
sql-server ×1
structuremap ×1
winforms ×1
xaml ×1