惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
K
Kaspersky official blog
AWS News Blog
AWS News Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News | PayPal Newsroom
S
Schneier on Security
O
OpenAI News
S
Security @ Cisco Blogs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
月光博客
月光博客
GbyAI
GbyAI
T
Tenable Blog
B
Blog
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
T
Troy Hunt's Blog
量子位
S
Security Affairs
Security Archives - TechRepublic
Security Archives - TechRepublic
The Cloudflare Blog
W
WeLiveSecurity
U
Unit 42
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The GitHub Blog
The GitHub Blog
Cloudbric
Cloudbric
A
About on SuperTechFans
Hacker News - Newest:
Hacker News - Newest: "LLM"
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Google DeepMind News
Google DeepMind News
博客园_首页
I
Intezer
P
Proofpoint News Feed
N
News and Events Feed by Topic
SecWiki News
SecWiki News
Microsoft Security Blog
Microsoft Security Blog
TaoSecurity Blog
TaoSecurity Blog
博客园 - 三生石上(FineUI控件)
NISL@THU
NISL@THU
Latest news
Latest news
H
Help Net Security
G
Google Developers Blog
博客园 - Franky
T
The Exploit Database - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary

博客园 - Andrew Yin

数据访问层组件设计以及选型意识流 第四次扩展的讨论 数据访问层组件设计以及选型意识流 第三次封装(极致、极简而不简单) 数据访问层组件设计以及选型意识流 第二次封装以及各种牢骚 数据访问层组件设计以及选型意识流 第一次封装 数据访问层组件设计以及选型意识流 开篇 UTF-8, Unicode, GB2312三种编码方式解析, 深入研究汉字编码 C++中的模板实例:链表模板 一步一步学Ruby系列(二):Ruby中的函数 一步一步学Ruby系列(一):Ruby基础知识 .NET下的AOP: PostSharp 原理分析 AST,DLR,Expression Tree-----------推荐一位牛人的博客! C# 交互式SHELL C#中的 eval System.Web.Routing命名空间代码解析(四) Route解析中用到的实体类,一些以"Segment”为名的类 System.Web.Routing命名空间代码解析(三) RouteCollection类 System.Web.Routing命名空间代码解析(二) Routing类(上) ASP.NET MVC中的各种上下文对象 有关string和Cookie的几个有用的扩展方法 反射加异步,根据枚举值来异步执行方法 操作Enum的一些实用方法
System.Web.Routing命名空间代码解析(一) RouteBase类,RouteData类,RouteValueDictionary类
Andrew Yin · 2008-12-05 · via 博客园 - Andrew Yin

1.RouteBase是一个抽象基类,定义了两个功能:

1.从HttpContextBase中根据Route Map规则得到RouteData

2.得到虚拟路径数据(将在 Route 类(下) 中讲解)

using System.Security.Permissions;
using System.Web;

namespace System.Web.Routing
{
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level 
= AspNetHostingPermissionLevel.Minimal),
     AspNetHostingPermission(SecurityAction.LinkDemand, Level 
= AspNetHostingPermissionLevel.Minimal)]
    
public abstract class RouteBase
    
{
        
// Methods

        
public abstract RouteData GetRouteData(HttpContextBase httpContext);
        
public abstract VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values);
    }

}

2. RouteData类,保存Route数据的类,提供如下功能

     1.可保存对Route和RouteHandler的引用(基类和接口)

     2.保存两个键值对,分别存储RouteValues 和用户自传入的DataToken

     3.提供一个方法从RouteValues 中读取文本值

using System;
using System.Globalization;
using System.Security.Permissions;
using System.Web;

namespace System.Web.Routing
{
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level 
= AspNetHostingPermissionLevel.Minimal),
     AspNetHostingPermission(SecurityAction.InheritanceDemand, Level 
= AspNetHostingPermissionLevel.Minimal)]
    
public class RouteData
    
{
        
// Fields
        private RouteValueDictionary _dataTokens;
        
private IRouteHandler _routeHandler;
        
private RouteValueDictionary _values;

        
// Methods
        public RouteData()
        
{
            
this._values = new RouteValueDictionary();
            
this._dataTokens = new RouteValueDictionary();
        }


        
public RouteData(RouteBase route, IRouteHandler routeHandler)
        
{
            
this._values = new RouteValueDictionary();
            
this._dataTokens = new RouteValueDictionary();
            
this.Route = route;
            
this.RouteHandler = routeHandler;
        }


        
public string GetRequiredString(string valueName)
        
{
            
object obj2;
            
if (this.Values.TryGetValue(valueName, out obj2))
            
{
                
string str = obj2 as string;
                
if (!string.IsNullOrEmpty(str))
                    
return str;
            }

            
throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture,
                                                              RoutingResources.RouteData_RequiredValue,
                                                              
new object[] {valueName}));
        }


        
// Properties
        public RouteValueDictionary DataTokens
        
{
            
get return this._dataTokens; }
        }


        
public RouteBase Route getset; }

        
public IRouteHandler RouteHandler
        
{
            
get return this._routeHandler; }
            
set this._routeHandler = value; }
        }


        
public RouteValueDictionary Values
        
{
            
get return this._values; }
        }

    }

}

3.RouteValueDictionary 类,实现了一个IDictionary<stringobject>接口,包装了一个Dictionary<stringobject>对象,其实没什么功能的,唯一的功能就是支持传入一个对象(最好是匿名类型的对象),并通过反射把它当作键值对使用,详情请看代码中加粗的部分。

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Permissions;
using System.Web;

namespace System.Web.Routing
{
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level 
= AspNetHostingPermissionLevel.Minimal),
     AspNetHostingPermission(SecurityAction.LinkDemand, Level 
= AspNetHostingPermissionLevel.Minimal)]
    
public class RouteValueDictionary : IDictionary<stringobject>
    
{
        
// Fields
        private Dictionary<stringobject> _dictionary;

        
Constructors

        
private void AddValues(object values)
        
{
            
if (values != null
)
                
foreach (PropertyDescriptor descriptor in
 TypeDescriptor.GetProperties(values))
                
{
                    
object obj2 =
 descriptor.GetValue(values);
                    
this
.Add(descriptor.Name, obj2);
                }

        }


        
public bool ContainsValue(object value)
        
{
            
return this._dictionary.ContainsValue(value);
        }


        
public Dictionary<stringobject>.Enumerator GetEnumerator()
        
{
            
return this._dictionary.GetEnumerator();
        }


        
public Dictionary<stringobject>.KeyCollection Keys
        
{
            
get return this._dictionary.Keys; }
        }


        
public Dictionary<stringobject>.ValueCollection Values
        
{
            
get return this._dictionary.Values; }
        }


        
IEnumerableKeyValuePairstring, object Members

        
IEnumerable Members

        
Implementation of ICollectionKeyValuePairstring,object

        
Implementation of IDictionarystring,object
    }

}