public SplitSheetData Split(StyleSheet s1, StyleSheet s2, UssComments s1SrcComments = null, UssComments s2SrcComments = null) { s1Cache = new StyleSheetCache(s1); s1Comments = s1SrcComments ?? new UssComments(); s2Cache = new StyleSheetCache(s2); s2Comments = s2SrcComments ?? new UssComments(); s1Builder = new StyleSheetBuilderHelper(); s2Builder = new StyleSheetBuilderHelper(); commonBuilder = new StyleSheetBuilderHelper(); var allSelectors = new HashSet <string>(s1Cache.selectors.Keys); allSelectors.UnionWith(s2Cache.selectors.Keys); foreach (var selectorStr in allSelectors) { StyleComplexSelector complexSelector1; s1Cache.selectors.TryGetValue(selectorStr, out complexSelector1); StyleComplexSelector complexSelector2; s2Cache.selectors.TryGetValue(selectorStr, out complexSelector2); if (complexSelector1 != null) { if (complexSelector2 != null) { // Common rules, write common properties Split(complexSelector1, complexSelector2); } else { // Rules only existing in S1: copy it straight StyleSheetBuilderHelper.CopySelector(s1, s1Comments, complexSelector1, s1Builder); } } else { // Rules only existing in S2: copy it straight StyleSheetBuilderHelper.CopySelector(s2, s2Comments, complexSelector2, s2Builder); } } commonBuilder.PopulateSheet(); s1Builder.PopulateSheet(); s2Builder.PopulateSheet(); var result = new SplitSheetData { common = commonBuilder.sheet, s1 = s1Builder.sheet, s2 = s2Builder.sheet }; return(result); }