Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't had much time to look at this or refactor my code so this is more of a brain dump but might be a good place to start and refactor into something a little neater!</p> <pre><code>public class StrongFileType { private string _friendlyName = string.Empty; public StrongFileType(string friendlyName) { _friendlyName = friendlyName; } public IEnumerable&lt;StrongFileType&gt; CompatibleTypes { get; set; } public override string ToString() { return _friendlyName; } } private void SampleTest() { // The possible types var typeA = new StrongFileType("A"); var typeB = new StrongFileType("B"); var typeC = new StrongFileType("C"); var typeD = new StrongFileType("D"); var typeE = new StrongFileType("E"); // Setup possible compatible types typeA.CompatibleTypes = new List&lt;StrongFileType&gt; { typeA, typeB, typeC, typeD }; typeB.CompatibleTypes = new List&lt;StrongFileType&gt; { typeA, typeB, typeC }; typeC.CompatibleTypes = new List&lt;StrongFileType&gt; { typeA, typeB, typeC, typeD }; typeD.CompatibleTypes = new List&lt;StrongFileType&gt; { typeA, typeC, typeD, typeE }; typeE.CompatibleTypes = new List&lt;StrongFileType&gt; { typeD, typeE }; // Now do a check... var userSubmittedFilesValid = new List&lt;StrongFileType&gt; { typeA, typeB, typeC }; CheckCompatible(userSubmittedFilesValid); var userSubmittedFilesInvalid = new List&lt;StrongFileType&gt; { typeA, typeB, typeC, typeD }; CheckCompatible(userSubmittedFilesInvalid); } private bool CheckCompatible(IEnumerable&lt;StrongFileType&gt; requestedFiles) { // Useful for debugging var validList = new List&lt;string&gt;(); var invalidList = new List&lt;string&gt;(); foreach (StrongFileType fileType in requestedFiles) { string invalid = string.Empty; string validCombination = string.Empty; foreach (StrongFileType fileTypeToCheck in requestedFiles) { if (!fileType.CompatibleTypes.Contains(fileTypeToCheck)) { // Show as not compatible and remove any previously valid combinations that match invalid += string.Format("{0} not compatible with {1}", fileType, fileTypeToCheck); validList.RemoveAll(x =&gt; x.Contains(fileType.ToString()) &amp;&amp; x.Contains(fileTypeToCheck.ToString())); } else { validCombination += string.Format("{0}", fileTypeToCheck); } } // Add to respective lists if (!string.IsNullOrEmpty(validCombination) &amp;&amp; !validList.Contains(validCombination)) { validList.Add(validCombination); } if (!string.IsNullOrEmpty(invalid)) { invalidList.Add(invalid); } } // Was valid? return invalidList.Count == 0; } </code></pre> <p>This should result with the first one showing VALID list of ABC and INVALID list is empty. Second one should show ABC and ACD as VALID and BD and DB as INVALID.</p> <p>Sorry I didn't have more time to tidy it up!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload