App_Code/Sections/SectionLoader.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
//===============================================================================================
//
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
//
//===============================================================================================
using System;
using System.Reflection;
using System.IO;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace MyWebPagesStarterKit
{
/// <summary>
/// Utility class to load sections independent of their type. Implemented as singleton.
/// </summary>
public class SectionLoader
{
private static SectionLoader _instance;
private SectionLoader() { }
public static SectionLoader GetInstance()
{
if (_instance == null)
_instance = new SectionLoader();
return _instance;
}
/// <summary>
/// Searches through the whole App_Data folder for the given section and tries to create a instance of ISection with the found data.
/// </summary>
/// <param name="id">SectionId</param>
/// <returns>ISection</returns>
public ISection LoadSection(string id)
{
//looks for all files matching {id}.config in the App_Data directory
string[] files = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/App_Data"), string.Format("{0}.config", id), SearchOption.AllDirectories);
if (files.Length != 0)
{
//As the directories for the sections are named like the class-names of their corresponding section, the type of the section can be acquired by using the directory-name.
//after the next two lines, dir contains the type-name of the section for which the data-file was found.
string dir = Path.GetDirectoryName(files[0]);
dir = "MyWebPagesStarterKit." + dir.Substring(dir.LastIndexOf("\\") + 1);
try
{
//here we try to create a instance of the type-name contained in the variable "dir" and return it as ISection.
return (ISection)Activator.CreateInstance(this.GetType().Assembly.GetType(dir), id);
}
后面还有 12 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
