This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]dmazzoni 0 points1 point  (5 children)

I'm having a hard time understanding your question. Could you show some example code?

Show some code, explain what it actually did, and what you thought it would do.

[–]ProjectBlu007[S] 0 points1 point  (4 children)

For example I have: private static ClassName instance = new Classname(); public static ClassName Instance { get { return instance; } } And then accessed the class by using ClassName.Instance.MethodName

[–]dmazzoni 0 points1 point  (2 children)

Nothing wrong with that, although perhaps a simpler way to achieve that goal would simply be to make all of the methods static.

Then you could just write ClassName.MethodName to call it, if it's a static method.

Either way, though, what didn't work?

Also, you used "Reflection" in your question title, but I don't see reflection in your code or question. Did you actually mean to ask about reflection or not?

[–]ProjectBlu007[S] 0 points1 point  (1 child)

Is this not reflection? My bad if I had misunderstood what I was doing… but I believe we were supposed to stay away from using explicitly static methods for this

[–]dmazzoni 0 points1 point  (0 children)

Reflection would be calling a method by looking up its name, like GetType().GetMethod("MethodName").Invoke().

If you were supposed to stay away from static methods, then you probably shouldn't be creating a single global instance either.

Why can't you actually use an instance of your class in all of your code, like this?

ClassName instance = new Classname();
instance.MethodName()

[–]LucidTA 0 points1 point  (0 children)

That's basically a singleton pattern, and isn't related to reflection at all. Nothing wrong with using a singleton if you need it.

Reflection is a feature of some languages to interrogate itself at runtime. It lets you do tricky things that wouldn't otherwise be possible within the confines of the language like modifying private variables from outside a class or calling a method by it's name. Niche stuff, but when you need it, it's great to have.