有没有什么方法可以改变Label的行为来支持点击-in WPF切换?即,通过单击,"Selector.IsSelected"属性在"True"和"False"之间切换.问候.
我有这个代码片段:
int x = 2;
int y = x + 4 * ++x;
// what is y???
Run Code Online (Sandbox Code Playgroud)
当我用c/c ++编译和测试时,我会得到:
// C/C++
y is 15
Run Code Online (Sandbox Code Playgroud)
但是通过c#我会得到的
// C#
y is 14
Run Code Online (Sandbox Code Playgroud)
为什么?
IL的一部分是:
locals init ([0] int32 x,
[1] int32 y)
IL_0000: nop
IL_0001: ldc.i4.2
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: ldc.i4.4
IL_0005: ldloc.0
IL_0006: ldc.i4.1
IL_0007: add
IL_0008: dup
IL_0009: stloc.0
IL_000a: mul
IL_000b: add
IL_000c: stloc.1
IL_000d: ldloca.s y
Run Code Online (Sandbox Code Playgroud) 我想了解Google +的流项目边框左边是如何工作的?每个机构都可以解释它或建议任何链接和/或文章吗?
更多:当您关注流时,您会看到流的左边界变为蓝色,而当您关注另一个流时,边框将动画显示新的焦点项.
感谢任何建议.
我知道Activator.CreateInstance()
可以创建一个新的实例object
。IL
但我正在寻找一种通过和创建实例的方法Expression
。我想我可以创建一个动态 lambda 来创建类型的实例,并缓存 lambda 以加速对象初始化。我对吗?你能帮我吗?
如何注册条件装饰的SimpleInjector
?以下是我的定义:
public interface ICommand { }
public interface ICleanableCommand : ICommand {
void Clean();
}
public interface ICommandHandler<in TCommand>
where TCommand : ICommand {
void Handle(TCommand command);
}
public class CleanableCommandHandlerDecorator<TCommand>
: ICommandHandler<TCommand>
where TCommand : ICleanableCommand {
private readonly ICommandHandler<TCommand> _handler;
public CleanableCommandHandlerDecorator(
ICommandHandler<TCommand> handler) {
_handler = handler;
}
void ICommandHandler<TCommand>.Handle(TCommand command) {
command.Clean();
_handler.Handle(command);
}
}
Run Code Online (Sandbox Code Playgroud)
而我正在努力:
container.RegisterManyForOpenGeneric(
typeof(ICommandHandler<>),
AppDomain.CurrentDomain.GetAssemblies()
);
container.RegisterDecorator(
typeof(ICommandHandler<>),
typeof(CleanableCommandHandlerDecorator<>)
// ,context => context.ImplementationType ???
// I want to …
Run Code Online (Sandbox Code Playgroud) .net dependency-injection decorator inversion-of-control simple-injector
如你所知,有一个渐变选项PhotoShop的命名AngleGradient
.但是,WPF
只有LinearGradientBrush
和RadialGradientBrush
渐变.你有没有想过如何创建一个AngleGradient
使用XAML
?
更新:样品 - 来自photoshop:
我在这个上下文中使用 Quartz.NET(需要提到这GrabberContext
是一个DbContext
扩展类):
// configuring Autofac:
var builder = new ContainerBuilder();
// configuring GrabberContext
builder.RegisterType<GrabberContext>()
.AsSelf()
.InstancePerLifetimeScope();
// configuring GrabService
builder.RegisterType<GrabService>()
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
// configuring Quartz to use Autofac
builder.RegisterModule(new QuartzAutofacFactoryModule());
builder.RegisterModule(new QuartzAutofacJobsModule(typeof(DiConfig).Assembly));
var container = builder.Build();
// configuring jobs:
var scheduler = container.Resolve<IScheduler>();
scheduler.Start();
var jobDetail = new JobDetailImpl("GrabJob", null, typeof(GrabJob));
var trigger = TriggerBuilder.Create()
.WithIdentity("GrabJobTrigger")
.WithSimpleSchedule(x => x
.RepeatForever()
.WithIntervalInMinutes(1)
)
.StartAt(DateTimeOffset.UtcNow.AddSeconds(30))
.Build();
scheduler.ScheduleJob(jobDetail, trigger);
Run Code Online (Sandbox Code Playgroud)
这就是工作:
public class GrabJob : IJob {
private readonly IGrabService …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Expression
此代码创建一个简单的映射器:
public static class MyUtility {
public static Action<TSource, TTarget> BuildMapAction<TSource, TTarget>(IEnumerable<PropertyMap> properties) {
var sourceInstance = Expression.Parameter(typeof(TSource), "source");
var targetInstance = Expression.Parameter(typeof(TTarget), "target");
var statements = BuildPropertyGettersSetters(sourceInstance, targetInstance, properties);
Expression blockExp = Expression.Block(new[] { sourceInstance, targetInstance }, statements);
if (blockExp.CanReduce)
blockExp = blockExp.ReduceAndCheck();
blockExp = blockExp.ReduceExtensions();
var lambda = Expression.Lambda<Action<TSource, TTarget>>(blockExp, sourceInstance, targetInstance);
return lambda.Compile();
}
private static IEnumerable<Expression> BuildPropertyGettersSetters(
ParameterExpression sourceInstance,
ParameterExpression targetInstance,
IEnumerable<PropertyMap> properties) {
var statements = new List<Expression>();
foreach (var property in properties) …
Run Code Online (Sandbox Code Playgroud) 我有一个问题,用于保存文件并在TransactionScope中的DB中插入记录; 意味着保存文件和插入记录,必须依赖于=或两者兼有.有人能帮帮我吗?
List<>
我有一个反射代码,用于创建(运行时已知的类型参数)的实例,并调用Add
方法向其添加一些值。我的片段是这样的:
// here is my type parameter
var genericType = typeof(MyRunTimeType);
// here is a list of my values
MyRunTimeType[] values = MyRunTimeValuesOfTypeMyRunTimeType();
// creating instance of List<>
var listType = typeof(List<>);
var listGenericType = listType.MakeGenericType(genericType);
var listInstance = Activator.CreateInstance(listGenericType);
// getting Add method and call it
var addMethod = listGenericType.GetMethod("Add", genericType);
foreach (var value invalues)
addMethod.Invoke(listInstance, new[] { value });
Run Code Online (Sandbox Code Playgroud)
那么,您建议如何将此反射片段转换为表达式树?
更新:
好吧,我写了这个片段,它似乎无法工作:
public static Func<IEnumerable<object>, object> GetAndFillListMethod(Type genericType) {
var listType = typeof(List<>);
var listGenericType …
Run Code Online (Sandbox Code Playgroud) c# ×6
lambda ×3
wpf ×2
.net ×1
animation ×1
async-await ×1
c ×1
c++ ×1
css ×1
decorator ×1
delegates ×1
dependencies ×1
expression ×1
file-io ×1
google-plus ×1
gradient ×1
il ×1
insert ×1
javascript ×1
label ×1
linq ×1
quartz.net ×1
reflection ×1
toggle ×1
transactions ×1
wpf-4.0 ×1
wpf-brushes ×1
wpf-controls ×1
xaml ×1