c# - Same extension class available in multiple namespaces -


In an MVC application I have a namespace that contains a specific model class. This class implements a specific interface and says It goes that there is an extension class in the interface.

I have expanded the model class and interface within a common namespace, however, the extension methods will not work in ideas. Expose the namespace within the ideas. In each and every view, Using a namespace that is actually going to use those extension methods is not an option. Thank you, but I have reasons to not expose my model namespace.

Keeping in mind, I was thinking of taking the extension methods to a different place of place, so I can safely highlight all of my thoughts, but now the model namespace All administrators will be missing the extension. I do not want to add this namespace to all of my controllers and this time I do not want to make this Nation place globally available. I want the extension to be usable if the model namespace is in contact with the code only.

The cheaper solution will add the same extension class (in other words, two CS files with the same code) in the two namespaces, and with it, but if possible, Would like to use

For a moment I thought I could get the extension name in another namespace, but it does not work since the stationary orbits can not inherit anything.

I also tried to use the solution, but it does not work (at least for the expansion class). I mean, I highlighted that nomenclature, which had only the extension of the scene, but in my scenes my objects did not have access to the extension methods. I had to add a dummy class to the namespace (otherwise the app will not be taken into account).

To deposit it, I have an extension class which should be available to me in two different names, what is said in other namespace, besides pasting the class, there is no way to get it?

Of course, you enter the same class Can not do, but you can produce two classes of the same code.

One way is to use T4 to create a file, which has both classes (you can not become familiar with T4.) If you use the Anti-Fake Framework, , Even if you do not know it.)

Add a text template (.tt) file to your project with a foreach with namespace, like:

  & lt; # @ Template debug = "false" hostpecific = "false" language = "c #" # & gt; & Lt; # @ Output Extension = ".cs" # # Using the system; Using System.Collections.Generic; Using System.Globalization; & Lt; # Foreach (var @namespace new in [] {"One.", "First."}} {# & Gt; Name space & lt; # = @namespace # & gt; {Public Stable Class Useful Extention {Public Fixed IEnumerable & lt; String & gt; ToTextElements (this string str) {var iter = StringInfo.GetTextElementEnumerator (str); While (iter.MoveNext ()) {yield returns iter.GetTextElement (); }}}} & Lt; #} # & Gt;  

Or you can convert the property property by changing the TextTemplatingFileGenerator and the Build Action property by changing the .t file extension.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -