小编xof*_*ofz的帖子

如何在保持Designer满意的同时将依赖注入应用于UserControl视图?

public class StatisticsViewPresenter
{
    private IStatisticsView view;
    private Statistics statsModel;

    public StatisticsViewPresenter(IStatisticsView view, Statistics statsModel)
    {
        this.view = view;
        this.statsModel = statsModel;
    }
}
Run Code Online (Sandbox Code Playgroud)

我不使用事件(但我愿意,如果它可以解决我的问题),所以我的View类看起来像这样:

public class StatisticsForm : Form, IStatisticsView
{
    public StatisticsForm()
    {
        InitializeComponent();
    }

    [Inject]
    public StatisticsViewPresenter Presenter
    {
        private get;
        set;
    }
}
Run Code Online (Sandbox Code Playgroud)

kernel.Bind<StatisticsPresenter>().ToSelf().InSingletonScope();
kernel.Bind<IStatisticsView>().To<StatisticsForm>();
kernel.Get<IStatisticsView>();
Run Code Online (Sandbox Code Playgroud)

它构建表单,构建演示者,然后将演示者注入Presenter属性.一切都很好看.(除了那个单例范围的演示者 - 有关更好的方法的任何想法吗?也许只是手动将演示者注入到演示者的构造函数中的视图的Presenter属性中:this.view.Presenter = this).

但是如果我将StatisticsForm转换为StatisticsUserControl并将其拖放到我的MainForm上,它就不会被Ninject注入到MainForm中,它只是由Designer新设计的.我在这看到三个解决方案:

1)不要使用UserControls,只使用一个实现这些多视图的巨型表单(eww);

2)将UserControls注入我的表单并失去Designer支持;

3)你的解决方案!:)

c# user-controls dependency-injection ninject windows-forms-designer

6
推荐指数
1
解决办法
1913
查看次数

扩展Pharo Smalltalk类行为的最佳方法是什么?

我想用一个方法扩展String类,从字符串中创建一个url slug.我在这里找到了一个链接,显示了如何将扩展移动到自己的包中:

Smalltalk每日07/13/10:扩展行为II.

但是,我在Pharo Smalltalk中找不到任何"移动到打包"选项.是否可以使用新方法扩展核心类,还是有更好的方法?

smalltalk pharo

6
推荐指数
2
解决办法
1275
查看次数

将Seaside装载到Pharo 2.0上

Pharo 2.0最近发布.我下载了它,并试着运行它:

Gofer new
    squeaksource: 'MetacelloRepository';
    package: 'ConfigurationOfSeaside30';
    load.
