小编jav*_*iry的帖子

通过在WPF中单击来更改Label的行为以支持切换

有没有什么方法可以改变Label的行为来支持点击-in WPF切换?即,通过单击,"Selector.IsSelected"属性在"True"和"False"之间切换.问候.

wpf label toggle wpf-controls

3
推荐指数
1
解决办法
1487
查看次数

一元:为什么一元在c#中的行为因c/c ++而异

可能重复:
未定义,未指定和实现定义的行为
未定义的行为和序列点
C,C++,Java和C#中的前后增量运算符行为

我有这个代码片段:

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)

c c# c++ unary-operator

3
推荐指数
1
解决办法
225
查看次数

Google+喜欢边框

我想了解Google +的流项目边框左边是如何工作的?每个机构都可以解释它或建议任何链接和/或文章吗?

更多:当您关注流时,您会看到流的左边界变为蓝色,而当您关注另一个流时,边框将动画显示新的焦点项.

  1. 专注于元素a
  2. 一个人的左边界变成了蓝色
  3. 专注于元素b
  4. 蓝色边框动画到元素b的左边界

感谢任何建议.

javascript css animation google-plus

3
推荐指数
1
解决办法
319
查看次数

如何通过动态 lambda 和 IL 创建对象的新实例?

我知道Activator.CreateInstance()可以创建一个新的实例objectIL但我正在寻找一种通过和创建实例的方法Expression。我想我可以创建一个动态 lambda 来创建类型的实例,并缓存 lambda 以加速对象初始化。我对吗?你能帮我吗?

c# lambda il delegates expression

3
推荐指数
1
解决办法
2477
查看次数

条件注册基于SimpleInjector中的泛型类型约束的命令装饰器

如何注册条件装饰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

3
推荐指数
1
解决办法
634
查看次数

WPF中的AngleGradient

如你所知,有一个渐变选项PhotoShop的命名AngleGradient.但是,WPF只有LinearGradientBrushRadialGradientBrush渐变.你有没有想过如何创建一个AngleGradient使用XAML

更新:样品 - 来自photoshop:

在此输入图像描述

wpf xaml gradient wpf-4.0 wpf-brushes

3
推荐指数
1
解决办法
1148
查看次数

将异步方法作为 Quartz.NET 作业运行并处理对象问题

我在这个上下文中使用 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)

c# entity-framework quartz.net async-await quartz.net-2.0

3
推荐指数
1
解决办法
2894
查看次数

表达式在同一属性上将一个对象映射到另一个对象

我正在尝试使用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)

c# linq lambda expression-trees dynamicmethod

3
推荐指数
1
解决办法
726
查看次数

如何在C#中保存文件和在DB中插入记录之间创建一个Transactions望远镜

我有一个问题,用于保存文件并在TransactionScope中的DB中插入记录; 意味着保存文件和插入记录,必须依赖于=或两者兼有.有人能帮帮我吗?

c# file-io dependencies transactions insert

2
推荐指数
1
解决办法
2932
查看次数

从反射转向表达式树

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# reflection lambda expression-trees

2
推荐指数
1
解决办法
1562
查看次数