本文整理汇总了C#中Mode.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Mode.Intersect方法的具体用法?C# Mode.Intersect怎么用?C# Mode.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mode
的用法示例。
在下文中一共展示了Mode.Intersect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChooseParameters
/// <summary>
/// Choose suitable values for Type, Version, ErrorCorrection and Mode.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private Mode ChooseParameters(string data, ErrorCorrection minimumErrorCorrection, bool allowMicroCodes)
{
// get list of error correction modes at least as good as the user-specified one
var allowedErrorCorrectionModes = new ErrorCorrection[]
{
ErrorCorrection.None,
ErrorCorrection.L,
ErrorCorrection.M,
ErrorCorrection.Q,
ErrorCorrection.H,
}.SkipWhile(e => e != minimumErrorCorrection).ToList();
// get the tightest-fit encoding mode
Mode tightestMode;
if (data.All(c => Char.IsDigit(c)))
tightestMode = Mode.Numeric;
else if (data.All(c => AlphaNumericTable.ContainsKey(c)))
tightestMode = Mode.AlphaNumeric;
else
tightestMode = Mode.Byte;
// get list of allowed encoding modes
var allowedModes = new Mode[]
{
Mode.Numeric,
Mode.AlphaNumeric,
Mode.Byte
}.SkipWhile(m => m != tightestMode).ToList();
// get list of possible types
List<Tuple<SymbolType, byte>> possibleTypes =
allowMicroCodes
? Enumerable.Concat(
Enumerable.Range(1, 4).Select(i => Tuple.Create(SymbolType.Micro, (byte)i)),
Enumerable.Range(1, 40).Select(i => Tuple.Create(SymbolType.Normal, (byte)i))).ToList()
: Enumerable.Range(1, 40).Select(i => Tuple.Create(SymbolType.Normal, (byte)i)).ToList();
// for each type in ascending order of size
foreach (var p in possibleTypes)
{
// for each error correction level from most to least
foreach (var e in allowedErrorCorrectionModes.Intersect(GetAvailableErrorCorrectionLevels(p.Item1, p.Item2)).Reverse())
{
// lookup the data capacity
var capacityEntry = DataCapacityTable.First(f => f.Item1 == p.Item1 && f.Item2 == p.Item2 && f.Item3 == e).Item4;
// for each encoding mode from tightest to loosest
foreach (var m in allowedModes.Intersect(GetAvailableModes(p.Item1, p.Item2)))
{
int capacity = 0;
switch (m)
{
case Mode.Numeric: capacity = capacityEntry.Item2; break;
case Mode.AlphaNumeric: capacity = capacityEntry.Item3; break;
case Mode.Byte: capacity = capacityEntry.Item4; break;
default: capacity = 0; break;
}
// if there is enough room, we've found our solution
if (capacity >= data.Length)
{
Type = p.Item1;
Version = p.Item2;
ErrorCorrection = e;
return m;
}
}
}
}
throw new InvalidOperationException("no suitable parameters found");
}