Is there any performance for creating extension methods that work with an object type?
Yes. If you pass a value type, then the value type will be indicated. This creates a performance limitation when distributing the field and executing the copy, and also, of course, later, to garbage collect the box.
Instead
public static string FormatSomething(this object o) { return (o != null) ? o.ToString() : ""; }
I would write
public static string FormatSomething<T>(this T o) { return (o != null) ? o.ToString() : ""; }
This has the same effect, but avoids the penalty for boxing. Rather, he trades a penalty for a bonus for each penalty for the first penalty for jing.
Is it good in terms of performance to create all extension methods on an object?
We cannot answer the question. Give it a try! Measure productivity, compare it with the desired performance and make sure that you have reached your goal. If so, excellent. If not, use the profiler, find the slowest thing and fix it.
But not a single question is a question that you must ask. The question you should ask:
Good programming practice to create an extension method that extends everything?
No. This is almost never a good idea. In most cases, when people want to do this, they abuse the mechanism of the extension method. Typically, there is a more specific type that can be extended. If you do this a lot, then you get a lot of extension methods for each type, and the coding becomes confusing and error prone.
For example, suppose you want to have an extension method that answers the question "does this sequence contain this value?" You can write:
public static bool IsContainedIn<T>(this T item, IEnumerable<T> sequence)
and then say
if (myInt.IsContainedIn(myIntSequence))
But itβs much better to say:
public static bool Contains<T>(this IEnumerable<T> sequence, T item)
and then say
if (myIntSequence.Contains(myInt))
If you do this in the first way, then you print to the IDE, and every time you enter ".", You get a request with IsContainedIn as an option, because maybe you are going to write code that determines if this object is in collection. But in 99% of cases you will not do it. This adds noise to the instrument and makes it difficult to find what you really want.