我正在尝试使用枚举来显示相应的图像.为此,我有一个值转换器,将枚举转换为正确的资源名称.我的资源定义如下:
<UserControl.Resources>
<BitmapImage x:Key="AlarmCat1" UriSource="/Lib.Infrastructure;component/Resources/msg_cat1.bmp" />
<BitmapImage x:Key="AlarmCat2" UriSource="/Lib.Infrastructure;component/Resources/msg_cat2.bmp" />
<BitmapImage x:Key="AlarmCat3" UriSource="/Lib.Infrastructure;component/Resources/msg_cat3.bmp" />
<converters:JamCategoryToImageConverter x:Key="AlarmCategoryConverter" />
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
这有效:
<Image Source="{StaticResource AlarmCat1}" />
Run Code Online (Sandbox Code Playgroud)
但事实并非如此,调用转换器并传回正确的值.什么是正确的语法?
<Image Source="{StaticResource { Binding CurrentAlarmItem.AlarmCategory, Converter={StaticResource AlarmCategoryConverter}}}" />
Run Code Online (Sandbox Code Playgroud)
为完整起见,这是转换功能:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
switch ((AlarmCategory)value)
{
case AlarmCategory.Category1:
return "AlarmCat1";
case AlarmCategory.Category2:
return "AlarmCat2";
case AlarmCategory.Category3:
return "AlarmCat3";
default:
return null;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在设置一个ViewModel
具有很多属性的WPF应用程序.这些都是非常重复的,我想知道是否有办法摆脱这个.这是一个属性的样子,我有大约8-10个属性.
public string Name
{
get
{
return this.name;
}
set
{
if (this.name != value)
{
this.name = value;
this.RaisePropertyChanged("Name");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的脚本来测试在docker容器中运行的情况。容器启动,我可以连接到容器了。
node('docker') {
docker.image('python:3').inside() {
sh "python --version"
}
}
Run Code Online (Sandbox Code Playgroud)
最后,工作失败了。任何想法有什么问题吗?
更新1:
我已经将环境变量添加到Jenkins中,现在看到以下内容。看起来有些奇怪的变量传递给了docker。我知道如何检查中给出的命令sh
吗?
[Pipeline] stage
[Pipeline] { (test)
[Pipeline] echo
I'm here
[Pipeline] sh
invalid argument "=" for "-e, --env" flag: invalid environment variable: =
See 'docker exec --help'.
process apparently never started in /var/lib/jenkins-
slave/workspace/SYSTEM/clean-artifactory@tmp/durable-4d51de81
[Pipeline] }
[Pipeline] // stage
Run Code Online (Sandbox Code Playgroud) 我正在尝试在运行时创建一个通用对象。到目前为止,我已经能够创建它,但我不知道如何投射它。我拥有的是枚举对象,我想生成将枚举值转换为自定义字符串以映射到旧数据库的 EnumMapper。
Type enumType = myEnum.GetType();
Type enumMapperType = typeof(EnumMapper<>)
.GetGenericTypeDefinition().MakeGenericType(enumType);
var mapper = Activator.CreateInstance(enumMapperType); // OK
EnumMapper<> mapper = (EnumMapper<>) Activator.CreateInstance(enumMapperType); // Error
Run Code Online (Sandbox Code Playgroud)
当我在调试器中检查对象时,它是按我的预期创建的,但是我如何投射它以便我可以使用它?
班上:
public class EnumMapper<T> : IEnumMapper<T>
Run Code Online (Sandbox Code Playgroud)
界面:
public interface IEnumMapper<T>
{
T EnumValue(string value);
bool HasEnumValue(string stringValue);
bool HasStringValue(T enumValue);
string StringValue(T enumValue);
}
Run Code Online (Sandbox Code Playgroud)
Error 2 ; expected \EnumMapperTest.cs 36
Error 4 ; expected \EnumMapperTest.cs 36
Error 1 Invalid expression term '>' \EnumMapperTest.cs 36
Error 3 Invalid expression term '>' \EnumMapperTest.cs 36
Error 34 Only …
Run Code Online (Sandbox Code Playgroud) 我在VS2010中有静态库(.lib)并将它链接到我的测试项目.
lib有一个我使用下面的MACRO创建的工厂:
#define REGISTER_FACTORY(mType, my_class) \
class Factory##my_class : public CAbstractFactory\
{\
public:\
Factory##my_class() : CAbstractFactory(mType){}\
CBaseClass *Create()\
{ return new my_class(); }\
};\
static Factory##my_class StaticFactory##my_class;
Run Code Online (Sandbox Code Playgroud)
应该发生的是,在CAbstractFactory中,新工厂被注册mtype
.但是当我检查工厂时工厂不存在.
当我使用DLL而不是.lib时,它工作正常.我的猜测是链接器不包含静态变量,因为它没有被引用,或者静态变量甚至没有包含在库中.
如何强制链接器在我的.exe中包含静态库中的所有对象.
我像这样使用宏:
// Register factory that can create CMyObject with ID=100
REGISTER_FACTORY(100, CMyObject);
class CMyObject
{
};
Run Code Online (Sandbox Code Playgroud)
CAbstractFactory如下所示:
class CAbstractFactory {
CAbstractFactory(int id) {
CFactory::instance().add(id, this);
}
}
Run Code Online (Sandbox Code Playgroud)
然后在代码中的其他地方,我使用的主要.exe:
CBaseClass *pObject = CFactory::instance().Create(100);
Run Code Online (Sandbox Code Playgroud)
这将给我一个新的CMyObject
.我的想法是,我有许多不同类型的对象,我有一个数据库,其中包含指定我需要的对象类型的id.
100
只是一个例子.
确实,我没有直接引用.lib中的任何内容,但我希望能够使用我的工厂创建对象
CFactory类是一个简单的类,它保存所有CAbstractFactory类的寄存器(在映射中),并将create方法委托给正确的工厂.
CFactory &CFactory::Instance()
{
static CFactory instance;
return instance;
} …
Run Code Online (Sandbox Code Playgroud) 想知道它是否可能让Moq成为Prism EventAggregator让我们来看看他们拥有的EventAggregator快速入门
[TestMethod]
public void PresenterPublishesFundAddedOnViewAddClick()
{
var view = new MockAddFundView();
var EventAggregator = new MockEventAggregator();
var mockFundAddedEvent = new MockFundAddedEvent();
EventAggregator.AddMapping<FundAddedEvent>(mockFundAddedEvent);
var presenter = new AddFundPresenter(EventAggregator);
presenter.View = view;
view.Customer = "99";
view.Fund = "TestFund";
view.PublishAddClick();
Assert.IsTrue(mockFundAddedEvent.PublishCalled);
Assert.AreEqual("99", mockFundAddedEvent.PublishArgumentPayload.CustomerId);
}
I have tried to convert the above using moq but I get problems
Run Code Online (Sandbox Code Playgroud)
他们有MockEventAggregator.我怎么能用Moq做到这一点?
public class MockEventAggregator : IEventAggregator
{
Dictionary<Type, object> events = new Dictionary<Type, object>();
public TEventType GetEvent<TEventType>() where TEventType : EventBase
{
return (TEventType)events[typeof(TEventType)];
} …
Run Code Online (Sandbox Code Playgroud) 我试图通过詹金斯的Windows批处理命令插件执行devenv.exe但它继续执行并无法启动应用程序.
控制台输出:
**In progressConsole Output
Started by user anonymous
Building on master in workspace C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace
[workspace] $ cmd /c call C:\Windows\TEMP\hudson3900292017086958332.bat
C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace>set DEVPATH=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace>set PATH=D:\app\nazopay\product\11.2.0\dbhome_1\bin;D:\app\nazopay\product\11.2.0\client_1;C:\Program Files (x86)\Integrity\IntegrityClient10\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\cde\tools;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.6.0_23\bin\;C:\Program Files (x86)\Google\Chrome\Application;C:\MingW;C:\PROGRA~2\INTEGR~1\Toolkit\mksnt;%JAVA_HOME%;,;C:\Program Files\Java\jdk1.6.0_23;,;C:\Program Files\Java\jdk1.6.0_23\bin;%CLASS_PATH%;,;C:\Program Files\Java\jdk1.6.0_23\lib;,;C:\Program Files\Java\jdk1.6.0_23\lib;;C:\Program Files (x86)\M**icrosoft Visual Studio 10.0\Common7\IDE
C:\Program Files (x86)\Jenkins\jobs\TEMP\workspace>devenv.exe
Run Code Online (Sandbox Code Playgroud)