如何在代码中引用本地方法的名称属性?

发布于 2024-11-29 10:06:04 字数 486 浏览 1 评论 0原文

我有一个缓存对象属性,我想将其设置为上下文名称中的当前类和方法,以便对哪些方法/类生成这些对象的最大频率进行一些跟踪。

我可以使用下面的代码轻松获取当前类的名称,但正在努力寻找类似的方法来从文档中收集当前方法的名称。

set obj.ClassName  = ..%ClassName(1)  //Grab class name
set obj.MethodName =                  //Need to grab the method's name here

我知道当有问题的方法设置为对象生成器时,这可以很容易地完成,但我不想走这条路。必须有一种简单的方法来引用方法的名称,对吗?

///I'd rather not do this to my methods if I don't have to.
Method MyMethod() [ CodeMode = objectgenerator ]

I have a cache object property that I'd like to set to the current class and method in context's name, in order to do some tracking on what methods/classes are generating the largest frequency of these objects.

I can easily grab the current class' name using the code below, but am struggling to find a similar method for gathering the current method's name from the documentation.

set obj.ClassName  = ..%ClassName(1)  //Grab class name
set obj.MethodName =                  //Need to grab the method's name here

I know this can be easily accomplished when the method in question is setup as an object generator, but I'd rather not go down this route.. There has to be a simple way to reference the method's name, right?

///I'd rather not do this to my methods if I don't have to.
Method MyMethod() [ CodeMode = objectgenerator ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

左秋 2024-12-06 10:06:05

在方法中没有“官方”方法可以做到这一点。

您可以使用 $stack($stack,"PLACE") 表达式来确定当前执行的代码位置。对于调试目的来说应该足够了。如果您确实需要,可以从中提取方法名称。我不建议在生产代码中使用它=)

There is no "official" way to do that in a method.

You can use the $stack($stack,"PLACE") expression to determine currently executed code position. It should be enough for debugging purposes. You may extract a method name from it if you really need. I wouldn't advise to use this in a production code though =)

月隐月明月朦胧 2024-12-06 10:06:05

对于这样的事情,我喜欢使用 %Projection 类。您可以查找有关如何执行此操作的文档,但基本思想是,当您编译一个类时,可以将其设置为生成另一个类。

如果你想扩展 Intersystem 为你提供的功能,比如知道你所在的方法(Intersystem 本身只是作弊并更改类编译器,而不创建每个人都可以使用的通用方法),你可以做一些黑客攻击,比如使用 #CurrentMethod类参数并设置投影类以在保存时将其替换为实际方法名称。

设置起来很痛苦,但是一旦完成,您就可以根据需要添加任何其他元类类型的功能。我这样做的目的与您提到的类似,以及使用一些便捷方法生成强类型结果集对象。

您还可以在从 Cache Studio 加载项调用的代码中执行相同的操作。例如,根据您编写加载项的方式,您可以从菜单项运行代码。

For things like this I like to use the %Projection classes. You can look up the documentation on how to do it, but the basic idea is that when you compile one class it can be set up to generate another.

If you want to extend what Intersystem's gives you with things like knowing what method you're in (Intersystem's itself just cheats and changes the class compiler without creating a general method everyone can use) you can do some kind of hack like having a #CurrentMethod class parameter and setting up the projection class to replace that with the actual method name on save.

This is a pain to set up, but once you are doing it you can any additional meta-class kinds of features as needed. I do this for similar purposes as you mentioned, and for generating strongly typed result set objects with some convenience methods.

You can also do the same thing in code called from a Cache Studio add-in. Depending on how you write your add-in you could run your code from a menu item, for example.

浊酒尽余欢 2024-12-06 10:06:04

有一个宏可以执行此操作:$$$CurrentMethod,在 %occIO.inc 中定义,您可以在 %SYS 中找到它,因此您不需要包含即可使用它。 $$$CurrentClass 也在那里定义。

There is a macro to do this: $$$CurrentMethod, defined within %occIO.inc, which you will find in %SYS so you don't need an include to use it. $$$CurrentClass is also defined there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文