还不清楚全球功能 [英] Still not clear about global functions

查看:62
本文介绍了还不清楚全球功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我花了很长时间在Google上搜索,在ASP.NET中查找有关

全局函数的信息,我仍然没有明确最好的方式

去讨论这个(或不是)。


我正在写一个仅供会员使用的网站。他们必须登录

才能访问任何页面。我在XML文件中持有用户信息

(可能永远不会有大量用户,所以

这个就足够了)。


我想要做的是有一个全局函数,我可以用来从XML文件中获取
用户设置。例如,如果我打电话给...


UserSettings(accessLevel)


然后我会获得访问级别设置目前已登录

用户(其中​​accessLevel是我放入XML文件中的内容)。


经过研究后,似乎有两个要点一遍又一遍

再次...


1)要使用全局函数,请创建一个类并在
$ b $中添加函数那边。如果它们是静态的,那么你不需要实例化这个类,

你只需要调用MyStuff.UserSettings(" accessLevel")。


2)没有全局功能,这不是OOP方式。


我遇到的问题(关于这两点)......

1)好的,所以我可以创建一个名为MyStuff.cs的文件,其中包含一个类

和静态成员。那我该怎么办呢?我想如果你是使用VS的
那么这就是你需要做的,但我正在使用文本编辑器。

我该怎么办我创建的.cs文件?似乎没有人提到这一点。


2)这样做的更好(即更多OOP)方式是什么?我非常渴望学习

正确的做事方式,但我在这里看不到。


任何建议都表示赞赏。


-

Alan Silver

(此行下方添加的任何内容都与我无关)

解决方案

1)好的,所以我可以创建一个名为MyStuff.cs的文件,其中包含一个类
和静态成员。那我该怎么办呢?我猜你是否使用VS,那就是你需要做的全部,但我正在使用文本编辑器。
当我''时,我怎么处理.cs文件我创造了吗?似乎没有人提到这一点。

2)什么是更好的(即更多的OOP)方式呢?我非常渴望学习正确的做事方式,但我在这里看不到。

任何建议都值得赞赏。

- -
Alan Silver
(这行下面添加的任何内容都与我无关)




你目前如何编译多个类文件单个程序集?

如果您不想,并且您希望使用单个文件,则可以将

类定义移动到您使用的单个文件中。 1个文件可以包含多个1

类定义:)


除此之外,我不知道如何从命令行编译而不用

研究它。这是因为,我不做,也从不需要。


HTH,


Mythran


re:

1)好的,所以我可以创建一个名为MyStuff.cs的文件,其中包含一个类和静态
成员。那我该怎么办呢?


只需打开一个命令窗口(cmd.exe);

确保.Net Framework目录在你的路径中

(.Net目录是编译器所在的位置(vbc.exe,csc.exe));

导航到您拥有.vb文件的目录,

并运行编译命令:


csc / t:library /out:MyStuff.dll MyStuff.cs


如果需要导入.Net类,在命令行中包含它们:

csc / t:library /r:system.dll /r:system.web.dll /out:MyStuff.dll MyStuff.cs

MyStuff.dll将在当前目录中创建/编译。


将其移至应用程序的/ bin目录并开火。

如果你想让VS.NET使用它,请在你的项目中引用它。


你现在可以使用
调用MyStuff.dll中的类
YourClassName.your方法,只要您将汇编导入到您的aspx文件中




<%@ Import命名空间= QUOT; YourClassname" %>


Juan T. Llibre

ASP.NET MVP
http://asp.net.do/foros/

Foros de ASP.NET en Espa?ol

Ven,y hablemos de ASP.NET ...

======================


" Alan Silver" <人********* @ nospam.thanx>在留言中写道

新闻:C6 ************** @ nospamthankyou.spam ...你好,

我花了很多年的时间拖网通过谷歌,在ASP.NET中查找有关全局
功能的信息,我仍然不清楚最好的方法(或者不是)。

我正在写一个仅供会员使用的网站。他们必须登录才能获得对任何页面的访问权限。我将用户信息保存在XML文件中(可能永远不会有大量用户,所以这很有效)。

我想做的是拥有一个我可以使用全局函数从XML文件中获取用户设置。例如,如果我打电话给...

UserSettings(" accessLevel")
那么我将获得当前登录用户的访问级别设置(其中
accessLevel是我放在XML文件中的东西。

经过研究,两个要点似乎一遍又一遍地出现......

1)要使用全局函数,请创建一个类并在其中添加函数。如果它们是静态的,那么你不需要实例化这个类,你只需要调用
MyStuff.UserSettings(accessLevel)。

2)Don'没有全局功能,它不是OOP的方式。

我遇到的问题(关于这两点)......

1)好的,所以我可以创建一个名为MyStuff.cs的文件,其中包含一个类和静态
成员。那我该怎么办呢?我想如果你使用VS,那就是你需要做的全部,但我正在使用文本编辑器。当我创建它时,如何处理.cs文件?似乎没有人提到这一点。

2)什么是更好的(即更多的OOP)方式来做到这一点?我非常渴望学习正确的做事方法,但我在这里看不到。

任何建议都赞赏。

