Sipo Blog

宁静致远

X-UA-Compatible之chrome=1

<meta http-equiv="X-UA-Compatible" content="chrome=1">

Google这招走的不错。cf:什么的是点缀。这个meta X-UA-Compatible才是主菜啊。这不是阴损,这是明斗。哇哈哈。
X-UA-Compatible 是仅支持IE8的。过不了多久你就会发现,网上有百分之XX的网页上加了这句话。
嗯。如果,Google Frame再绑定一个什么迅雷,QQ之类的。哇咔,以后打开IE8,会发现突然变快了,还不知怎么回事呢,原来是Chrome的功劳呀。不错,好棋。

Mutantic Assignment

尝试在C#3.0中用扩展方法模拟突变赋值功能:

public static class Mutant
{
    
public static void  MAssign(this object target, object source)
    {
        
foreach (PropertyInfo pi1 in source.GetType().GetProperties())
        {
            
if (!pi1.CanRead) continue;

            PropertyInfo pi2 
= target.GetType().GetProperty(pi1.Name, pi1.PropertyType);

            
if (null == pi2 || !pi2.CanWrite) continue;

            pi2.SetValue(target, pi1.GetValue(source, 
null), null);
        }
    }
}

 

上面对object类定义了MAssign扩展方法,通过反射获取和设置属性值模拟突变赋值。这样,我们就可以对任意对象进行突变赋值了:

form.MAssign(new {Text = “Hello World”, Top = 100, Left = 200});

Jquery的扩展


该示例用以在JQuery中增加新函数,该函数是静态函数。

$.extend({
max: function(a, b) {
return a > b ? a : b;
},
min: function(a, b) {
return a > b ? b : a;
},
avg: function(a, b) {
return a / b;
}
});

调用如下:

jQuery.min(2,3); // => 2
jQuery.max(4,5); // => 5

如果针对组件的功能扩展函数:

$.fn.hightlight = function(colorName) {
this.mouseover(function() {
$(this).css('background-color', colorName); //this对是对组件自身的引用
});
this.mouseout(function() {
$(this).css('background-color', '');
});
}
调用如下:

$(function() {
$('#test').hightlight('red');
});

本文属于转载+修改

.NET 扩展

class Command
{
    public virtual void Execute() { }
}

class InvalidOperationException<T> : InvalidOperationException
    where T : Command
{
    public InvalidOperationException(string message) : base(message) { }
    // some specific information about
    // the command type T that threw this exception
}

static class CommandExtensions
{
    public static void ThrowInvalidOperationException<TCommand>(
        this TCommand command, string message) 
        where TCommand : Command
    {
        throw new InvalidOperationException<TCommand>(message);
    }
}

class CopyCommand : Command
{
    public override void Execute()
    {
        // after something went wrong:
        this.ThrowInvalidOperationException("Something went wrong");
    }
}

class CutCommand : Command
{
    public override void Execute()
    {
        // after something went wrong:
        this.ThrowInvalidOperationException("Something else went wrong");
    }
}

把VBScript的函数迁移到C#.NET

Migrates from VBScript Functions to C#
ASP2ASPX can migrate from the VBScript functions to C#, but some vbscript functions are not implemented in C#. So Microsoft.VisualBasic.dll should be referenced(you can copy Microsoft.VisualBasic.dll to the /bin directory of your ASP.NET project).

Please see following table that lists VBScript and C# codes:

Using Internet Explorer from .NET

Using Internet Explorer from .NET
5.0         Introduction
Earlier in this book we have looked at how to read HTML from websites, and how to navigate through websites using GET and POST requests. These techni...

Ajax!!

DRUNK DREAM 看到了解决XNA速度问题的又一剂良方。

要好好研究如何应用!

[数据结构]二叉树的前序中序后序遍历

私人文章,登录状态下方可查看。

CSS技巧/CSS缩写语法

CSS技巧/CSS缩写语法

WEB标准

WEB标准
«123»

Powered By Z-Blog 1.8 Walle Build 100427
Copyright Sipo.