(Smalltalk at: #ConfigurationOfSeaside30) load.
Run Code Online (Sandbox Code Playgroud)

它已完成,但它没有在"世界"菜单的"工具"子菜单中创建"海边控制面板"菜单选项.

接下来要采取的步骤是什么?

seaside pharo

6
推荐指数
1
解决办法
640
查看次数

为什么没有List <T>的构造函数采用params参数?

我知道我可以使用集合初始化程序来初始化列表:

var list = new List<string>
{
    "test string 1",
    "test string 2"
};
Run Code Online (Sandbox Code Playgroud)

如果我记得,这内部为每个项目调用添加.

为什么没有一个构造函数List<T>需要params T[] items

var list = new List<string>("test string 1", "test string 2");
Run Code Online (Sandbox Code Playgroud)

c# collections params

6
推荐指数
2
解决办法
155
查看次数

业务对象应该能够创建自己的DTO吗?

假设我有以下课程:

class Camera
{
    public Camera(
        double exposure,
        double brightness,
        double contrast,
        RegionOfInterest regionOfInterest)
    {
        this.exposure = exposure;
        this.brightness = brightness;
        this.contrast = contrast;
        this.regionOfInterest = regionOfInterest;
    }

    public void ConfigureAcquisitionFifo(IAcquisitionFifo acquisitionFifo)
    {
        // do stuff to the acquisition FIFO
    }

    readonly double exposure;
    readonly double brightness;
    readonly double contrast;
    readonly RegionOfInterest regionOfInterest;
}
Run Code Online (Sandbox Code Playgroud)

...和DTO在服务边界(WCF)上传输摄像头信息,比如在WinForms/WPF/Web应用程序中查看:

using System.Runtime.Serialization;

[DataContract]
public class CameraData
{
    [DataMember]
    public double Exposure { get; set; }

    [DataMember]
    public double Brightness { get; set; }

    [DataMember]
    public …
Run Code Online (Sandbox Code Playgroud)

c# oop dto

5
推荐指数
1
解决办法
1576
查看次数

如何将Smalltalk代码编辑器嵌入到我的应用程序中?

我正在我的Pharo图像中构建一个博客条目查看器和编辑器应用程序,并且条目内容被格式化为Smalltalk代码(Seaside标记API非常好).我对Smalltalk很新,所以我以这篇博文作为例子.

我目前有这个BlogEditor>>open方法:

open
| builder content |

builder := UITheme builder.
content := builder newColumn: {
    builder newRow: {
        builder newListFor: self
        list: #entries 
        selected: #entrySelectedIndex
        changeSelected: #entrySelectedIndex:
        help: 'Blog entries'.
    }.
    builder newRow: {
        editor := builder
            newTextEditorFor: self
            getText: #readSelectedEntry
            setText: #changeSelectedEntry:.
        editor minHeight: 400 } }.

(content openInWindowLabeled: 'Entries') extent: 800@700
Run Code Online (Sandbox Code Playgroud)

我不知道该代替什么editor := builder newTextEditorFor:.我看到了这门课SmalltalkEditor,但我不知道如何在我的UI上放一个.

smalltalk pharo

5
推荐指数
1
解决办法
373
查看次数

为什么BigInteger.ToString(“ x”)在signed.MaxValue(不包括)和unsigned.MaxValue(不包括)之间的值前面加上0?

示例(星号旁边的星号):

    [Fact]
    public void BigInteger_ToString_behavior_is_odd()
    {
        writeHex(new BigInteger(short.MaxValue)); // 7fff
        writeHex(new BigInteger(short.MaxValue) + 1); // 08000 **
        writeHex(new BigInteger(ushort.MaxValue)); // 0ffff **
        writeHex(new BigInteger(ushort.MaxValue) + 1); // 10000

        writeHex(new BigInteger(int.MaxValue)); // 7fffffff
        writeHex(new BigInteger(int.MaxValue) + 1); // 080000000 **
        writeHex(new BigInteger(uint.MaxValue)); // 0ffffffff **
        writeHex(new BigInteger(uint.MaxValue) + 1); // 100000000

        writeHex(new BigInteger(long.MaxValue)); // 7fffffffffffffff
        writeHex(new BigInteger(long.MaxValue) + 1); // 08000000000000000 **
        writeHex(new BigInteger(ulong.MaxValue)); // 0ffffffffffffffff **
        writeHex(new BigInteger(ulong.MaxValue) + 1); // 10000000000000000
    }

    private static void writeHex(BigInteger value)
    {
        Console.WriteLine(value.ToString("x")); …
Run Code Online (Sandbox Code Playgroud)

c# biginteger

4
推荐指数
1
解决办法
1149
查看次数

OOD和主题 - 对象混淆

假设我有一个门的定义:

class Door
{
    public void Lock()
    {
        // lock the door
    }
}
Run Code Online (Sandbox Code Playgroud)

这似乎对我有意义,至少在一段时间内.但现在,我不太确定.如果我有一个想要锁门的Person对象,他会调用aDoor.Lock().但在现实生活中,我们不会通过告诉门锁自己锁门.

似乎更准确的情况模型是能够直接修改门的状态的人,只要他有足够的力量来锁门.例如,aCat不能设置aDoor.IsLocked = true.如果它们支持参数,我可以看到如何使用属性执行此操作:

class Person
{
    public void LockDoor(Door door)
    {
        door.IsLocked(this) = true;
    }
}

class Door
{
    bool isLocked;

    public bool IsLocked(Person person)
    {
        set
        {
            if(person != null) // ensure there is a real person trying to lock the door
            {
                this.isLocked = value;
            }
        }
    }
}

static void Main()
{
    Person personFromThinAir = new Person();
    Door doorFromThinAir = new Door(); …
Run Code Online (Sandbox Code Playgroud)

c# oop

3
推荐指数
2
解决办法
261
查看次数

在Visual Studio中,如何仅为非测试代码可视化代码行长度?

我现在正在使用指南,但我认为没有办法为某些项目禁用它们(我的测试项目).

一般来说,如何将长的描述性测试方法名称与非测试代码的行长限制进行协调(我认为两者都很好)?如果您有同样的感觉并解决了这个问题,您使用什么解决方案?

text-editor visual-studio

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

ILMerge'd程序集的运行时版本是v4.0.20926; 预期版本是v4.0.30319

这就是我的.csproj AfterBuild的样子:

  <Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'">
    <Exec Command="&quot;..\Tools\ILMerge\ILMerge.exe&quot; /internalize /ndebug /out:@(MainAssembly) /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 &quot;@(IntermediateAssembly)&quot; @(ReferenceCopyLocalPaths->'&quot;%(FullPath)&quot;', ' ')" Condition=" '$(TargetFrameworkVersion)' == 'v4.0'" />
  </Target>
Run Code Online (Sandbox Code Playgroud)

我正在运行64位Windows.我尝试过更改.NET Framework ...\Microsoft.NET\Framework\...,...\Microsoft.NET\Framework64\...但它没有帮助.

我还在ILMerge目录中创建了ILMerge.exe.config:

<?xml version ="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
    </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

为什么ILMerge不能生成4.0.30319程序集?

.net ilmerge

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