小编fat*_*tty的帖子

按样式设置Button的内容

我有一个像这样定义的WPF按钮:

<Button Style="{StaticResource RevertButtonStyle}" />
Run Code Online (Sandbox Code Playgroud)

这是风格的样子:

<Style x:Key="RevertButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Height" Value="25" />
    <Setter Property="Width" Value="20" />
    <Setter Property="Margin" Value="3,0,0,0" />
</Style>
Run Code Online (Sandbox Code Playgroud)

如何更改样式以指定内容以使用名为"revert.png"的图像?

谢谢,

wpf

24
推荐指数
1
解决办法
1万
查看次数

具有别名表名的ActiveRecord查询

使用包含范围的模型关注点,知道嵌套和/或自引用查询的最佳方法是什么?

在我的一个问题中,我的范围类似于这些:

scope :current, ->(as_at = Time.now) { current_and_expired(as_at).current_and_future(as_at) }
scope :current_and_future, ->(as_at = Time.now) { where("#{upper_bound_column} IS NULL OR #{upper_bound_column} >= ?", as_at) }
scope :current_and_expired, ->(as_at = Time.now) { where("#{lower_bound_column} IS NULL OR #{lower_bound_column} <= ?", as_at) }

def self.lower_bound_column
  lower_bound_field
end
def self.upper_bound_column
  upper_bound_field
end
Run Code Online (Sandbox Code Playgroud)

并通过has_many来引用,例如: has_many :company_users, -> { current }

如果进行ActiveRecord查询,该查询引用包含关注点的少数模型,则会导致"模糊列名称"异常,这是有意义的.

为了帮助解决这个问题,我将列名称辅助方法更改为现在

def self.lower_bound_column
  "#{self.table_name}.#{lower_bound_field}"
end
def self.upper_bound_column
   "#{self.table_name}.#{upper_bound_field}"
end
Run Code Online (Sandbox Code Playgroud)

哪种方法很有效,直到您需要自引用查询.Arel通过在生成的SQL中对表名进行别名来帮助缓解这些问题,例如:

LEFT OUTER JOIN "company_users" "company_users_companies" ON "company_users_companies"."company_id" = "companies"."id"

INNER JOIN "company_users" ON …

activerecord ruby-on-rails arel

8
推荐指数
1
解决办法
7134
查看次数

C#,将字符串变量转换为类变量

我的功能如下.

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}
Run Code Online (Sandbox Code Playgroud)

键变量将具有我的类名.我需要返回类的新实例.如果constructorParm为null,那么我需要使用默认构造函数else传递构造函数参数来加载该类.我该怎么做呢 ?

添加:

我写了这样的代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Catalyst.BO.StudentProfileBO;
using Catalyst.BO.ReportBO;
using Catalyst.DAL.ReportDAO;
using System.Collections;
using System.Data;

namespace Catalyst.BO.Factory
{
    public class CFactory
    {
        public static object getClassInstance(string key, params  object[] constructorArgs)
        {
            string assemblyPath = null;
            string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

            DataSet objDataset = getAssemblyInfo(key);
            if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count …
Run Code Online (Sandbox Code Playgroud)

c# reflection constructor class

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

标签 统计

activerecord ×1

arel ×1

c# ×1

class ×1

constructor ×1

reflection ×1

ruby-on-rails ×1

wpf ×1