したがって、2つの関数があり、興味深い問題が発生しています。基本的に、簡単にインクルードできるcsファイルでコードの移植性を高めることを目指しています。
これがcsファイルです:
namespace basicFunctions {
public partial class phpPort : System.Web.UI.Page {
public string includer(string filename) {
string path = Server.MapPath("./" + filename);
string content = System.IO.File.ReadAllText(path);
return content;
}
public void returnError() {
Response.Write("<h2>An error has occurred!</h2>");
Response.Write("<p>You have followed an incorrect link. Please double check and try again.</p>");
Response.Write(includer("footer.html"));
Response.End();
}
}
}
これを参照しているページは次のとおりです。
<% @Page Language="C#" Debug="true" Inherits="basicFunctions.phpPort" CodeFile="basicfunctions.cs" %>
<% @Import Namespace="System.Web.Configuration" %>
<script language="C#" runat="server">
void Page_Load(object sender,EventArgs e) {
Response.Write(basicFunctions.phpPort.includer("header.html"));
//irrelevant code
if ('stuff happens') {
basicFunctions.phpPort.returnError();
}
Response.Write(basicFunctions.phpPort.includer("footer.html"));
}
</script>
私が得ているエラーは、上記のエラーです。
Compiler Error Message: CS0120: An object reference is required for the non-static field, method, or property 'basicFunctions.phpPort.includer(string)'