- -
Alan Silver
(此行下方添加的任何内容与我无关)



勘误表:
< blockquote class =post_quotes>导航到您拥有.vb文件的目录,


应该是:导航到您拥有.cs文件的目录,




<%@ Import Namespace =" YourClassname" %GT;


应该是:

<%@ Import Namespace =" YourNameSpace" %GT;


对不起...


Juan T. Llibre

ASP.NET MVP
http://asp.net.do/foros/

Foros de ASP.NET en Espa?ol

Ven,y hablemos de ASP.NET ...

========= =============

Juan T. Llibre <无*********** @ nowhere.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP14.phx.gbl ... re:

1)好的,所以我可以创建一个名为MyStuff.cs的文件,其中包含一个类和静态
成员。我该怎么办?



只需打开一个命令窗口(cmd.exe);
确保.Net Framework目录在你的路径中
(.Net目录是编译器所在的位置(vbc.exe,csc.exe));
导航到您拥有.vb文件的目录,
并运行编译命令:

csc / t:library /out:MyStuff.dll MyStuff.cs

如果需要导入.Net类,请将它们包含在命令行中:
csc / t:library /r:system.dll /r:system.web.dll /out:MyStuff.dll MyStuff.cs

MyStuff.dll将在当前目录中创建/编译。将它移动到应用程序的/ bin目录并消失。
如果你想让VS.NET使用它,请在你的项目中引用它。

你现在可以使用
YourClassName.your方法调用MyStuff.dll中的类,只要您将程序集导入到您的aspx文件中:

<%@ Import Namespace =" ; YourClassname" %>

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa?ol
Ven,y hablemos de ASP.NET ...
======================

Alan Silver <人********* @ nospam.thanx>在消息中写道
新闻:C6 ************** @ nospamthankyou.spam ...

你好,

我我花了很多年的时间在谷歌上搜索,寻找有关ASP.NET中全局功能的信息,我仍然不清楚最好的方法(或者不是)。

我正在写一个仅供会员使用的网站。他们必须登录才能获得对任何页面的访问权限。我将用户信息保存在XML文件中(
可能永远不会是大量用户,所以这很有效)。

我想做的是拥有一个我可以使用全局函数从XML文件中获取用户设置。例如,如果我打电话给...

UserSettings(" accessLevel")
那么我将获得当前登录用户的访问级别设置(其中
accessLevel是我放在XML文件中的东西。

经过研究,两个要点似乎一遍又一遍地出现......

1)要使用全局函数,请创建一个类并在其中添加函数。如果它们是静态的,那么你不需要实例化这个类,你只需要调用
MyStuff.UserSettings(accessLevel)。

2)Don'没有全局功能,它不是OOP的方式。

我遇到的问题(关于这两点)......

1)好的,所以我可以创建一个名为MyStuff.cs的文件,其中包含一个类和静态
成员。那我该怎么办呢?我想如果你使用VS,那就是你需要做的全部,但我正在使用文本编辑器。当我创建它时,如何处理.cs文件?似乎没有人提到这一点。

2)什么是更好的(即更多的OOP)方式来做到这一点?我非常渴望学习正确的方法来做事,但我在这里看不到。

任何建议都值得赞赏。

- -
Alan Silver
(此行下面添加的任何内容都与我无关)




Hello,

I have spent ages trawling through Google, looking for information about
global functions in ASP.NET and I''m still not clear about the best way
to go about this (or not).

I am writing a site that will be for members only. They will have to log
in to gain access to any of the pages. I am holding the user information
in an XML file (there will probably never be a large number of user, so
this is efficient enough).

What I would like to do is have a global function that I can use to get
user settings out of the XML file. For example, if I called ...

UserSettings("accessLevel")

then I would get the access level setting for the currently logged in
user (where "accessLevel" is something I put in the XML file).

After researching this, two main points seem to come up over and over
again...

1) To use global functions, create a class and add the functions in
there. If they are static, then you don''t need to instantiate the class,
you just call MyStuff.UserSettings("accessLevel").

2) Don''t have global functions, it''s not the OOP way.

The problems I have are (in relation to these two points)...

1) OK, so I can create a file called MyStuff.cs, which contains a class
and the static members. What do I do with it then? I guess if you are
using VS, then that''s all you need to do, but I''m using a text editor.
What do I do with the .cs file when I''ve created it? No-one seems to
mention that point.

2) What''s a better (ie more OOP) way to do this? I''m very keen to learn
the right way to do things, but I can''t see one here.

Any advice appreciated.

--
Alan Silver
(anything added below this line is nothing to do with me)

解决方案

1) OK, so I can create a file called MyStuff.cs, which contains a class
and the static members. What do I do with it then? I guess if you are
using VS, then that''s all you need to do, but I''m using a text editor.
What do I do with the .cs file when I''ve created it? No-one seems to
mention that point.

2) What''s a better (ie more OOP) way to do this? I''m very keen to learn
the right way to do things, but I can''t see one here.

Any advice appreciated.

--
Alan Silver
(anything added below this line is nothing to do with me)



How do you currently compile more than 1 class file into a single assembly?
If you don''t, and you would prefer to use a single file, you can move the
class definition to the single file you use. 1 file can contain more than 1
class definition :)

