我一直在使用Windsor IoC Container作为基于Web的应用程序,以解决应用程序应该使用的数据访问层实现.
Web应用程序的UI将由页面组成,每个页面由称为portlet的小单元组成.(它们的概念有点类似于小部件.)这些所谓的portlet基本上是Web控件,可以在运行时为每个页面进行静态配置.
该应用程序将附带一些内置的,但我希望能够轻松扩展它.
我发现这个机制正是MEF的构建方式.所以我决定以这样的方式实现系统,即它使用MEF发现portlet.然后,我意识到它也可以做我目前使用温莎的东西,所以我决定放弃温莎而不是MEF.
显然,我将不得不使用DirectoryCatalog,它会扫描应用程序bin文件夹中的.dll并返回我需要的所有内容.
我在StackOverflow中阅读了一些有关MEF的教程,示例和所有问题.我认为使用MEF最简单的方法是通过Glenn Block在他的教程中提到的PartInitializer,但我意识到它不在MEF中.实际上,它是在我从CodePlex下载的代码中,但是在一个单独的程序集中,并且只在源代码中,而不是以二进制形式.(这是否意味着它不是MEF的一部分?或者将它放到一个单独的项目中有什么意义?)然后,我意识到它适用于Silverlight,所以它并没有真正帮助我.(或者我应该只针对.NET 3.5进行编译,还是将其包含在我的项目中,我很高兴?)
所以现在我遇到了以下问题:我应该将CompositionContainer放在我的应用程序中?
还有一件事我想考虑一下:我应该在应用程序的生命周期中只使用一个CompositionContainer,或者我最好在每次需要时创建一个容器?
我需要在Google地图上只打开一个InfoWindow.在打开新的InfoWindows之前,我需要关闭所有其他InfoWindows.
有人能告诉我怎么做吗?
我有一个从列表生成的下拉选择器,并希望筛选选项以删除重复的条目.我要过滤...
<select name="company">
<option "1">Microsoft</option>
<option "2">Microsoft</option>
<option "3">Microsoft</option>
<option "4">Microsoft</option>
<option "5">Apple</option>
<option "6">Apple</option>
<option "7">Google</option>
</select>
Run Code Online (Sandbox Code Playgroud)
...向下呈现用户......
<select name="company">
<option "1">Microsoft</option>
<option "5">Apple</option>
<option "7">Google</option>
</select>
Run Code Online (Sandbox Code Playgroud)
(数据来自另一个列表上的Sharepoint Lookup,我想我可以使用jquery来保留唯一的选项,而不必深入了解正在发生的事情.)我可以删除这样的选项吗?谢谢.
在我的一个学校课程中,我使用以下函数来计算字符串中标识符的频率,用换行符和#分隔:
输入:
dog
cat
mouse
#
rabbit
snake
#
Run Code Online (Sandbox Code Playgroud)
功能:
//assume I have the proper includes, and am using namespace std
vector< pair<string,int> > getFreqcounts(string input) {
vector<string> items = splitString(input,"\n");
map<string,int> counts;
for (int i=0; i<items.size(); i++) {
if (items[i] == "#") continue;
counts[items[i]] = 0;
}
for (int i=0; i<items.size(); i++) {
if (items[i] == "#") continue;
counts[items[i]]++;
}
return vector< pair<string,int> > (counts.begin(),counts.end());
}
Run Code Online (Sandbox Code Playgroud)
我想至少
vector< pair<string,int> >有任何想法吗?
顺便说一句,这不是功课.真正的家庭作业将使用这个功能,但这完全出于我自己的好奇心和渴望拥有"更好"的代码.
我想在Powershell中将内容添加到文本文件的中间.我正在搜索特定模式,然后在其后添加内容.请注意,这是在文件的中间.
我现在拥有的是:
(Get-Content ( $fileName )) |
Foreach-Object {
if($_ -match "pattern")
{
#Add Lines after the selected pattern
$_ += "`nText To Add"
}
}
} | Set-Content( $fileName )
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.我假设因为$ _是不可变的,或者因为+ =运算符没有正确修改它?
将文本附加到$ _的方法是什么,这将反映在以下Set-Content调用中?
我有两个类,WebServiceRequest和OrderRequest.每个类都有属性.OrderRequest继承自WebServiceRequest - 如下所示:
public class WebServiceRequest
{
private string mAuthenticationToken;
public string AuthenticationToken
{
get { return mAuthenticationToken; }
set { mAuthenticationToken = value; }
}
...
}
Run Code Online (Sandbox Code Playgroud)
public class OrderRequest : WebServiceRequest
{
private string mVendorId;
public string VendorId
{
get { return mVendorId; }
set { mVendorId = value; }
}
...
}
Run Code Online (Sandbox Code Playgroud)
OrderRequest通过WebMethod公开.在查看公开OrderRequest的ASMX文件的WSDL(即MyWebService.asmx?WSDL)时,两个属性都是可见的 - 正如它们应该的那样.但是,当您查看公开OrderRequest的Web方法的SOAP示例时,只有VendorId属性可见,而不是继承的AuthenticationToken属性.这是怎么回事?
注意:我已将此问题作为MS Connect上的错误发布:https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedidID = 520200
当我们将参数声明为ICollection并将对象实例化为List时,为什么我们无法检索索引?即
ICollection<ProductDTO> Products = new List<ProductDTO>();
Products.Add(new ProductDTO(1,"Pen"));
Products.Add(new ProductDTO(2,"Notebook"));Run Code Online (Sandbox Code Playgroud)
然后,这将无效:
ProductDTO product = (ProductDTO)Products[0];Run Code Online (Sandbox Code Playgroud)
我错过了什么?
[是的,我们可以使用List作为声明,它可以工作,但我不想声明为列表,如:
List<ProductDTO> Products = new List<ProductDTO>();Run Code Online (Sandbox Code Playgroud)
]
我正在考虑使用隐藏的api在我的应用程序中关闭屏幕.
setScreenState来自https://android.googlesource.com/platform/frameworks/base/+/eclair-release/core/java/android/os/Power.java做我想要的,但它是一个隐藏的API.这是否意味着我不应该使用它?我认为它是一个相当稳定的API.
目前,我将屏幕超时设置为1毫秒,然后在屏幕关闭后重置超时.然而,android忽略1毫秒,而关闭它需要大约3秒,有时它完全忽略它并且不会关闭.
有什么建议?
我在我的活动中使用了AsyncTask.好像:
public class MyActivity {
private AsyncTask mTask;
private void doSomethingCool() {
mTask = new AsyncTask(...);
mTask.execute();
}
@Override
protected void onPause() {
super.onPause();
// How do I let the task keep running if just rotating?
if (isFinishing() == false) {
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果用户正在旋转设备,onPause()将被调用,但我不想因此而取消任务.我知道有一种方法可以告诉系统实际上不会破坏我的旋转活动,但这是推荐用于此问题吗?我是否应该将AsyncTask放在一个不会绑定到Activity的静态全局类中?
谢谢
Using str.format()是在Python 2.6和Python 3中格式化字符串的新标准.我在使用str.format()正则表达式时遇到了一个问题.
我写了一个正则表达式来返回指定域下的单个级别的所有域或者指定域下2级的任何域,如果下面的第二级是www ...
假设指定的域名是delivery.com,我的正则表达式应该返回a.delivery.com,b.delivery.com,www.c.delivery.com ......但它不应该返回xadelivery.com.
import re
str1 = "www.pizza.delivery.com"
str2 = "w.pizza.delivery.com"
str3 = "pizza.delivery.com"
if (re.match('^(w{3}\.)?([0-9A-Za-z-]+\.){1}delivery.com$', str1): print 'String 1 matches!'
if (re.match('^(w{3}\.)?([0-9A-Za-z-]+\.){1}delivery.com$', str2): print 'String 2 matches!'
if (re.match('^(w{3}\.)?([0-9A-Za-z-]+\.){1}delivery.com$', str3): print 'String 3 matches!'
Run Code Online (Sandbox Code Playgroud)
运行它应该给出结果:
String 1 matches!
String 3 matches!
Run Code Online (Sandbox Code Playgroud)
现在,问题是当我尝试使用str.format动态替换delivery.com时...
if (re.match('^(w{3}\.)?([0-9A-Za-z-]+\.){1}{domainName}$'.format(domainName = 'delivery.com'), str1): print 'String 1 matches!'
Run Code Online (Sandbox Code Playgroud)
这似乎失败了,因为str.format()期望{3}和{1}成为函数的参数.(我假设)
我可以使用+运算符连接字符串
'^(w{3}\.)?([0-9A-Za-z-]+\.){1}' + domainName + '$'
Run Code Online (Sandbox Code Playgroud)
问题归结为,str.format()当字符串(通常是正则表达式)中有" {n} " 时,是否可以使用?
c# ×3
android ×2
.net ×1
asmx ×1
asp.net ×1
c++ ×1
format ×1
forms ×1
google-maps ×1
icollection ×1
indexing ×1
inheritance ×1
javascript ×1
jquery ×1
list ×1
mef ×1
options ×1
powershell ×1
python ×1
regex ×1
sharepoint ×1
stl ×1
web-services ×1