c# - Comparing namespaces to see if they match -


I'm trying to compare namespaces to see if only in my method only throws the right exception With the right exceptions I mean the following:

  1. Exception from the same namespace.
  2. Exception from high namespace.
  3. Exception from the equivalent (and higher) system-namespace. Example:

    1. The method is in the namespace MyNamespace.Collections.Generic , so it can throw exceptions from MyNamespace.Collections.Generic .
    2. The method is in the namespace MyNamespace.Collections.Generic , so it is MyNamespace.Collections and MyNamespace .
    3. The method is in the namespace MyNamespace.Collections.Generic , so it can throw exceptions from System.Collections.Generic and System.Collections and system .

    The first section is quite easy; One part of the same name space check number 3 works; Because system namespace is always correct

    For other parts I tried the following:

      string [exceptNamespaceSegments = exceptionNamespaceSegments. Except (classNamespaceSegments) ToArray (); If (except for appointments of names, the threshold == 1 & amp; amp; amp; amp; amp; amp; amp; amp; leave; Namespace section.Other default () == "system") return;  

    What determines that the name-space-section (archive, generic) is also used in class-namespace. If this is the case, then the right exception is thrown.

    But this will not work for the case where the exception is in the namespace System.Collections.Generic.Something , because is not something class-namespace

    Come to think about it, it does not take into consideration the sequence. Then System.Generic.Collections will also be correct;

    In any way, can I write agar-statements in comparison to Segment every person?

Unless I am misinterpreting this question: you can try to do something like this , Which can find all permitted namespaces according to the norms.

  Private static IEnumerable & lt; String & gt; GetAllowedNamespaces (type type) {const string system = "system"; String thisNamespace = type.Namespace; HashSet & LT; String & gt; HashSet = New Hashet & lt; String & gt; (); Hashset.Add (thisNamespace); Hashset.Add (system); Var parts = this namespace. Lamp ('.'); If (parts.Length & gt; 1) {string previous = string.Empty; Forrest (part part) {var current = string.IsNullOrEmpty (last)? Part: string.Format ("{0}. {1}", Previous, Part); Previous = current; Hashset.Add (current); } Back = string Empty; Leading (new part [] {system} .concact (parts. Skip (1))) var current = string .isial olive (last)? Part: string.Format ("{0}. {1}", Previous, Part); Previous = current; Hashset.Add (current); }} Return hashet; }  

Then you can easily check the namespace fallout of the exception in this list, if there is no problem :)

Duplicate code is block, For a method to re-drill the principle can follow.


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 -