....貌似不行, 把原文件发上来吧... 我想在 gallery.cs 中调用 a.csgallery.cs using System; using System.Web; using System.IO; using System.Text.RegularExpressions; //a t=new a();/*-----------------------------------------------------------------------------------*\ * shawl.qiu c# .net Gallery class v1.0 \*-----------------------------------------------------------------------------------*/ //---------------------------------------------------------------------begin class Gallery public class Gallery { //-----------------------------------begin event public Gallery() { }
//-----------------------------------begin public constant //-----------------------begin about public const String auSubject="shawl.qiu c# .net Gallery class"; public const String auVersion="v1.0"; public const String au="shawl.qiu"; public const String auEmail="[email protected]"; public const String auBlog="http://blog.csdn.net/btbtd"; public const String auCreateDate="2007-2-5"; //-----------------------end about //-----------------------------------end public constant
//-----------------------------------begin public variable public String Path="/images/"; public String ThumbFolder="thumb"; public String ShowExtension=".jpg|.jpeg|.gif|.png"; //public Strin //-----------------------------------end public variable
//-----------------------------------begin public method public void Go() { //--------------------------------检测指定的图片路径是否存在 Path_Phs=System.Web.HttpContext.Current.Server.MapPath(Path); if(!Path_Phs.EndsWith("\\")) { Path_Phs+="\\"; } if(!Directory.Exists(Path_Phs)) { System.Web.HttpContext.Current.Response.Write(WordGallery.PathNotExists); PathExists=false; goto End; }
//-----------------------------------begin public property //-----------------------------------end public property
//-----------------------------------begin private property //-----------------------------------end private property } //---------------------------------------------------------------------end class Gallerypublic class WordGallery { public static String PathNotExists="<h2>指定的路径不存在, 操作被终止...</h2>"; }
a.csusing System; //System.Web.HttpContext.Current.Response.Write("");/*-----------------------------------------------------------------------------------*\ * shawl.qiu class v \*-----------------------------------------------------------------------------------*/ //---------------------------------------------------------------------begin class a public class a { //-----------------------------------begin event public a() { }
//-----------------------------------begin public constant //-----------------------begin about public const String auSubject=""; public const String auVersion="v1.0"; public const String au="shawl.qiu"; public const String auEmail="[email protected]"; public const String auBlog="http://blog.csdn.net/btbtd"; public const String auCreateDate="2007-1-25"; //-----------------------end about //-----------------------------------end public constant
//-----------------------------------begin public property //-----------------------------------end public property
//-----------------------------------begin private property //-----------------------------------end private property } //---------------------------------------------------------------------end class a
我想在 gallery.cs 中调用 a.csgallery.cs
using System;
using System.Web;
using System.IO;
using System.Text.RegularExpressions;
//a t=new a();/*-----------------------------------------------------------------------------------*\
* shawl.qiu c# .net Gallery class v1.0
\*-----------------------------------------------------------------------------------*/
//---------------------------------------------------------------------begin class Gallery
public class Gallery
{
//-----------------------------------begin event
public Gallery()
{
}
~Gallery()
{
}
//-----------------------------------end event
//-----------------------------------begin public constant
//-----------------------begin about
public const String auSubject="shawl.qiu c# .net Gallery class";
public const String auVersion="v1.0";
public const String au="shawl.qiu";
public const String auEmail="[email protected]";
public const String auBlog="http://blog.csdn.net/btbtd";
public const String auCreateDate="2007-2-5";
//-----------------------end about
//-----------------------------------end public constant
//-----------------------------------begin private constant
//-----------------------------------end private constant
//-----------------------------------begin public static method
//-----------------------------------end public static method
//-----------------------------------begin private static method
//-----------------------------------end private static method
//-----------------------------------begin public variable
public String Path="/images/";
public String ThumbFolder="thumb";
public String ShowExtension=".jpg|.jpeg|.gif|.png";
//public Strin
//-----------------------------------end public variable
//-----------------------------------begin public method
public void Go()
{
//--------------------------------检测指定的图片路径是否存在
Path_Phs=System.Web.HttpContext.Current.Server.MapPath(Path);
if(!Path_Phs.EndsWith("\\"))
{
Path_Phs+="\\";
}
if(!Directory.Exists(Path_Phs))
{
System.Web.HttpContext.Current.Response.Write(WordGallery.PathNotExists);
PathExists=false;
goto End;
}
//--------------------------------设置 缩略图 文件夹
ThumbFolder_Phs=Path_Phs+ThumbFolder;
if(!ThumbFolder_Phs.EndsWith("\\"))
{
ThumbFolder_Phs+="\\";
}
if(!Directory.Exists(ThumbFolder_Phs))
{
Directory.CreateDirectory(ThumbFolder_Phs);
}
//---------------------------------遍历指定目录所有文件
String[] CurrentPathFiles=Directory.GetFiles(Path_Phs);
for(Int32 i=0, j=CurrentPathFiles.Length; i<j; i++)
{
String path=CurrentPathFiles[i];
String ext=System.IO.Path.GetExtension(path)+"";
//--------------------------------检测是否显示该类型
if(RegexTest(ShowExtension, ext))
{
String fileName=System.IO.Path.GetFileName(path);
String thumbFileName=ThumbFolder_Phs+fileName;
// 缩略图文件夹不存在某文件的缩略图
if(!File.Exists(thumbFileName))
{
System.Web.HttpContext.Current.Response.Write("<li/>file not exists");
}
}
} // end for
End:;
}
//-----------------------------------end public method
//-----------------------------------begin private variable
private String Path_Phs="";
private Boolean PathExists=true;
private String ThumbFolder_Phs="";
//-----------------------------------end private variable
//-----------------------------------begin private method
private Boolean RegexTest(String input, String pattern)
{
if(Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase))
{
return true;
}
return false;
}
//-----------------------------------end private method
//-----------------------------------begin public property
//-----------------------------------end public property
//-----------------------------------begin private property
//-----------------------------------end private property
}
//---------------------------------------------------------------------end class Gallerypublic class WordGallery
{
public static String PathNotExists="<h2>指定的路径不存在, 操作被终止...</h2>";
}
//System.Web.HttpContext.Current.Response.Write("");/*-----------------------------------------------------------------------------------*\
* shawl.qiu class v
\*-----------------------------------------------------------------------------------*/
//---------------------------------------------------------------------begin class a
public class a
{
//-----------------------------------begin event
public a()
{
}
~a()
{
}
//-----------------------------------end event
//-----------------------------------begin public constant
//-----------------------begin about
public const String auSubject="";
public const String auVersion="v1.0";
public const String au="shawl.qiu";
public const String auEmail="[email protected]";
public const String auBlog="http://blog.csdn.net/btbtd";
public const String auCreateDate="2007-1-25";
//-----------------------end about
//-----------------------------------end public constant
//-----------------------------------begin private constant
//-----------------------------------end private constant
//-----------------------------------begin public static method
//-----------------------------------end public static method
//-----------------------------------begin private static method
//-----------------------------------end private static method
//-----------------------------------begin public variable
//-----------------------------------end public variable
//-----------------------------------begin public method
//-----------------------------------end public method
//-----------------------------------begin private variable
//-----------------------------------end private variable
//-----------------------------------begin private method
//-----------------------------------end private method
//-----------------------------------begin public property
//-----------------------------------end public property
//-----------------------------------begin private property
//-----------------------------------end private property
}
//---------------------------------------------------------------------end class a
动态编译 .Net中有类实现
参见using System.CodeDom.Compiler;
具体可以去CodeProject找