现在的位置: 首页 > 综合 > 正文

我来读代码之三(d-podium)

2013年06月23日 ⁄ 综合 ⁄ 共 4356字 ⁄ 字号 评论关闭

1:泛型

 System.Collections.Generic

http://msdn.microsoft.com/zh-cn/library/system.collections.generic(VS.80).aspx

// type parameter T in angle brackets
public
class GenericList<T> {    
// The nested class is also generic on T
    private
class Node     {        
// T used in non-generic constructor
        public Node(T t)         {             next =
null;             data = t;         }        
private
Node next;         public Node Next         {            
get { return next; }            
set { next = value; }         }                
// T as private member data type
        private T data;        
// T as return type of property        
public
T Data          {             get {
return data; }            
set
{ data = value; }         }     }     private Node head;        
// constructor     public GenericList()     {         head =
null;     }     // T as method parameter type:    
public void AddHead(T t)     {         Node n =
new Node(t);         n.Next = head;         head = n;     }    
public IEnumerator<T> GetEnumerator()     {         Node current = head;        
while (current != null)         {             yield
return current.Data;             current = current.Next;         }     } } ——————————————————————

class TestGenericList {    
static
void Main()     {        
// int is the type argument
        GenericList<int> list =
new GenericList<int>();        
for (int x = 0; x < 10; x++)         {             list.AddHead(x);         }        
foreach (int i
in
list)         {             System.Console.Write(i +
" "
);         }         System.Console.WriteLine("/nDone");     } }

下面涉及到了反射!!!

public virtual object getValue(T t, string valueName)     {         object ret=default(object);         System.Reflection.PropertyInfo property = t.GetType().GetProperty(valueName);         if (property == null)
            return null;         ret=t.GetType().InvokeMember(valueName,System.Reflection.BindingFlags.GetProperty,null,t,new object[]{});         return ret;     }

    public virtual void setValue(T t, string valueName,string val)     {         System.Reflection.PropertyInfo property = t.GetType().GetProperty(valueName);         if (property == null)             return;        
val = "001";         t.GetType().InvokeMember(valueName, System.Reflection.BindingFlags.SetProperty, null, t, new object[] { val });     }

    public virtual object getValue(T t, string valueName)     {         object ret = default(object);         System.Reflection.MemberInfo[] member = t.GetType().GetMember(valueName);         if (member == null)
            return null;         ret = t.GetType().InvokeMember(valueName, System.Reflection.BindingFlags.GetField, null, t, new object[] { });         return ret;     }

    public virtual void setValue(T t, string valueName, string val)     {         System.Reflection.MemberInfo[] member = t.GetType().GetMember(valueName);         if (member == null)             return;        
t.GetType().InvokeMember(valueName, System.Reflection.BindingFlags.SetField, null, t, new object[] { val });     }

2:?与??

*变量定义中含有一个问号,意思是这个数据类型是NullAble类型的。
*变量定义中含有两个问号,意思是取所赋值??左边的,如果左边为null,取所赋值??右边的。

cred.adaptorName = WebConfigurationManager.AppSettings["LDAPAdaptor"] ?? "Domestic";

3:public ItemMapping(Control target, String boundproperty, String targetproperty)             : this(target, boundproperty, targetproperty, null, null)这里的:表示继承,只能用于构造函数。         {         }

        public ItemMapping(Control target, String boundproperty):this(target, boundproperty,null,null,null)         {这里的:表示继承,只能用于构造函数。         }         public ItemMapping(Control target, String boundproperty, String targetproperty, String format, ICustomFormatter
formatter)         {             if (target == null) throw new ArgumentNullException("target");             if (boundproperty == null) throw new ArgumentNullException("boundproperty");

            this.mTarget = target;             this.mBound = boundproperty;             this.mTgtProp = targetproperty;             this.mFormat = format;             this.mFormatter = formatter;         }

4:string.Format("Service
Url:{0
}", “aaabbbccc”)

相当于:"Service Url:aaabbbccc"

5:

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">             <triggers>                 <asp:AsyncPostBackTrigger ControlID="RadioButtonList1" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>                 <asp:AsyncPostBackTrigger
ControlID="Search1" EventName="Click"></asp:AsyncPostBackTrigger>                 <asp:AsyncPostBackTrigger ControlID="Search" EventName="Click"></asp:AsyncPostBackTrigger>             </triggers>         </asp:UpdatePanel>

微软自带的ajax控件:Ajax Extensions。把你所需要异步update的区域用updatepanel包起来,然后设置哪些trigger可以影响这个panel。另外还需要ScriptManager这个控件。

注意;先创建一个Ajax Website(装AJAX时会装上ScriptManager的)

6:if (lst == null) throw new ArgumentNullException("lst"); throw,哈哈!

【上篇】
【下篇】

抱歉!评论已关闭.