小编Roo*_*ian的帖子

使用LINQ的魔力 - 如何为匹配的每个条件调用委托?

我想做这样的事情:

List<string> list = new List<string>();
... put some data in it ...

list.CallActionForEachMatch(x=>x.StartsWith("a"), ()=> Console.WriteLine(x + " matches!"););

Syntax: CallActionForEachMatch(Criteria, Action)
Run Code Online (Sandbox Code Playgroud)

这怎么可能?:)

linq lambda

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

如何使用NHibernate的ICriteria进行分组,获取关联和T-SQL函数

我想创建以下T-SQL语句:

SELECT  SUM (sa.Amount) as 'SumAmount',
        SUM(sa.Cost) as 'SumCost', 
        gg.[Description] as 'Goodsgroup', Month(sa.[Date]) as 'Month' 
FROM SalesmanArticle sa
INNER JOIN Article a
    ON a.ArticleId = sa.ArticleId
INNER JOIN GoodsGroup gg
    ON gg.GoodsGroupId = a.GoodsGroupId
GROUP BY gg.[Description], Month(sa.[Date])
ORDER BY 'Month', 'Goodsgroup'
Run Code Online (Sandbox Code Playgroud)

这可能与NHibernates ICriteria有关吗?

我如何使用Month-T-SQL函数?

我必须手动加入或不的的ICriteria API知道,当我使用propetyName"SalesmanArticle.Article.Goodsgroup.Description"它加入了第二条和Goodsgroup?

编辑:

现在我在这里写了这段代码:

// typesafe properties
string article = typeof(Article).Name;
string goodsGroup = typeof(GoodsGroup).Name;
string salesmanArticle = typeof(SalesmanArticle).Name;

