我有一个回调机制,涉及的类是:
class App
{
void onEvent(const MyEvent& event);
void onEvent(const MyOtherEvent& event);
Connector connect;
}
class Connector
{
template <class T> void Subscribe(boost::function <void (const T&)> callback);
}
App::App()
{
connect.Subscribe<MyEvent>(&App::OnEvent<MyEvent>);
}
Run Code Online (Sandbox Code Playgroud)
首先这个代码不能编译,这是一个例子.
模板的使用使我的例子变得复杂,但是我把它们留下了,因为它影响了我的问题.我似乎确定我的订阅需要模板化,因为Connector类不知道它处理了多少事件类型.当我尝试创建一个:
boost::function f = &App::OnEvent,
Run Code Online (Sandbox Code Playgroud)
我尝试使用特化创建OnEvent作为模板函数,但似乎编译器将我的OnEvent函数视为重载而不是模板特化,否则如果我尝试将其明确声明为,则不会在命名空间错误中获取模板特化
template <> OnEvent(const MyEvent& e) ...
Run Code Online (Sandbox Code Playgroud)
我可以得到以下代码来编译:
boost::function <void (App*, const MyEvent&)> f = &App::OnEvent;
f(this, e);
Run Code Online (Sandbox Code Playgroud)
编译,运行和工作.
boost::function<void (const MyEvent&)> g = boost::bind(&App::OnEvent, this);
Run Code Online (Sandbox Code Playgroud)
才不是.我认为是因为我没有正确指定重载函数的地址.
现在已经向泰迪熊解释了这一切 - 我认为我的问题是"如何正确创建一个指向重载或模板化成员函数的函数指针并将此指针绑定到它?"
我当前的代码如下所示:
DateTime dateBegin = DateTime.ParseExact(begin, "MM/dd/yyyy", null);
DateTime dateEnd = DateTime.ParseExact(end, "MM/dd/yyyy", null);
Run Code Online (Sandbox Code Playgroud)
但只要"结束"中的日期不同,它就会抛出异常.我从DateTimePicker控件获取日期,因此日期可能看起来像"1/12/2010",然后它将抛出异常.我该如何避免这种情况?
谢谢.
我已经生成了一个类似的情节
figure; hold;
axis([0 10 0 10]);
fill([ 1 1 5 5], [5 1 1 5],'b')
Run Code Online (Sandbox Code Playgroud)
现在我想将这个情节作为一个矩阵,以便我可以用高斯过滤博客.谷歌我发现这个线程在MATLAB Central上用Rasterizing Plot to Image.我试过了,但我只能让它适用于线条或功能图.
你有什么想法?
我有一个Base64编码的对象与以下标题:
application/x-xfdl;content-encoding="asc-gzip"
Run Code Online (Sandbox Code Playgroud)
解码对象的最佳方法是什么?我需要剥离第一行吗?另外,如果我把它变成一个字节数组(byte []),我该怎么解压缩呢?
谢谢!
我想我最初错过了.通过说标题是
application/x-xfdl;content-encoding="asc-gzip"
Run Code Online (Sandbox Code Playgroud)
我的意思是这是文件的第一行.因此,为了使用Java或C#库来解码文件,是否需要删除此行?
如果是这样,剥离第一行的最简单方法是什么?
我需要为我的窗口应用程序(像powerpoint这样的编辑器)实现撤消/重做框架工作,应该遵循的最佳实践,如何处理我的对象的所有属性更改以及它在UI上的反射.
我想with在一些生产代码中使用Python 2.5中的语句.如果我发现任何问题(例如其他机器上的可用性/兼容性等),它是向后移植的吗?
这是代码
from __future__ import with_statement
Run Code Online (Sandbox Code Playgroud)
兼容Python 2.6?
我有一堆表格,其中输入了货币值,我希望他们能够输入"$ 1,234.56".默认情况下,模型绑定器不会将其解析为小数.
我想要做的是创建一个自定义模型绑定器继承DefaultModelBinder,重写BindProperty方法,检查属性描述符类型是否为十进制,如果是,只需从值中删除$和.
这是最好的方法吗?
码:
public class CustomModelBinder : DefaultModelBinder
{
protected override void BindProperty( ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor )
{
if( propertyDescriptor.PropertyType == typeof( decimal ) || propertyDescriptor.PropertyType == typeof( decimal? ) )
{
var newValue = Regex.Replace( bindingContext.ValueProvider[propertyDescriptor.Name].AttemptedValue, @"[$,]", "", RegexOptions.Compiled );
bindingContext.ValueProvider[propertyDescriptor.Name] = new ValueProviderResult( newValue, newValue, bindingContext.ValueProvider[propertyDescriptor.Name].Culture );
}
base.BindProperty( controllerContext, bindingContext, propertyDescriptor );
}
}
Run Code Online (Sandbox Code Playgroud)
更新
这就是我最终做的事情:
public class CustomModelBinder : DataAnnotationsModelBinder
{
protected override void BindProperty( ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor …Run Code Online (Sandbox Code Playgroud) 有没有人知道我如何映射具有相同子类型的两个多对多集合的实体.
"正常"关系将是....
tbl_Parent
col_Parent_ID
tbl_Parent_Child_Xref
col_Parent_ID
col_Child_ID
tbl_Child
col_Child_ID
Run Code Online (Sandbox Code Playgroud)
替代关系是......
tbl_Parent
col_Parent_ID
tbl_Include_ParentChild_Xref
col_Parent_ID
col_Child_ID
tbl_Child
col_Child_ID
Run Code Online (Sandbox Code Playgroud)
实体和映射看起来像这样......
public partial class ParentEntity : AuditableDataEntity<ParentEntity>
{
public virtual IList<ChildEntity> Children { get; set; }
public virtual IList<ChildEntity> IncludedChildren { get; set; }
}
public partial class ParentMap : IAutoMappingOverride<ParentEntity>
{
public void Override(AutoMapping<ParentEntity> mapping)
{
mapping.Table("tbl_Parent");
mapping.HasManyToMany(x => x.Children)
.Table("tbl_Parent_Child_Xref")
.ParentKeyColumn("col_Parent_ID")
.ChildKeyColumn("col_Child_ID")
.Inverse()
.Cascade.All();
mapping.HasManyToMany(x => x.IncludedChildren)
.Table("tbl_Include_ParentChild_Xref")
.ParentKeyColumn("col_Parent_ID")
.ChildKeyColumn("col_Child_ID")
.Inverse()
.Cascade.All();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是 "System.NotSupportedException:无法弄清楚多少属性'孩子'的另一面应该是什么."
我正在使用NHibernate 2.1.2,FluentNhibernate 1.0.
我在这个网站上使用EPiServer.不像asp:DataList,EPiServer:PAgeList没有AlternatingItemTemplate.
所以我需要创建一个计数器并在我的增加这个计数器<ItemTemplate>,然后使用模数返回很多css样式附加到文章/页面.
模数"代码" - 来自后面的代码:
return index % 2 == 0 ? "styleA" : "styleB";
Run Code Online (Sandbox Code Playgroud)
但我不能在计数器上加一个计数器来增加它<ItemTemplate>.
任何建议非常感谢!
更新
这是我的EPiServer页面列表控制器:
<EPiServer:PageList runat="server" id="pageList" SortDirection="Ascending" Count="4" OnDataBinding="pageList_OnDataBinding">
<HeaderTemplate>
<ul id="articleList1">
</HeaderTemplate>
<ItemTemplate>
<li>
<h2><a href="<%# Eval("LinkURL") %>" title="<%# Eval("PageName") %>"><EPiServer:Property id="Property1" PropertyName="PageName" runat="server" /></a></h2>
<div class="articleImage">
<%# ArticleImage(Container.CurrentPage)%>
</div>
<div class="introText">
<%# IntroText(Container.CurrentPage)%>
</div>
<div class="readMore floatRight"><a href="<%# Eval("LinkURL") %>" title="<%# Eval("PageName") %>">Les mer</a></div>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</EPiServer:PageList>
Run Code Online (Sandbox Code Playgroud)
答案
我决定使用jQuery比使用.NET更简单.这不是我的首选解决方案,但它确实有效.我使用的代码是这样的:
if (jQuery("#articleList1").length …Run Code Online (Sandbox Code Playgroud) c# ×3
c++ ×2
.net ×1
asp.net-mvc ×1
backport ×1
base64 ×1
boost ×1
css ×1
datetime ×1
filtering ×1
frameworks ×1
itemtemplate ×1
java ×1
matlab ×1
modulo ×1
nhibernate ×1
parsing ×1
plot ×1
python ×1
rasterizing ×1
repeater ×1
templates ×1
undo-redo ×1