public void setExceptTest() { HashSet <int> first = new HashSet <int>() { 1, 2, 3 }; // TODO: 初始化为适当的值 //first.Add(1); //first.Add(2); //first.Add(3); HashSet <int> second = new HashSet <int>() { 2, 4, 5 }; // TODO: 初始化为适当的值 //first.Add(2); //first.Add(4); //first.Add(5); IList <int> expected = new List <int>() { 1, 3 }; // TODO: 初始化为适当的值 IList <int> actual; actual = HashSetUtil.setExcept(first, second); Assert.AreEqual(expected.Count, actual.Count); Assert.AreNotEqual(actual.Count, first.Count); Assert.AreNotEqual(actual.Count, second.Count); }
protected sealed override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback) { try { int num3; bool flag; bool flag2; int num4; int thresholdFromToken = this.GetThresholdFromToken(token); int ditherLevelFromToken = this.GetDitherLevelFromToken(token); HashSet <SavableBitDepths> allowedBitDepths = this.CreateAllowedBitDepthListFromToken(token); if (allowedBitDepths.Count == 0) { throw new ArgumentException("there must be at least 1 element returned from CreateAllowedBitDepthListFromToken()"); } SavableBitDepths[] items = new SavableBitDepths[] { SavableBitDepths.Rgb8, SavableBitDepths.Rgba8 }; if (allowedBitDepths.IsSubsetOf(HashSetUtil.Create <SavableBitDepths>(items))) { num3 = thresholdFromToken; } else { num3 = 1; } this.RenderFlattenedDocument(input, scratchSurface); this.Analyze(scratchSurface, out flag, out flag2, out num4); HashSet <SavableBitDepths> losslessBitDepths = new HashSet <SavableBitDepths> { SavableBitDepths.Rgba32 }; if (flag) { losslessBitDepths.Add(SavableBitDepths.Rgb24); if (num4 <= 0x100) { losslessBitDepths.Add(SavableBitDepths.Rgb8); } } else if (flag2 && (num4 < 0x100)) { losslessBitDepths.Add(SavableBitDepths.Rgba8); } double chooseBitDepthProgressLast = 0.0; ProgressEventHandler handler = delegate(object sender, ProgressEventArgs e) { chooseBitDepthProgressLast = e.Percent; progressCallback(sender, e); }; SavableBitDepths bitDepth = this.ChooseBitDepth(input, scratchSurface, ditherLevelFromToken, num3, token, handler, 0.0, 66.666666666666671, allowedBitDepths, losslessBitDepths, flag, flag2, num4); if (((bitDepth == SavableBitDepths.Rgba8) && (num3 == 0)) && (allowedBitDepths.Contains(SavableBitDepths.Rgba8) && allowedBitDepths.Contains(SavableBitDepths.Rgb8))) { bitDepth = SavableBitDepths.Rgb8; } this.FinalSave(input, output, scratchSurface, ditherLevelFromToken, num3, bitDepth, token, progressCallback, chooseBitDepthProgressLast, 100.0); } finally { } }
protected override void OnInitialized() { if (-1 != Array.IndexOf <string>(this.targetPropertyNames, this.sourcePropertyName)) { throw new ArgumentException("sourceProperty may not be in the list of targetProperties"); } HashSet <string> set = null; foreach (LinkValuesBasedOnBooleanRule <TValue, TProperty> rule in base.Owner.Rules) { if ((rule != null) && (this != rule)) { if (set == null) { set = new HashSet <string>(this.targetPropertyNames); } HashSet <string> set2 = new HashSet <string>(rule.targetPropertyNames); if (HashSetUtil.Intersect <string>(set, set2).Count != 0) { throw new ArgumentException("Cannot assign a property to be linked with more than one LinkValuesBasedOnBooleanRule instance"); } } } TProperty local = (TProperty)base.Owner[this.targetPropertyNames[0]]; foreach (string str in this.targetPropertyNames) { TProperty targetProperty = (TProperty)base.Owner[str]; if (targetProperty == null) { throw new ArgumentException("All of the target properties must be of type TProperty (" + typeof(TProperty).FullName + ")"); } if (!ScalarProperty <TValue> .IsEqualTo(targetProperty.MinValue, local.MinValue) || !ScalarProperty <TValue> .IsEqualTo(targetProperty.MaxValue, local.MaxValue)) { throw new ArgumentException("All of the target properties must have the same min/max range"); } targetProperty.ValueChanged += (s, e) => ((LinkValuesBasedOnBooleanRule <TValue, TProperty>) this).OnTargetPropertyValueChanged(targetProperty, e.Value); } BooleanProperty sourceProperty = (BooleanProperty)base.Owner[this.sourcePropertyName]; sourceProperty.ValueChanged += (s, e) => ((LinkValuesBasedOnBooleanRule <TValue, TProperty>) this).OnSourcePropertyValueChanged(sourceProperty, e.Value); this.Sync(); }
internal SavableBitDepths ChooseBitDepth(Document input, Surface scratchSurface, int ditherLevel, int threshold, PropertyBasedSaveConfigToken token, ProgressEventHandler progressCallback, double progressStart, double progressEnd, HashSet <SavableBitDepths> allowedBitDepths, HashSet <SavableBitDepths> losslessBitDepths, bool allOpaque, bool all0Or255Alpha, int uniqueColorCount) { if (allowedBitDepths.Count == 0) { throw new ArgumentException("Count must be 1 or more", "allowedBitDepths"); } try { HashSet <SavableBitDepths> set2; if (allowedBitDepths.Count == 1) { return(allowedBitDepths.First <SavableBitDepths>()); } HashSet <SavableBitDepths> source = HashSetUtil.Intersect <SavableBitDepths>(allowedBitDepths, losslessBitDepths); if (source.Count == 1) { return(source.First <SavableBitDepths>()); } if (source.Count == 0) { set2 = allowedBitDepths; } else { set2 = source; } long num = input.Width * input.Height; if (((all0Or255Alpha && (uniqueColorCount <= 0xff)) && ((num <= 0x10000L) && set2.Contains(SavableBitDepths.Rgb8))) && set2.Contains(SavableBitDepths.Rgb24)) { long num2 = 0L; long num3 = 0L; try { num2 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgb8, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 0.0, 50.0); num3 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgb24, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 50.0, 100.0); } catch (OutOfMemoryException) { return(SavableBitDepths.Rgb8); } if (num2 < num3) { return(SavableBitDepths.Rgb8); } return(SavableBitDepths.Rgb24); } if (((all0Or255Alpha && (uniqueColorCount <= 0xff)) && ((num < 0x10000L) && set2.Contains(SavableBitDepths.Rgba8))) && set2.Contains(SavableBitDepths.Rgba32)) { long num4 = 0L; long num5 = 0L; try { num4 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgba8, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 0.0, 50.0); num5 = this.GetSavableBitDepthFileLength(SavableBitDepths.Rgba32, input, scratchSurface, ditherLevel, threshold, token, progressCallback, 50.0, 100.0); } catch (OutOfMemoryException) { return(SavableBitDepths.Rgba8); } if (num4 < num5) { return(SavableBitDepths.Rgba8); } return(SavableBitDepths.Rgba32); } if ((set2.Contains(SavableBitDepths.Rgb8) & allOpaque) && (uniqueColorCount <= 0x100)) { return(SavableBitDepths.Rgb8); } if ((set2.Contains(SavableBitDepths.Rgba8) & all0Or255Alpha) && (uniqueColorCount <= 0xff)) { return(SavableBitDepths.Rgba8); } if (!(set2.Contains(SavableBitDepths.Rgb24) & allOpaque)) { if (set2.Contains(SavableBitDepths.Rgba32)) { return(SavableBitDepths.Rgba32); } SavableBitDepths[] items = new SavableBitDepths[] { SavableBitDepths.Rgb8, SavableBitDepths.Rgb24 }; if (set2.SetEquals(HashSetUtil.Create <SavableBitDepths>(items))) { return(SavableBitDepths.Rgb24); } SavableBitDepths[] depthsArray2 = new SavableBitDepths[] { SavableBitDepths.Rgb8, SavableBitDepths.Rgba8 }; if (set2.SetEquals(HashSetUtil.Create <SavableBitDepths>(depthsArray2))) { return(SavableBitDepths.Rgba8); } SavableBitDepths[] depthsArray3 = new SavableBitDepths[] { SavableBitDepths.Rgba8, SavableBitDepths.Rgb24 }; if (!set2.SetEquals(HashSetUtil.Create <SavableBitDepths>(depthsArray3))) { throw new ArgumentException("Could not accomodate input values -- internal error?"); } } return(SavableBitDepths.Rgb24); } finally { } }