string amount = Reflector.GetPropertyName<SalesmanArticle>(x => x.Amount);
string cost = Reflector.GetPropertyName<SalesmanArticle>(x => x.Cost);
string description = string.Format("{0}.{1}", …
Run Code Online (Sandbox Code Playgroud)

t-sql nhibernate group-by icriteria

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

Windows窗体:如何扩展按钮?

如何扩展按钮?

我想要一个具有附加属性IsSwitchOffable的Button.

我是否必须编写额外的自定义控件?

编辑: 我希望该按钮可用作标准的WindowsFormsButton.

这包括我可以在设计时添加按钮!

c# winforms

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

((IEnumerable)source).OfType <T>()和作为IEnumerable <T>的源有什么区别

((IEnumerable)source).OfType<T>()和之间有什么区别source as IEnumerable<T>

对我来说,他们看起来很相似,但他们不是!

source是类型IEnumerable<T>,但它被装箱为object.

编辑

这是一些代码:

public class PagedList<T> : List<T>, IPagedList
{
    public PagedList(object source, int index, int pageSize, int totalCount)
    {
        if (source == null)
            throw new ArgumentNullException("The source is null!");


        // as IEnumerable<T> gives me only null

        IEnumerable<T> list = ((IEnumerable)source).OfType<T>();

        if (list == null)
            throw new ArgumentException(String.Format("The source is not of type {0}, the type is {1}", typeof(T).Name, source.GetType().Name));

        PagerInfo = new PagerInfo
                        {
                            TotalCount = totalCount,
                            PageSize …
Run Code Online (Sandbox Code Playgroud)

c# linq ienumerable boxing casting

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

ASP.NET MVC 3:IDepencyResolver正在尝试获取IControllerFactory的实现

尽管我注册了DefaultControllerFactory,为什么IDependecyResolver试图获取IControllerFactory的实例?

Global.asax中:

ControllerBuilder.Current.SetControllerFactory(typeof(DefaultControllerFactory));
DependencyResolver.SetResolver(new StructureMapDependencyResolver());
Run Code Online (Sandbox Code Playgroud)

解析器:

public class StructureMapDependencyResolver : IDependencyResolver
{
    public static Func<Type, object> GetServiceViaDepencencyCallback = t =>
    {
        throw new NotImplementedException(
            "StructureMapDependencyResolver is not configured!");
    };

    public static Func<Type, IEnumerable<object>> GetServicesViaDepencencyCallback = t =>
    {
        throw new NotImplementedException(
            "StructureMapDependencyResolver is not configured!");
    };

    public object GetService(Type serviceType)
    {
        return GetServiceViaDepencencyCallback(serviceType);
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        return GetServicesViaDepencencyCallback(serviceType);
    }
}
Run Code Online (Sandbox Code Playgroud)

抛出的错误:

StructureMap异常代码:202没有为PluginFamily System.Web.Mvc.IControllerFactory,System.Web.Mvc,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35定义的默认实例

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

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

Nuget:如何使用packages.config重新创建包目录

我已经使用Nuget安装了StructureMap.

我不想签入创建的目录.

如何使用packages.config?重新创建包目录?

我尝试Update-Package没有成功(没有任何事情,我第一次只有一点延迟).

我的packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="structuremap" version="2.6.3" />
</packages>
Run Code Online (Sandbox Code Playgroud)

c# nuget

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

FormClosing事件未调用MDI子表单

我打算在打开一个新的时候关闭一个公式.关闭公式时,我想在结束事件中处理一些特殊逻辑.但是,在FormClosing和Closing事件中,也不在抽象基类中或在给定的手动附加事件中都不会调用结束事件form_FormClosing.

当我通过单击x手动关闭表单时,所有事件都被解雇了.调用该Close()方法失败.

你有一些建议来解决我的问题吗?

的MdiParent:

private Form _currentForm;
private void ShowForm<T>() where T : Form
{
    if (_currentForm != null && !_currentForm.IsDisposed)
    {
        _currentForm.Hide();
        _currentForm.Close();
    }

    var form = MdiChildren.FirstOrDefault(f => f.GetType() == typeof(T));
    if (form == null)
    {
        form = _formFactory.CreateForm<T>();
        form.MdiParent = this;
        form.WindowState = FormWindowState.Maximized;
        form.FormClosing += form_FormClosing;
        _currentForm = form;
        MdiBackground.Hide();
        form.Show();
    }
    else
    {
        ActivateMdiChild(form);
        form.Activate();
    }
}

void form_FormClosing(object sender, FormClosingEventArgs e)
{
    // will not be called
}
Run Code Online (Sandbox Code Playgroud)

抽象通用mdi子形式:

public …
Run Code Online (Sandbox Code Playgroud)

c# mdi mdichild winforms

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

ASP.NET MVC Windows身份验证和DirectoryServices - 获取当前用户的邮件地址会引发InvalidCastException

我正在使用ASP.NET MVC 4和Windows身份验证.当我使用VisualStudio时,一切正常,但是当我部署我的网站时,会抛出异常.

var emailAddress = UserPrincipal.Current.EmailAddress;
Run Code Online (Sandbox Code Playgroud)

抛出:

无法将类型为"System.DirectoryServices.AccountManagement.GroupPrincipal"的对象强制转换为"System.DirectoryServices.AccountManagement.UserPrincipal".

其余的工作正常.用户可以进行身份​​验证,我可以获取用户名等.

编辑:

我在IIS上启用了Impersonation.现在我得到以下异常:

[DirectoryServicesCOMException(0x80072020):发生操作错误.] System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)781 System.DirectoryServices.DirectoryEntry.Bind()44 System.DirectoryServices.DirectoryEntry.get_AdsObject()42 System.DirectoryServices.PropertyValueCollection.PopulateList()29周
的System.DirectoryServices .PropertyValueCollection..ctor(DirectoryEntry entry,String propertyName)+119
System.DirectoryServices.PropertyCollection.get_Item(String propertyName)+163
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()+535649 System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit( )+51 System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()+ 141 System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx()+42 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context,Type principalType,Nullable`1 identityType, String identityValue,DateTime refDate)+27
System.DirectoryServices.Account Management.Principal.FindByIdentityWithType(PrincipalContext context,Type principalType,IdentityType identityType,String identityValue)+146
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context,IdentityType identityType,String identityValue)+44
System.DirectoryServices.AccountManagement.UserPrincipal.get_Current ()390 Jericho.MVC.HtmlHelperExtensions.GetUser(的HtmlHelper的HtmlHelper)在C:\发展\杰里科\ Jericho.MVC\HtmlHelperExtensions.cs:48

我能做什么?

c# asp.net-mvc directoryservices windows-authentication userprincipal

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

LINQ是否有可能通过LINQ表达式树获取没有返回类型的方法名称?

我知道可以检索属性名称或返回类型的方法.但是也可以通过LINQ表达式树获得没有返回类型的方法名称吗?

示例:string methodname = GetMethodname(x => x.GetUser());

--->结果:"GetUser"

linq tree expression get properties

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

单元测试中的UNIT是什么?它应该是什么?

单元是一个类还是一个组件(多个类)?

什么应该是单元测试?一个单位的粒度应该多少?

automated-tests unit-testing

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