我如何制作Class.something.function? [英] How do I make Class.something.function?

查看:84
本文介绍了我如何制作Class.something.function?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个班上工作了一段时间,我认为能够调用我计划在myClass.DoSomething.ThismyClass.DoSomething中添加的某些功能对于可用性和可读性会很好该形式代替myClass.dosomethingThismyClass.DoSomethingThat.我敢肯定,答案很简单,我只是没有运气在互联网上找到有关它的任何东西.
有任何想法吗?

I have been working off and on for a while on a class and I thought it would be nice for usablity and readability to be able to call some of the functions I am planning to add in a myClass.DoSomething.This, myClass.DoSomething.That form instead of myClass.dosomethingThis, myClass.DoSomethingThat. I''m sure the answer is pretty simple I just haven''t had any luck finding something on the internet about it.
Any ideas?

推荐答案

非常模糊的问题,但可能涉及的是琐碎的事情.

让我们来看看. myClass.DoSomething.ThismyClass.DoSomething.This.

如果myClass确实是一个类(将其重命名为MyClass),则意味着DoSomething应该是字段的静态属性(该方法将带有方括号,但名称不正确,因为它暗示了该方法,但事实并非如此.然后,MyClass.DoSomething表示某个类或结构的静态属性,该属性具有名为This的字段的另一个静态属性(再次,它是一个坏名称,因为它类似于关键字this).因此,通过使用MyClass作为类,您可以将自己与任何级别的纯静态属性或字段绑定在一起.顺便说一句,我建议将DoSomething用作方法.在这种情况下,ThisThat将是任何类型的参数(考虑:枚举,让我称之为DoingOption).只是DoSomething将是该方法的另一个重载.因此,我们将使用可能调用myClass.DoSomething()myClass.DoSomething(DoingOption.This)myClass.DoSomething(DoingOption.That)等的静态方法.

如果myClassMyClass的实例,则DoSomething可以是静态的,也可以是实例属性或字段,并且如果是静态的,则将其简化为上段所示的选项.这是实例属性还是字段,This可以是This类型的字段的静态或实例属性.我会再次建议将DoSomething用作方法,这是一次实例方法,这次是实例方法,带有一段时间的参数来传递ThisThat.

顺便说一下,请考虑实例方法或属性的工作方式(属性也是一种或两种方法-getter和setter).如果该方法是实例(非静态),则将传递给它的不可见参数"this"(就像我说的,您的名称This令人困惑!)用于携带对实例的引用.

不幸的是,所有这些都没有有趣的想法.这太琐碎了.这就是为什么您在Internet上找不到任何相关信息的原因:谁会讨论如此琐碎的内容?

也许您只是没有正确地执行您的想法,然后再考虑一下…

—SA
Very vague Question, but probably about a trivial matter.

Let''s see. myClass.DoSomething.This and myClass.DoSomething.This.

If myClass is really a class (renamed it to MyClass then) it means DoSomething should be a static property of a field (the method would have brackets, but the the name is bad, because it suggests the method, but it is not). MyClass.DoSomething then means a static property of some class or structure, which has another static property of field named This (again, a bad name as it resembles the key word this). So, by using MyClass as a class you bound yourself with static-only properties or fields at any level. By the way, I would suggest to make DoSomething a method. In this case, This and That would be parameters of any type (consider: enumeration, let me call it DoingOption). Just DoSomething would be another overload of the method. So, we''re coming to the static methods with possible calls myClass.DoSomething(), myClass.DoSomething(DoingOption.This), myClass.DoSomething(DoingOption.That), etc.

If myClass is the instance of MyClass, DoSomething can be static or instance property or field, and if it is static, it is reduced to our options shown in the above paragraph. Is this is an instance property or field, This can be either static or instance property of field of the type of This. I would again suggest the same thing with making DoSomething a method — this time the instance method, with parameters of some time to pass This or That.

By the way, consider how instance method or property work (property is also one or two methods — getter and setter). If the method is instance (non-static), it has invisible parameter "this" passed to it (as I say, your name This is confusing!) used to carry a reference to an instance.

Unfortunately, there is no interesting idea in all that; it''s too trivial. That''s why you could not find anything about it on Internet: who will discuss something it it is so trivial?

Perhaps you simply did not conduct your idea properly, then think about it some more…

—SA


这篇关于我如何制作Class.something.function?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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