我创建了一个自定义属性来装饰我想在运行时查询的许多类:
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public class ExampleAttribute : Attribute
{
public ExampleAttribute(string name)
{
this.Name = name;
}
public string Name
{
get;
private set;
}
}
Run Code Online (Sandbox Code Playgroud)
这些类中的每一个都派生自一个抽象基类:
[Example("BaseExample")]
public abstract class ExampleContentControl : UserControl
{
// class contents here
}
public class DerivedControl : ExampleContentControl
{
// class contents here
}
Run Code Online (Sandbox Code Playgroud)
我是否需要将此属性放在每个派生类上,即使我将其添加到基类中?该属性被标记为可继承,但是当我执行查询时,我只看到基类而不是派生类.
从另一个线程:
var typesWithMyAttribute =
from a in AppDomain.CurrentDomain.GetAssemblies()
from t in a.GetTypes()
let attributes = t.GetCustomAttributes(typeof(ExampleAttribute), true)
where attributes != null && attributes.Length > 0 …Run Code Online (Sandbox Code Playgroud) 我需要在 Windows Server 2008 R2 上将一些事件从 Windows 事件日志导出到 XML。为了实现这一目标,我使用 EvtExportLog 将这些事件导出到文件,然后尝试使用 EvtArchiveExportedLog 获取事件的本地化描述。这是示例:
EvtExportLog( 0, 0, query, logFileName, EvtExportLogChannelPath );
EvtArchiveExportedLog( 0, logFileName, 0, 0 );
Run Code Online (Sandbox Code Playgroud)
EvtExportLog 函数成功并创建 .evtx 文件,但 EvtArchiveExportedLog 不断失败,并显示 ERROR_DIRECTORY 错误代码。我不知道这种行为的原因是什么。
在我的Spring应用程序中,我使用的SchedulerFactoryBean是与Quartz集成.我们将要有群集的Tomcat实例,因此我希望拥有一个集群的Quartz环境,这样相同的作业就不会在不同的Web服务器上同时运行.
为此,我的app-context.xml内容如下:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
<ref bean="simpleTrigger" />
</list>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="overwriteExistingJobs" value="true"/>
<!-- found in applicationContext-data.xml -->
<property name="applicationContextSchedulerContextKey" value="applicationContext"/>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">SomeBatchScheduler</prop>
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
<prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
<!--<prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>-->
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.isClustered">true</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">25</prop>
<prop key="org.quartz.threadPool.threadPriority">5</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
一切都运行良好,除了当我尝试删除或更改触发器,然后重新启动我的应用程序时,旧的触发器仍然保留在数据库中,仍然运行.我不希望这样,我只是希望在app停止(或重新启动)时删除它们.我将overwriteExistingJobs属性的值设置为true,因为我认为这就是它所做的.
有任何想法吗?我只想使用数据库进行聚类,而不是任何类型的持久性.
在试验scriptblocks时,我试图使用带有高级函数的scriptblock参数,并注意到它的执行方式与提供给编译的cmdlet时的执行方式不同.
在审查这个博客帖子从PowerShell团队博客,看来,如果一个脚本块是不是该参数的有效输入PowerShell引擎应评估脚本块.似乎在使用scriptblock参数调用函数时,它会尝试直接将scriptblock转换为参数类型,而不是根据管道中的当前对象来评估scriptblock.
我的意图是复制行为,如:
Import-CSV somecsv.csv | get-wmiobject -class {$_.class} -Computer {$_.computer}
Run Code Online (Sandbox Code Playgroud)
用于高级功能.
示例脚本:
$sb = {throw "If there was an error, the scriptblock was evaluated!"}
function test ()
{
param (
[Parameter()]
[string]
$ThisShouldBeEvaluatedForEachItem,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]
$FullName
)
process
{
write-host $Fullname, $ThisShouldBeEvaluatedForEachItem
}
}
Get-ChildItem | test -ThisShouldBeEvaluatedForEachItem $sb
Run Code Online (Sandbox Code Playgroud)
这是预期的行为,还是我朝错误的方向前进?
基于Keith的响应,我将ValueFromPipeline和ValueFromPipelineByPropertyName(在两个单独的测试中)添加到ThisShouldBeEvaluatedForEachItem参数的Parameter属性中.这样做会使示例工作,尽管它似乎从团队博客帖子中击败了scriptblock参数的既定目的.
虽然问题检查输入是否是字符串的类型已经关闭,但两个答案在我的脑海中飙升了一个微优化问题:以下哪两个解决方案会表现更好?
Char.IsLetter:string myString = "RandomStringOfLetters";
bool allLetters = myString.All( c => Char.IsLetter(c) );
Run Code Online (Sandbox Code Playgroud)
string s = "RandomStringOfLetters";
bool allLetters = Regex.IsMatch(s, "^[a-z]+$", RegexOptions.IgnoreCase);
Run Code Online (Sandbox Code Playgroud)
不想只问里德或马克的问题我以为我会写一个快速测试来确定哪个表现更好.问题是我没有做过很多代码优化(我倾向于将代码可读性放在首位).
除了在每个运行之前和之后获取时间戳之外,还有哪些其他(更好的?)选项可以确定哪个解决方案运行得更快?
编辑
我修改了Martin的工作答案Console.WriteLine(...)并将其作为控制台应用程序运行.不确定LinqPad究竟是如何运行应用程序的,但结果大致相同:
41 178
c# optimization premature-optimization micro-optimization speed-test
如何在使用scanf时使用变量指定字段长度.例如:
char word[20+1];
scanf(file, "%20s", word);
Run Code Online (Sandbox Code Playgroud)
另外,使用20 + 1是否正确(因为它需要在末尾添加\ 0?).相反,我希望有类似的东西:
#define MAX_STRING_LENGTH 20
Run Code Online (Sandbox Code Playgroud)
然后
char word[MAX_STRING_LENGTH+1];
scanf(file, "%"MAX_STRING_LENGTH"s", word); // what's the correct syntax here..?
Run Code Online (Sandbox Code Playgroud)
这可能吗?如果它是一个变量如何:
int length = 20;
char word[length+1];
scanf(file, "%" length "%s", word); // what's the correct syntax here..?
Run Code Online (Sandbox Code Playgroud)
谢谢.
虽然我确信其他人最终已经设法解决了这个问题,但我一直在关注各种文档,并且已经有了一段艰难的时间.
http://www.phpunit.de/manual/current/en/installation.html
听起来很容易.但是,根据您的设置,您可能会陷入一个兔子洞.
例如,PEAR必须是高于1.8.1的版本.我当时有1.8.0,所以我去了解如何更新PEAR
PEAR upgrade-all
Run Code Online (Sandbox Code Playgroud)
给出错误.无法访问.
sudo PEAR upgrade-all
Run Code Online (Sandbox Code Playgroud)
工作,但升级用户'sudo'拥有的PEAR安装(而不是你的主要帐户...或类似的东西,短版本是5,它显然不起作用)
cd ~
pico .bash_profile
Run Code Online (Sandbox Code Playgroud)
加
export PATH=/usr/local/bin:$PATH
Run Code Online (Sandbox Code Playgroud)
当您输入PEAR时,为您提供正确的PEAR,您终于准备好了安装PHPUnit指令的第1步.
pear channel-discover pear.phpunit.de
Run Code Online (Sandbox Code Playgroud)
错误.您无权访问/ usr/local/temp
sudo chmod 777 /usr/local/temp
Run Code Online (Sandbox Code Playgroud)
错误.您无权访问/usr/local/temp/channel.xml
sudo chmod 777 /usr/local/temp/channel.xml
pear channel-discover pear.phpunit.de
Run Code Online (Sandbox Code Playgroud)
错误.
Registry directory is not writeable by the current user
Run Code Online (Sandbox Code Playgroud)
但我在MAC上!
/sigh
/facepalm
/tears
Run Code Online (Sandbox Code Playgroud)
我实际上在我的机器上有一个phpunit的"工作副本".(YAY!)奇怪的问题是它只在我从一个特定文件夹输入phpunit时才有效
cd /usr/local/PEAR
phpunit
Run Code Online (Sandbox Code Playgroud)
^^工作
cd ~
phpunit
Run Code Online (Sandbox Code Playgroud)
^^返回
Warning: require_once(PHPUnit/Util/Filter.php): failed to open stream: No such file or directory in /usr/local/bin/phpunit on line 46
Fatal error: require_once(): Failed opening …Run Code Online (Sandbox Code Playgroud) 我有租户的列表(称之为TenantList),它的组成承租人对象,他们都有一个ID属性.如何返回由其ID属性组成的可枚举项?
我在寻找一些C#示例代码或可以解析.vdproj文件(视觉工作室2010安装和部署项目)的工具.
我的应用程序由后台UIView中的工具栏和AVCaptureVideoPreviewLayer组成.我想看看关于设备方向的工具栏旋转,所以在我的主ViewController中,我实现了这个功能:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)
这很好用,但是当界面方向改变时,我看到背景UIView(带有视频层)也在旋转,所以我的视频视图现在向左或向右旋转90度......这真的很酷!
所以我的问题是:有没有办法在特定的UIView上禁用自动旋转动画?
我已经看到了一个类似的问题:为单个UIView禁用自动旋转,但答案不适合我的问题,我真的需要背景视图不要移动,不要用一种"计数器来解决问题动画".所以我决定提出这个话题.
有任何想法吗 ?
谢谢 !
c# ×4
c++ ×2
attributes ×1
c ×1
event-log ×1
field ×1
inheritance ×1
installation ×1
iphone ×1
java ×1
linq ×1
optimization ×1
parsing ×1
pear ×1
phpunit ×1
powershell ×1
reflection ×1
scanf ×1
speed-test ×1
spring ×1
uiview ×1
vdproj ×1
winapi ×1
windows ×1