我正在开发一个MEF项目来发现使用和实现技术.我的第一个发现阶段是实现动态可配置和集中的数据控制器.自定义行为的一种方法是继承我提供的强制执行奇点规则的类.虽然Singleton模式在使用中受到很多诽谤,但我可能已经找到了一种可以在某种程度上验证模式存在困难的实现.
假设主机导入的数据控制模块(DataController)旨在根据兄弟模块的请求为数据库提供公共管道.我只需要一个DataController并作为一个模块组成,DataController必须实现IDataController.DataProvider作为基类的实现纯粹是可选的; 但是,从DataProvider派生需要一些额外的处理.
收集事实:
静态类无法实现或扩展抽象类或接口.仅此事实就消除了使用静态类来确保DataController的单一存在.
实现Singleton模式的DataController将确保每个应用程序域的单一存在.DataController没有限制; 允许继承在Host中导入和编写的必需接口.
给定DataController的推导,Singleton模式的标准实现可能在同样的情况下具有挑战性.建议的数据库提供了可公开访问的类:IDataController和抽象的DataProvider.为了确保派生的DataController的单个实例,实现将需要偏离规范.
此时,解决方案似乎很清楚.DataHandler基类实现Singleton模式.我并不天真地认为还有其他方法可以做到这一点.但这是我对如何实现模式的粗略期望:
// DataLibrary referenced by Host
public interface IDataController
{
IDataController Start();
DbConnection CreateConnection<TDbConnection>(params string[] args)
where TDbConnection : DbConnection, IDbConnection;
}
public abstract class DataProvider
{
// singleton implementation
private static IDataController dcInstance;
protected static IDataController Instance
{
get{ return dcInstance; }
}
// ========================
abstract IDataController CreateController();
protected IDataController instanceController<TDataController>()
where TDataController : IDataController, new()
{
return new TDataController (); …Run Code Online (Sandbox Code Playgroud) 我有一个extern函数和一个struct定义在token.c:
#include "stdio.h"
typedef struct token {
int start;
int length;
} t;
extern t get_token(int, int);
t get_token(int s, int l) {
printf("[C] new token: start [%d] length [%d]\n\n", s, l);
t m_T = {};
m_T.start = s;
m_T.length = l;
return m_T;
}
Run Code Online (Sandbox Code Playgroud)
...这样我就可以_get_token从我的程序集中调用并获得一个新令牌.在make_token.asm中我有以下内容:
SECTION .data ; initialized data
mtkn: db "call: token(%d, %d)", 10, 0
mlen db "length: %d", 10, 0
mstt: db "start: %d", 10, 0
mend: db 10, "*** …Run Code Online (Sandbox Code Playgroud) 以下代码是否使using(...)函数/目的无关紧要?
它会导致GC性能不足吗?
class Program
{
static Dictionary<string , DisposableClass> Disposables
{
get
{
if (disposables == null)
disposables = new Dictionary<string , DisposableClass>();
return disposables;
}
}
static Dictionary<string , DisposableClass> disposables;
static void Main(string[] args)
{
DisposableClass disposable;
using (disposable = new DisposableClass())
{
// do some work
disposable.Name = "SuperDisposable";
Disposables["uniqueID" + Disposables.Count] = disposable;
}
Console.WriteLine("Output: " + Disposables["uniqueID0"].Name);
Console.ReadLine();
}
}
class DisposableClass : IDisposable
{
internal string Name
{
get { return myName; …Run Code Online (Sandbox Code Playgroud) 好的,我正在制作一个卡片播放程序,我将卡片值存储为十六进制数字.这是数组:
public int[] originalCards = new int[54]
{
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D,
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
0x50, 0x51
};
Run Code Online (Sandbox Code Playgroud)
第一个数字指的是套装(1 =黑桃; 2 =俱乐部; .... 5 = Jokers)第二个数字是卡的编号(1 = ace,5 = 5; 13 = K等).
我想做类似以下的事情:
Pseudocode: …
我有一个gridview控件,带有复选框字段和几个绑定字段.复选框字段不直接映射到数据库中的字段.相反,我想从数据库中的字段读取值并"检查"一些复选框.
例如,给定数据库中的以下数据 - > datatable
PROCESSED NAME DATE
Y Mickey Mouse 11/15/2011
N Donald Duck 4/01/2012
Y James Bond 5/02/2011
我希望gridview显示一个复选框,并将框的值设置为UNCHECKED,其中PROCESSED = N,而PROCESSED = Y则具有不可编辑的复选框或根本没有复选框.
PROCESSED NAME DATE
[/] Mickey Mouse 11/15/2011
[ ] Donald Duck 4/01/2012
[/] James Bond 5/02/2011
要填充gridview,将对数据库运行SQL stmt,并将SQL查询的结果存储在数据表中.在将数据表绑定到gridview之前,我想检查"已处理"字段并根据该值设置复选框.
这是gridview控件(为清晰起见缩短了):
<asp:GridView ID="gridview_all_applicants" runat="server" AllowPaging="True">
<Columns>
<asp:TemplateField HeaderText="Complete">
<ItemTemplate>
<asp:CheckBox ID="process_flag" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="lastname" HeaderText="Last Name" ReadOnly="True" SortExpression="lastname" />
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止在代码背后的内容
SqlCommand cmd = new SqlCommand(sql query here);
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt …Run Code Online (Sandbox Code Playgroud) 我有以下内容:
foreach (string applicationName in applicationNames)
{
_uow.Applications.Add(
new Application
{
Name = applicationName,
ModifiedDate = DateTime.Now,
TestAccounts = (from testAccountName in testAccountNames
select new TestAccount
{
Name = testAccountName ,
ModifiedDate = DateTime.Now
})
});
}
Run Code Online (Sandbox Code Playgroud)
这个问题是它在选择的VS2012 IDE中给我一个错误.这里说:
Error 3 Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<Relational.Models.TestAccount>' to
'System.Collections.Generic.ICollection<Relational.Models.TestAccount>'.
An explicit conversion exists (are you missing a cast?
Run Code Online (Sandbox Code Playgroud)
这是Application类:
public partial class Application
{
public Application()
{
this.TestAccounts = new List<TestAccount>();
}
public int ApplicationId { get; set; }
public string …Run Code Online (Sandbox Code Playgroud) 我有一个CSV文件,我需要准备并验证每一行中的每个元素,并创建一个具有有效数据的类的集合.
即CSV文件看起来像:
EmpID,FirstName,LastName,Salary
1,James,Help,100000
2,Jane,Scott,1000
3,Mary,Fraze,10000
Run Code Online (Sandbox Code Playgroud)
类看起来像:
public class Employees
{
public int EmpID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Salary { get; set; }
public string ErrorReason { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以下是每个字段所需的验证:
的EmpID:
FirstName(LastName的相同验证):
薪水:
要做到这一点,这是我的方法:
所以,我的问题是,这是正确的方法,还是有任何其他更好/更清晰的方法来验证类属性.
谢谢
我试图使用函数指针实现一个简单的交换函数,但是当我将函数的地址分配给函数指针时pointersTofunctionB.c:14:6:warning: assignment from incompatible pointer type [enabled by default].以下是我的代码
#include <stdio.h>
void intSwap(int *a,int *b);
void charSwap(char *a,char *b);
void (*swap)(void*,void*);
int main(int argc, char const *argv[])
{
int a=20,b=15;
char c='j',d='H';
swap=&intSwap;// warning here
swap(&a,&b);
printf("%d %d\n",a,b);
swap=&charSwap;// warning here also
swap(&c,&d);
printf("%c %c\n",c,d );
return 0;
}
void intSwap(int *a,int *b)
{
*a=*a+*b;
*b=*a-*b;
*a=*a-*b;
}
void charSwap(char *a,char *b)
{
char temp;
temp=*a;
*a=*b;
*b=temp;
}
Run Code Online (Sandbox Code Playgroud)
如何删除此警告.有人帮我这个.
我尝试ObservableCollection使用WPF项目中的以下代码异步更新:
if (Dispatcher.Thread != Thread.CurrentThread)
{
if (Dispatcher.Thread.ThreadState != ThreadState.Stopped && !Dispatcher.Thread.IsBackground)
{
Dispatcher.Invoke(new Action(() => { ChangeCollectionByAction(action); }), null);
}
else
{
var op = Dispatcher.BeginInvoke(new Action(() => { ChangeCollectionByAction(action); }), null);
var status = op.Status;
while (status != DispatcherOperationStatus.Completed)
{
status = op.Wait(TimeSpan.FromSeconds(1));
}
}
}
Run Code Online (Sandbox Code Playgroud)
但不幸的是,状态总是等于DispatcherOperationStatus.Pending.
ps:可能是我在WinForms项目中使用ElementHost的问题?
我有一个带有list属性的模型
class myObj:
def getlist(self):
return self.list
Run Code Online (Sandbox Code Playgroud)
列表中填充了对象或实例化为空列表.
在模板中,我执行以下操作:
{% if len(myObj.list) > 0 %}
<img class="status" src="{% static "images/Check.png" %}" />
{% else %}
<img class="status" src="{% static "images/YellowWarning.png" %}" />
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我收到以下信息:
无法解析余数:来自'len(myObj.list)'的'(myObj.list)'
我究竟做错了什么?