我想使用Ninject作为IoC容器,但无法理解如何在构造函数中创建一个具有多个参数的类的实例.基本上我有一个用于PCL库中的身份验证的服务接口,以及它在WP8项目中的实现,该项目在构造函数中接收cosumer密钥,secret和baseAddress:
//On PCL project
public interface IAuthorizationService {
bool Authenticate();
}
//On WP8 Project
pubilc class MyAuthenticator : IAuthorizationService {
public MyAuthenticator(string consumerKey, string consumerSecret, string baseAddress) { ... }
public bool Authenticate() { ... }
}
Run Code Online (Sandbox Code Playgroud)
现在我需要配置Ninject模块,这样我就可以获得IAuthorizationService的实例.如果我的班级没有构造函数,我会这样做:
internal class Module : NinjectModule {
public override void Load() {
this.Bind<IAuthorizationService>().To<MyAuthenticator>();
}
}
Run Code Online (Sandbox Code Playgroud)
如果它有构造函数的固定值,我会这样做:
internal class Module : NinjectModule {
public override void Load() {
this.Bind<IAuthorizationService>().To<MyAuthenticator>().WithConstructorArgument( */* fixed argument here*/* );
}
}
Run Code Online (Sandbox Code Playgroud)
并获得一个实例 Module.Get<IAuthorizationService>()
但是如果构造函数参数在编译时无法解析呢?如何通过参数?绑定代码应该如何?
编辑了这个问题.
我使用注册表和键创建了一个新的Windows shell上下文菜单项
HKLM\Software\Classes\Folder\shell\appname
HKLM\Software\Classes\Folder\shell\appname\command
Run Code Online (Sandbox Code Playgroud)
现在我想为这个命令添加一个图标.我怎么做的?
我正在使用VS2010创建一个Office插件(用于Outlook),我得到以下错误:
"GenerateOfficeAddInManifest"任务未获得所需参数"TargetFramework"的值
我甚至没有在我的插件中添加代码.刚刚创建了模板并构建!
对此有何帮助?
函数式编程与OO编程的重载相同吗?如果没有,为什么?(如果可能,请举例)
TKS
有任何方法可以将布尔值转换为本地化字符串.我试过了:
var x = true;
var culture = new CultureInfo("en-US")
x.ToString(culture) // returns True
culture = new CultureInfo("pt-BR")
x.ToString(culture) // returns True, expected Verdadeiro
Run Code Online (Sandbox Code Playgroud)
或者我应该在2020年之前开始输入开关吗?
我有一个带有Pivot和3个PivotItems的应用程序.每个PivotItem都有自己的DataContext,DataContext有一个名为IsLoading的属性.
可以将SystemTray.ProgressIndicator IsVisible属性绑定到选定的pivotitem DataContext.IsLoading属性?
这是我尝试过的:
<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator
IsVisible="{Binding ElementName=pivot, Path=SelectedItem.DataContext.IsLoading}" />
</shell:SystemTray.ProgressIndicator>
<Grid Background="Transparent">
<controls:Pivot x:Name="pivot">
<controls:PivotItem Header="pivot item"
Margin="0,28,24,0"
DataContext="{Binding DCOne}" />
<controls:PivotItem Header="pivot item"
Margin="0,28,24,0"
DataContext="{Binding DCTwo}" />
<controls:PivotItem Header="pivot item"
Margin="0,28,24,0"
DataContext="{Binding DCThree}" />
</Grid>
Run Code Online (Sandbox Code Playgroud) 如何根据WP7上的属性值更改VisualState?
我试图使用MVVM模式,当我的模型加载时,我希望我的视图去特定的VisualState.
在Silverlight中,我们有属性更改的触发器,但在WP7中没有!
PS:我不想使用框架,我想了解它是如何在WP7中完成的.
我试图学习Haskell,但我被卡在数字转换上,有人可以解释为什么Haskell编译器会对这段代码感到厌倦:
phimagic :: Int -> [Int]
phimagic x = x : (phimagic (round (x * 4.236068)))
Run Code Online (Sandbox Code Playgroud)
它会输出错误消息:
problem2.hs:25:33:
No instance for (RealFrac Int) arising from a use of `round'
Possible fix: add an instance declaration for (RealFrac Int)
In the first argument of `phimagic', namely
`(round (x * 4.236068))'
In the second argument of `(:)', namely
`(phimagic (round (x * 4.236068)))'
In the expression: x : (phimagic (round (x * 4.236068)))
problem2.hs:25:44:
No instance for (Fractional Int)
arising from the …Run Code Online (Sandbox Code Playgroud) 为什么这个c#代码会抛出一个null异常?
bool boolResult = SomeClass?.NullableProperty.ItsOkProperty ?? false;
Run Code Online (Sandbox Code Playgroud)
一旦NullableProperty评估为null,elvis运营商是否应该停止评估(短路)?
根据我的理解,上面的代码行是一个快捷方式:
bool boolResult
if(SomeClass != null)
if(SomeClass.NullableProperty != null)
boolResult = SomeClass.NullableProperty.ItsOkProperty;
else
boolResult = false;
else
boolResult = false;
Run Code Online (Sandbox Code Playgroud)
我错了吗?
编辑:现在我明白为什么我弄错了,代码行实际上转换为类似于:
bool boolResult
if(SomeClass != null)
boolResult = SomeClass.NullableProperty.ItsOkProperty;
else
boolResult = false;
Run Code Online (Sandbox Code Playgroud)
因为NullableProperty为空而抛出...
c# ×2
.net ×1
add-in ×1
c#-6.0 ×1
cultureinfo ×1
currying ×1
data-binding ×1
haskell ×1
localization ×1
mvvm ×1
ninject ×1
oop ×1
outlook ×1
overloading ×1
pivot ×1
pivotitem ×1
registry ×1
silverlight ×1
string ×1
system-tray ×1
windows ×1