小编ale*_*x.g的帖子

使用基本构造函数时,C#避免重复

有两个类,NodeBase和ContentSectionNode继承自抽象类NodeBase,我想知道是否有任何方法可以避免在ContentSectionNode构造函数中重复一段代码,同时也委托给基类构造函数.

抽象的NodeBase类ctors看起来像这样:

protected NodeBase(string tagType, string content)
  : this()
{
  TagType = tagType;
  Content = content;
}

protected NodeBase(Guid? parentId, int? internalParentId, string tagType, string content) 
  : this(tagType, content)
{
  ParentId = parentId;
  InternalParentId = internalParentId;
}
Run Code Online (Sandbox Code Playgroud)

ContentSectionNode类ctors看起来像这样:

public ContentSectionNode(Guid createdBy)
  : this()
{
  _createdBy = createdBy;
  _createdAt = DateTime.Now;
  UpdatedAt = _createdAt;
  UpdatedBy = _createdBy;
}

public ContentSectionNode(Guid createdBy, string tagType, string content)
  :base(tagType, content)
{
  _createdBy = createdBy;
  _createdAt = DateTime.Now;
  UpdatedAt = _createdAt;
  UpdatedBy = _createdBy;
} …
Run Code Online (Sandbox Code Playgroud)

.net c# architecture c#-5.0

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

使用ruby gsub和regexp更智能地替换字符

我正在尝试为某些文章标题创建类似行为的永久链接,我不想为永久链接添加新的数据库字段.所以我决定写一个帮助器来转换我的文章标题:

" O"focoasă"a pornit cruciada,împotrivabărbaţilorzgârciţi "to" o-focoasa-a-pornit-cruciada-impotriva-barbatilor-zgarciti ".

虽然我想出了如何用连字符替换空格并删除其他特殊字符(除了 - )使用:

title.gsub(/\s/, "-").gsub(/[^\w-]/, '').downcase
Run Code Online (Sandbox Code Playgroud)

我想知道是否有任何其他方法可以从一个.gsub方法调用替换一个特定的其他字符的字符,所以我不必为所有的链接title.gsub("ă","a")方法我本地化的UTF-8特殊字符.

我正在考虑用所有特殊字符和它们的对应物构建一个哈希,但我还没有弄清楚如何使用regexp的变量.

我在寻找的是:

title.gsub(/\s/, "-").gsub(*replace character goes here*).gsub(/[^\w-]/, '').downcase
Run Code Online (Sandbox Code Playgroud)

谢谢!

ruby string replace ruby-on-rails gsub

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

在sitecore中将数据从一个子布局发送到另一个子布局

我很难在Sitecore 7中构建过滤系统.

我在页面的同一级别有2个子布局.

子布局A是一个侧边栏,其中包含一个复选框列表,并且具有使用所选值填充列表的事件.子布局B显示一组项目.

我想做的是,将填充的列表从子布局A发送到子布局B,以便根据用户选择的内容过滤项目列表.我能够通过Session传递数据来做到这一点,但这不是处理数据的最佳方式.

我已经尝试为子布局A定义一个属性并在那里加载列表,但是我无法从子布局B获得子布局A的确切实例以便读取填充的属性.此外,尝试Page.FindControl("IdOfSomeElementFromSublayoutA")始终在Sublayout B中返回null.尽管我已将Page转换为包含Sublayouts的.aspx页面.

我正在使用Sitecore 7 Update 2.

非常感谢你的时间.

c# asp.net sitecore sitecore7

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

标签 统计

c# ×2

.net ×1

architecture ×1

asp.net ×1

c#-5.0 ×1

gsub ×1

replace ×1

ruby ×1

ruby-on-rails ×1

sitecore ×1

sitecore7 ×1

string ×1