在我的领域中,我有一些“处理器”类,它们包含大部分业务逻辑。使用带有默认约定的StructureMap,我将存储库注入这些类的各种IO(数据库,文件系统等)中。例如:
public interface IHelloWorldProcessor
{
string HelloWorld();
}
public class HelloWorldProcessor : IHelloWorldProcessor
{
private IDBRepository _dbRepository;
public HelloWorldProcessor(IDBRepository dbRepository)
{
_dbRepository = dbrepository;
}
public string HelloWorld(){ return _dbRepository.GetHelloWorld(); }
}
Run Code Online (Sandbox Code Playgroud)
现在,有一些存储库可供所有处理器使用,因此我做了一个基类,如下所示:
public class BaseProcessor
{
protected ICommonRepository _commonRepository;
public BaseProcessor(ICommonRepository commonRepository)
{
_commonRepository = commonRepository;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我的其他处理器继承自该处理器时,每个处理器都会收到一个编译器错误,说没有BaseProcessor的构造函数,该构造函数采用零参数。
有没有办法做我想在这里做的事情?就是说,是否要将公共依赖项注入到我的其他类可以使用的基类中,而不必将注入内容写入每个基类中?
我在一个客户端站点,他们有一个从SharePoint开始的应用程序,并正在慢慢迁移到一个非常自定义的ASP.NET应用程序.他们的一些数据元素仍然托管在SharePoint列表中,其中两个当前有问题的是一些"Notes"和"Tasks"(SharePoint设置中相当简单的数据元素,没有什么特别之处).我需要在ASP.NET中做的一件事就是为这些列表自动创建一些新项目并从代码中添加它们.
到目前为止,这很容易.我找到了现有的Web部件,它处理了这些项目的编辑,将调试器附加到它,跟踪它如何获取其值以及它添加到列表中的内容等.但是,添加到列表项中的一个字段是'n'很明显.在现有的Web部件UI中,该字段如下所示:
从本质上讲,它是从当前Windows域进入用户的字段.书籍图标打开一个弹出窗口,允许用户搜索名称等.在我当前的测试中,我在开发机器上以本地管理员身份运行.所以我只是在弹出窗口中查找"admin",并按预期填充"[machine name]\Administrator"字段.然后,在调试中,从字段中提取并输入到SharePoint列表项的值为"1",而不是名称或类似名称.
我假设"1"是本地管理员帐户的标识符.毕竟,这是有道理的.但我的问题是,如何在代码中获取当前登录用户的标识符?我找到了获取当前用户名的代码,但没有找到任何类型的数字(即使它是一个字符串)ID.
此外,这不仅仅发生在ASP.NET应用程序上下文中.还有一个用于笔记本电脑的WPF客户端应用程序,它将生成这些列表项并在连接时将它们同步回服务器.我目前正在假设客户端用户将使用服务器已知的正确域帐户登录.
我想这很简单,我只是没有偶然发现我需要的东西.
如何删除字符串中的第一个数字?如果我将这48个数字与','(逗号)分开,请说:
8,5,8,10,15,20,27,25,60,31,25,39,25,31,26,28,80,28,27,31,27,29,26,35,8,5,8,10,15,20,27,25,60,31,25,39,25,31,26,28,80,28,27,31,27,29,26,35
Run Code Online (Sandbox Code Playgroud)
如何从字符串中删除"8"?谢谢.
我浏览过网页,通过PHP文档等等,我已经看过了.
没有标准的解决方案似乎是一个荒谬的问题.如果您收到未知字符集,它有奇怪的字符(如英语引号),在那里将它们转换为UTF-8的标准方式?
我已经看到许多混乱的解决方案使用了大量的功能和检查,但它们都不会发挥作用.
有没有人提出自己的功能或总是有效的解决方案?
编辑
许多人回答说"这是不可解决的"或类似的东西.我现在明白了,但是没有人提供任何有效的解决方案,除此之外utf8_encode
非常有限.有什么方法可以解决这个问题?什么是最好的方法?
我确信这很简单,我很遗憾,但我似乎无法找到它.我在这里指定了一个简单的jqGrid:
$('#mainGrid').jqGrid({
datatype: 'local',
colNames: ['id', 'name'],
colModel: [
{ name: 'id', index: 'id', width: 100 },
{ name: 'name', index: 'name', width: 300 }
],
rowNum: 9999,
sortname: 'name',
viewrecords: true,
sortorder: 'asc',
data: [{"id":"924c18a4-cad6-4b6a-97ef-f9ca61614530","name":"Pathway 1"},{"id":"54897f40-49ab-4abd-acac-6047006c7cc7","name":"Pathway 2"},{"id":"61542c48-102f-4d8e-ba9f-c24c64a20d28","name":"Pathway 3"},{"id":"c4ca9575-7353-4c18-b38a-33b383fcd8b2","name":"Pathway 4"}]
});
Run Code Online (Sandbox Code Playgroud)
这正确加载.简单的概念证明.现在我尝试通过调用服务器资源来替换本地数据:
$('#mainGrid').jqGrid({
url: 'AJAXHandler.aspx',
datatype: 'json',
colNames: ['id', 'name'],
colModel: [
{ name: 'id', index: 'id', width: 100 },
{ name: 'name', index: 'name', width: 300 }
],
rowNum: 9999,
sortname: 'name',
viewrecords: true,
sortorder: 'asc'
});
Run Code Online (Sandbox Code Playgroud)
服务器资源返回相同的数据.但是网格没有加载数据.(至少,它没有显示任何记录.)我已经确认FireBug确实正在调用资源并返回预期的数据.
起初我认为应该将资源响应中的内容类型更改为 …
<form method="post">
<select name="users" id="users" onchange="showUser(this.value)" value="">
<option value="">Select a person:</option>
<option value="1" onchange="copy();">tcs</option>
<option value="2" onchange="copy();">wipro</option>
<option value="3" onchange="copy();">Hcl</option>
<option value="4" onchange="copy();">krystal kones</option>
</select>
</form>
Run Code Online (Sandbox Code Playgroud)
我有这个下拉我希望当值改变像tcs,wipro或hcl那么那个值应该在html标签中显示
我正在使用以下代码fadeOut
和fadeIn
页面上的内容div(jsfiddle here)...
HTML:
<ul>
<li><a id="indexNav" href="index.html">Home</a></li>
<li><a id="aboutNav" href="about.html">About</a></li>
</ul>
<div id="indexContent">
This is the main page content.
</div>
<div id="aboutContent">
This is the about page content.
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
ul {
float: left;
display: block;
margin-top: 50px;
margin-left: 0px;
}
ul li {
list-style: none;
display: block;
margin-top: 5px;
}
ul li a {
display: block;
height: 20px;
width: 50px;
margin: 0px;
background: #7d5900;
color: white;
text-decoration: none;
text-align: center;
}
div { …
Run Code Online (Sandbox Code Playgroud) 我的代码库中有一些相当复杂的实体框架查询,我决定将逻辑集中到模型中.基本上,描绘了一堆控制器,它们在表达式树中有大量查询和大量重复代码.因此,我取出了部分表达树并将它们移动到模型中,从而减少了重复次数.
例如,假设我经常需要获取名为Entity的模型,这些模型处于Not Deleted状态.在我的实体模型上,我有:
public static Func<Entity, bool> IsNotDeleted = e =>
e.Versions != null ?
e.Versions.OrderByDescending(v => v.VersionDate).FirstOrDefault() != null ?
e.Versions.OrderByDescending(v => v.VersionDate).First().ActivityType != VersionActivityType.Delete :
false :
false;
Run Code Online (Sandbox Code Playgroud)
(这是较小的示例之一,主要是在尝试检查数据之前检查有效数据.)
使用它看起来像:
var entities = EntityRepository.Entities.Where(Entity.IsNotDeleted).Where(...
Run Code Online (Sandbox Code Playgroud)
但是我发现,虽然有时候我想这是不会被删除的记录,其他时间我想要的记录被删除.要做到这一点,有没有办法从消费代码中反转逻辑?概念上类似于此的东西(显然不起作用):
var entities = EntityRepository.Entities.Where(!Entity.IsDeleted).Where(...
Run Code Online (Sandbox Code Playgroud)
我宁愿不在Func<>
物体上有两个,一个用于IsDeleted
,另一个IsNotDeleted
几乎相同.的Func<>
回报bool
,是否有语法把一个在当它调用它的逆.Where()
条款?
// snippet for syntax error\nconsole.log("hello stackoverflow!");\nconst test3;\ntest3=\'\xe2\x9d\x8c\'\nconsole.log(test3)\n\nvar name="me"\nconsole.log(name)
Run Code Online (Sandbox Code Playgroud)\r\n我知道 JS 是同步的并逐行执行代码,但为什么这里hello stackoverflow!
没有打印出来,因为错误在下一行。
另外,考虑下面的另一个片段
\n// snippet for typeError\nconsole.log(\'hello stackoverflow!\')\nconst test3 = \'\xe2\x9c\x85\'\ntest3=\'\xe2\x9d\x8c\'\nconsole.log(test3)\n\nvar name="me"\nconsole.log(name)
Run Code Online (Sandbox Code Playgroud)\r\n此代码片段打印“hello stackoverflow”。这与第一个片段的行为不同。
\n任何人都可以帮助我为什么会发生这种情况,谁在 JS 中识别出这些错误,以及这种情况是否发生在 JavaScript 中的内存分配之前?
\n我期望 console.log() 在这两种情况下都能打印出来,但这在第一个片段中没有发生。
\nforeach (int dirId in dirIds)
{
serieIds.AddRange((from serie in TableDataGrid.TargetBaseContext.Series
where serie.RepertoireId == dirId
select serie.SerieId).ToList());
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,VS建议使用var
而不是int
. int
如果只是需要的话,我们为什么要这么做呢?有没有办法告诉VS不要建议这样的修改?
我只是试图了解当我认为某件事比某件事int
更好时我是否错过了某事var
。
c# ×2
php ×2
asp.net ×1
constructor ×1
css ×1
func ×1
inheritance ×1
iso-8859-1 ×1
javascript ×1
jqgrid ×1
jquery ×1
jquery-ui ×1
linq ×1
sharepoint ×1
structuremap ×1
syntax-error ×1
typeerror ×1
utf-8 ×1
var ×1
wpf ×1