我试图在javascript中实现继承.我想出了以下最小代码来支持它.
function Base(){
this.call = function(handler, args){
handler.call(this, args);
}
}
Base.extend = function(child, parent){
parent.apply(child);
child.base = new parent;
child.base.child = child;
}
Run Code Online (Sandbox Code Playgroud)
专家,请告诉我这是否足够或我可能错过的任何其他重要问题.根据面临的类似问题,请提出其他更改建议.
这是完整的测试脚本:
function Base(){
this.call = function(handler, args){
handler.call(this, args);
}
this.superalert = function(){
alert('tst');
}
}
Base.extend = function(child, parent){
parent.apply(child);
child.base = new parent;
child.base.child = child;
}
function Child(){
Base.extend(this, Base);
this.width = 20;
this.height = 15;
this.a = ['s',''];
this.alert = function(){
alert(this.a.length);
alert(this.height);
}
}
function Child1(){
Base.extend(this, Child);
this.depth = …
Run Code Online (Sandbox Code Playgroud) 因为我们可以在SQL中编写以返回单个静态值
select "Jan" as StartMonth
Run Code Online (Sandbox Code Playgroud)
以类似的方式,SQL应该允许写入以返回同一列中的多个值
select {"Jan", "Feb", "Mar"} as Qtr1, {"Apr", "May", "Jun"} as Qtr2
Run Code Online (Sandbox Code Playgroud)
当我们需要数据作为表来执行连接并且数据在Sp级别是未知的时,即它来自参数时,创建临时表并在临时表中插入拆分值似乎是不必要的任务.如果MS SQL Server中存在此类功能,请更正我.或者更好的方法来使用除了pivot和temp表之外的其他方法.
我有一个属性,我想要在其他域中的实例.
public ModuleLoader Loader
{
get
{
if(_loader == null)
_loader = (ModuleLoader)myDomain.CreateInstanceAndUnwrap(
this.GetType().Assembly.FullName,
"ModuleLoader",
false,
System.Reflection.BindingFlags.CreateInstance,
null,
null,
null,
null);
System.Diagnostics.Debug.WriteLine("Is proxy={0}",
RemotingServices.IsTransparentProxy(_loader));
//writes false
_loader.Session = this;
return _loader;
}
}
Run Code Online (Sandbox Code Playgroud)
这很好用.但我假设_loader实例上的所有方法调用都将在其他域(myDomain)中调用.但是当我运行以下代码时,它仍然会编写主应用程序域.
public void LoadModule(string moduleAssembly)
{
System.Diagnostics.Debug.WriteLine("Is proxy={0}",
RemotingServices.IsTransparentProxy(this));
System.Diagnostics.Debug.WriteLine(
AppDomain.CurrentDomain.FriendlyName);
System.Diagnostics.Debug.WriteLine("-----------");
}
Run Code Online (Sandbox Code Playgroud)
是因为Unwrap()?我在哪里做错了?
我知道AppDomain会创建单独的内存.我需要的是我的主应用程序运行,它在不同的AppDomain中加载模块.由于主应用程序还希望观看模块的一些活动以及与在单独域中运行的对象进行交互,因此实现它的最佳方法是什么.
我有一个接口IServiceInfo和一个抽象类ServiceInfo.有几个继承自ServiceInfo的类,如CoreServiceInfo,ModuleServiceInfo等.有一个名为RootService的服务契约,它返回IServiceInfo.
public IServiceInfo GetServiceInfo()
{
return (IServiceInfo)new CoreServiceInfo();
}
Run Code Online (Sandbox Code Playgroud)
我有序列化问题.我可以使用ServiceKnownType来标识基类,使用KnownType来标识子类.
问题是我不知道所有的ServiceInfo子节点,因为应用程序可以有从ServiceInfo继承的不同子节点的插件,所以我无法告诉序列化器将序列化XML中的所有子节点.
我可以忽略抽象类,但它包含某些常见的实现,所以我需要保留它.作为一种解决方法,我可以让另一个类说"sampleServiceInfo"并将所有info类转换为sampleServiceInfo并从Service方法返回它,并将KnownType定义为ServiceInfo类.
[KnownType(typeof(sampleServiceInfo))]
public class ServiceInfo : IServiceInfo
Run Code Online (Sandbox Code Playgroud)
但这听起来并不是很好的方式.请建议.我需要编写自定义序列化程序吗?是否有任何方法只能序列化基数并忽略孩子,当两者都有相同的成员?
我有一个带有数据绑定textBox的Windows窗体,它显示如下格式的电话号码:(800)555-5555.数据以十进制形式存储,然后以正确的格式显示.问题是,当我点击textBox然后点击其他东西时,它从(800)555-5555变回8005555555.格式化丢失了.我尝试在textBox leave事件上再次重新格式化数字,但这不起作用.可能是什么导致了这个?
vs 2010 c#
首先格式化我这样做
private string FormatCustPhoneBox(string a)
{
string phone = a;
for (int j = 0; j < phone.Length; j++)
{
if (!Char.IsDigit(phone, j))
{
phone = phone.Remove(j, 1); //Remove any non numeric chars.
j--;
}
}
return phone;
}
Run Code Online (Sandbox Code Playgroud)
然后我这样做
private void FormatPhoneNum()
{
decimal iPhone = decimal.Parse(CustomerPhone1Box.Text);
CustomerPhone1Box.Text = string.Format("{0:(###) ###-####}", iPhone);
}
Run Code Online (Sandbox Code Playgroud) 这是我的班级代码.我想从过程_return()返回数据集我想将其返回给我调用过程的另一个形式.我应该使用什么样的返回类型?怎么实现呢?
public class Class1
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS2005;AttachDbFilename='C:\Users\krish\Documents\Visual Studio 2005\WebSites\TRS\App_Data\Database.mdf';Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
public void _return(String qry)
{
con.Open();
da = new SqlDataAdapter(qry, con);
da.Fill(ds, "details");
con.Close();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含几个程序集的框架.由于代码的逻辑分离,创建了多个程序集.该框架应该分发给开发人员和最终用户.开发人员应该使用少量框架程序集来开发他们的模块.但是所有其他程序集都需要运行模块.在几个程序集中,我希望只有少数程序集可以添加到项目引用中,并限制其他程序集添加到开发人员项目引用中.换句话说,我希望开发人员不应该使用程序集中包含的类型,这些类型不适用于插件开发.最好的方法是什么?我想避免将一些对象传递给那些程序集中每种类型的构造函数并验证它们.
我可以利用AppDomain或类似的东西,它标识的类型是由主应用程序或模块创建的.如果它不是主应用程序,则抛出异常或不初始化.建议对架构进行任何更改.
我正在编写一个程序,读取两个文本文件并找到差异但由于某种原因,我无法打印结果集.我检查了很多次,仍然找不到原因,我希望你们可以帮助我.这是代码.
问题出现在每个打印集合.
import java.io.*;
import java.util.*;
public class PartOne {
public static void readFileAtPath(String filePathOne, String filePathTwo) {
// Lets make sure the file path is not empty or null
if (filePathOne == null || filePathOne.isEmpty()) {
System.out.println("Invalid File Path");
return;
}
if (filePathTwo == null || filePathTwo.isEmpty()) {
System.out.println("Invalid File Path");
return;
}
Set<String> newUser = new HashSet<String>();
Set<String> oldUser = new HashSet<String>();
BufferedReader inputStream = null;
BufferedReader inputStream2 = null;
// We need a try catch block so …
Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×2
abstract ×1
appdomain ×1
asp.net ×1
dataset ×1
inheritance ×1
io ×1
java ×1
javascript ×1
plugins ×1
return ×1
sql-server ×1
wcf ×1
winforms ×1