Other than that, I do not know how to compile from the command line without
researching it. This is because, I don''t do it and never needed to.

HTH,

Mythran


re:

1) OK, so I can create a file called MyStuff.cs, which contains a class and the static
members. What do I do with it then?
Just open a command window ( cmd.exe );
make sure that the .Net Framework directory is in your path
( the .Net dir is where the compilers are located (vbc.exe, csc.exe));
navigate to the directory where you have your .vb files,
and run the compile command :

csc /t:library /out:MyStuff.dll MyStuff.cs

If you need to import .Net classes, include them in your command line:
csc /t:library /r:system.dll /r:system.web.dll /out:MyStuff.dll MyStuff.cs

MyStuff.dll will be created/compiled in the current directory.

Move it to the /bin directory of your application and fire away.
If you want to have VS.NET use it, reference it in your project.

You can now call the classes in MyStuff.dll using
YourClassName.yourmethod, as long as you import
the assembly into your aspx file :

<%@ Import Namespace="YourClassname" %>

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa?ol
Ven, y hablemos de ASP.NET...
======================

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:C6**************@nospamthankyou.spam... Hello,

I have spent ages trawling through Google, looking for information about global
functions in ASP.NET and I''m still not clear about the best way to go about this (or
not).

I am writing a site that will be for members only. They will have to log in to gain
access to any of the pages. I am holding the user information in an XML file (there will
probably never be a large number of user, so this is efficient enough).

What I would like to do is have a global function that I can use to get user settings
out of the XML file. For example, if I called ...

UserSettings("accessLevel")

then I would get the access level setting for the currently logged in user (where
"accessLevel" is something I put in the XML file).

After researching this, two main points seem to come up over and over again...

1) To use global functions, create a class and add the functions in there. If they are
static, then you don''t need to instantiate the class, you just call
MyStuff.UserSettings("accessLevel").

2) Don''t have global functions, it''s not the OOP way.

The problems I have are (in relation to these two points)...

1) OK, so I can create a file called MyStuff.cs, which contains a class and the static
members. What do I do with it then? I guess if you are using VS, then that''s all you
need to do, but I''m using a text editor. What do I do with the .cs file when I''ve
created it? No-one seems to mention that point.

2) What''s a better (ie more OOP) way to do this? I''m very keen to learn the right way to
do things, but I can''t see one here.

Any advice appreciated.

--
Alan Silver
(anything added below this line is nothing to do with me)



errata :

navigate to the directory where you have your .vb files,
should be : navigate to the directory where you have your .cs files,

and
<%@ Import Namespace="YourClassname" %>
Should be :
<%@ Import Namespace="YourNameSpace" %>
Sorry...


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa?ol
Ven, y hablemos de ASP.NET...
======================

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... re:

1) OK, so I can create a file called MyStuff.cs, which contains a class and the static
members. What do I do with it then?



Just open a command window ( cmd.exe );
make sure that the .Net Framework directory is in your path
( the .Net dir is where the compilers are located (vbc.exe, csc.exe));
navigate to the directory where you have your .vb files,
and run the compile command :

csc /t:library /out:MyStuff.dll MyStuff.cs

If you need to import .Net classes, include them in your command line:
csc /t:library /r:system.dll /r:system.web.dll /out:MyStuff.dll MyStuff.cs

MyStuff.dll will be created/compiled in the current directory.

Move it to the /bin directory of your application and fire away.
If you want to have VS.NET use it, reference it in your project.

You can now call the classes in MyStuff.dll using
YourClassName.yourmethod, as long as you import
the assembly into your aspx file :

<%@ Import Namespace="YourClassname" %>

Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espa?ol
Ven, y hablemos de ASP.NET...
======================

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:C6**************@nospamthankyou.spam...

Hello,

I have spent ages trawling through Google, looking for information about global
functions in ASP.NET and I''m still not clear about the best way to go about this (or
not).

I am writing a site that will be for members only. They will have to log in to gain
access to any of the pages. I am holding the user information in an XML file (there
will probably never be a large number of user, so this is efficient enough).

What I would like to do is have a global function that I can use to get user settings
out of the XML file. For example, if I called ...

UserSettings("accessLevel")

then I would get the access level setting for the currently logged in user (where
"accessLevel" is something I put in the XML file).

After researching this, two main points seem to come up over and over again...

1) To use global functions, create a class and add the functions in there. If they are
static, then you don''t need to instantiate the class, you just call
MyStuff.UserSettings("accessLevel").

2) Don''t have global functions, it''s not the OOP way.

The problems I have are (in relation to these two points)...

1) OK, so I can create a file called MyStuff.cs, which contains a class and the static
members. What do I do with it then? I guess if you are using VS, then that''s all you
need to do, but I''m using a text editor. What do I do with the .cs file when I''ve
created it? No-one seems to mention that point.

2) What''s a better (ie more OOP) way to do this? I''m very keen to learn the right way
to do things, but I can''t see one here.

Any advice appreciated.

--
Alan Silver
(anything added below this line is nothing to do with me)




这篇关于还不清楚全球功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