/// <summary> /// Returns the keyword for the provided accessibility level /// </summary> /// <param name="accessibilityLevel"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static string AccessibilityLevelKeyword(AccessibilityLevel accessibilityLevel) { switch (accessibilityLevel) { case AccessibilityLevel.Public: return("Public"); case AccessibilityLevel.Protected: return("Protected"); case AccessibilityLevel.Internal: return("Friend"); case AccessibilityLevel.ProtectedInternal: return("Protected Friend"); case AccessibilityLevel.Private: return("Private"); case AccessibilityLevel.PrivateProtected: return("Private Protected"); default: throw new ArgumentOutOfRangeException(nameof(accessibilityLevel), accessibilityLevel, null); } }
/// <summary> /// Returns the type attribute visibility flag for the correponding accessibility level /// </summary> /// <param name="accessibilityLevel"></param> /// <returns></returns> public static TypeAttributes GetTypeAttribute(this AccessibilityLevel accessibilityLevel) { switch (accessibilityLevel) { case AccessibilityLevel.Public: return(TypeAttributes.Public); case AccessibilityLevel.Protected: return(TypeAttributes.NestedFamily); case AccessibilityLevel.ProtectedInternal: return(TypeAttributes.NestedFamORAssem); case AccessibilityLevel.Private: return(TypeAttributes.NestedPrivate); case AccessibilityLevel.PrivateProtected: return(TypeAttributes.NestedFamANDAssem); case AccessibilityLevel.Internal: case AccessibilityLevel.Default: return(TypeAttributes.NotPublic); default: throw new ArgumentOutOfRangeException(nameof(accessibilityLevel), accessibilityLevel, null); } }
public void AccessibiltyTests( ModeSaveData mode, RequirementType type, AccessibilityLevel expected) { Mode.Instance.Load(mode); Assert.Equal(expected, RequirementDictionary.Instance[type].Accessibility); }
private void WriteMethodStart(AccessibilityLevel level, bool isOverride, string returnTypeName, string methodName, string parameterListValue) { // Apply indentation. _sourceBuilder.Append(new string(' ', _indent * 4)); if (level == AccessibilityLevel.Public) { _sourceBuilder.Append("public"); } _sourceBuilder.Append(" "); if (isOverride) { _sourceBuilder.Append("override"); _sourceBuilder.Append(" "); } _sourceBuilder.Append(returnTypeName); _sourceBuilder.Append(" "); _sourceBuilder.Append(methodName); _sourceBuilder.Append("("); _sourceBuilder.Append(parameterListValue); _sourceBuilder.Append(")"); MoveToNewLine(); WriteControlBlockStart(); }
public void Max_TwoValueTests( AccessibilityLevel a1, AccessibilityLevel a2, AccessibilityLevel expected) { AccessibilityLevel actual = AccessibilityLevelMethods.Max(a1, a2); Assert.Equal(expected, actual); }
/// <summary> /// Constructor /// </summary> /// <param name="bossAccessibility"> /// A list of accessibility of each boss. /// </param> /// <param name="accessibility"> /// The accessibility level of the dungeon items. /// </param> /// <param name="accessible"> /// The number of accessible items. /// </param> public DungeonResult( List <AccessibilityLevel> bossAccessibility, AccessibilityLevel accessibility, int accessible) { BossAccessibility = bossAccessibility; Accessibility = accessibility; Accessible = accessible; }
public void Min_ThreeValueTests( AccessibilityLevel a1, AccessibilityLevel a2, AccessibilityLevel a3, AccessibilityLevel expected) { AccessibilityLevel actual = AccessibilityLevelMethods.Min(a1, a2, a3); Assert.Equal(expected, actual); }
public void AccessibilityTests(RequirementType type, AccessibilityLevel expected) { var container = ContainerConfig.Configure(); using var scope = container.BeginLifetimeScope(); var requirements = scope.Resolve <IRequirementDictionary>(); Assert.Equal(expected, requirements[type].Accessibility); }
public static BindingFlags GetMethodBindingFlags(AccessibilityLevel accessibilityLevel) { switch (accessibilityLevel) { case AccessibilityLevel.All: return(BaseBindingFlags() | BindingFlags.NonPublic | BindingFlags.InvokeMethod); case AccessibilityLevel.PublicOnly: return(BaseBindingFlags() | BindingFlags.InvokeMethod); default: throw new InvalidOperationException("Unknown AccessibilityLevel"); } }
public void Tests( ModeSaveData mode, RequirementNodeID[] accessibleNodes, RequirementNodeID id, AccessibilityLevel expected) { Mode.Instance.Load(mode); RequirementNodeDictionary.Instance.Reset(); foreach (var node in accessibleNodes) { RequirementNodeDictionary.Instance[node].AlwaysAccessible = true; } Assert.Equal(expected, RequirementNodeDictionary.Instance[id].Accessibility); }
public void AccessibilityTests(int towerCrystals, int crystals, int redCrystals) { ItemDictionary.Instance.Reset(); PrizeDictionary.Instance.Reset(); ItemDictionary.Instance[ItemType.TowerCrystals].Current = towerCrystals; PrizeDictionary.Instance[PrizeType.Crystal].Current = crystals; PrizeDictionary.Instance[PrizeType.RedCrystal].Current = redCrystals; AccessibilityLevel expected = towerCrystals + crystals + redCrystals >= 7 ? AccessibilityLevel.Normal : AccessibilityLevel.None; Assert.Equal( expected, RequirementDictionary.Instance[RequirementType.GTCrystal].Accessibility); }
/// <inheritdoc /> public bool Handle(TypeAttributes obj, Context ctx) { AccessibilityLevel accessLevel = AccessibilityLevel.Default; try { accessLevel = obj.GetAccessibilityLevel(); } catch (ArgumentOutOfRangeException) { if (ctx.Options.DoConsistencyChecks) { throw new ConsistencyException("Invalid type attributes"); } } if (accessLevel != AccessibilityLevel.Default) { ctx.Writer.Write(GetAccessibilityLevelKeyword(accessLevel, ctx)); ctx.Writer.Write(" "); } if (ctx.CurrentDeclarationType == DeclarationType.Class) { if ((obj & TypeAttributes.Sealed) != 0 && (obj & TypeAttributes.Abstract) != 0 && ctx.Options.DoConsistencyChecks) { throw new ConsistencyException("A class can't be both sealed and abstract"); } if ((obj & TypeAttributes.Sealed) != 0) { if (!string.IsNullOrEmpty(GetSealedKeyword(ctx))) { ctx.Writer.Write(GetSealedKeyword(ctx) + " "); } } if ((obj & TypeAttributes.Abstract) != 0) { if (!string.IsNullOrEmpty(GetAbstractKeyword(ctx))) { ctx.Writer.Write(GetAbstractKeyword(ctx) + " "); } } } return(true); }
public override string ToString() { // TODO ADD TESTS FOR MULTIPLE TO STRING SCENARIOS StringBuilder sb = new StringBuilder(); if (!AccessibilityLevel.Equals(SGAccessibilityLevel.None)) { sb.Append($"{AccessibilityLevel} "); } if (IsStatic) { sb.Append("static "); } if (IsAsync) { sb.Append("async "); } if (IsOverride) { sb.Append("override "); } sb.Append($"{ReturnType} {MethodName}"); if (IsGeneric && GenericTypeNames.Count > 0) { sb.Append("<"); sb.Append(String.Join(", ", GenericTypeNames)); sb.Append(">"); } sb.Append(" ("); sb.Append(String.Join(", ", Arguments.Select(x => x.ToString()))); sb.Append(")"); return(sb.ToString()); }
public static bool IsPrivate(this AccessibilityLevel accessibility) => accessibility is AccessibilityLevel.Private;
/// <summary> /// Returns the accessibility level keyword for the provided accessibility level or null /// </summary> /// <param name="accessibilityLevel"></param> /// <param name="ctx"></param> /// <returns></returns> protected abstract string GetAccessibilityLevelKeyword(AccessibilityLevel accessibilityLevel, Context ctx);
/// <inheritdoc /> protected override string GetAccessibilityLevelKeyword(AccessibilityLevel accessibilityLevel, Context ctx) { return(VisualBasicKeywordsUtils.AccessibilityLevelKeyword(accessibilityLevel)); }
public static bool IsProtected(this AccessibilityLevel accessibility) => accessibility is AccessibilityLevel.Protected || accessibility is AccessibilityLevel.Private_Protected;
public AccessibilitySettings(AccessibilityLevel level, AccessibilityGuidelinesVersion version) { Level = level; GuidelinesVersion = version; }
public static bool IsPotentiallyInternal(this AccessibilityLevel accessibility) => accessibility is AccessibilityLevel.Internal || accessibility is AccessibilityLevel.Protected_Internal || accessibility is AccessibilityLevel.Private_Protected;
/// <summary> /// Updates the accessibility and number of accessible items for the contained sections /// using parallel operation. /// </summary> private void UpdateSectionAccessibilityParallel() { var keyDoorPermutationQueue = new List <BlockingCollection <(List <KeyDoorID>, int, bool, bool)> >(); var keyDoorTasks = new List <Task[]>(); var finalKeyDoorPermutationQueue = new BlockingCollection <(List <KeyDoorID>, int, bool, bool)>(); var resultQueue = new BlockingCollection < (List <AccessibilityLevel>, AccessibilityLevel, int, bool)>(); for (int i = 0; i <= SmallKeyDoors.Count; i++) { keyDoorPermutationQueue.Add( new BlockingCollection <(List <KeyDoorID>, int, bool, bool)>()); } List <int> smallKeyValues = GetSmallKeyValues(); List <bool> bigKeyValues = GetBigKeyValues(); foreach (int smallKeyValue in smallKeyValues) { foreach (bool bigKeyValue in bigKeyValues) { keyDoorPermutationQueue[0].Add( (new List <KeyDoorID>(), smallKeyValue, bigKeyValue, false)); } } keyDoorPermutationQueue[0].CompleteAdding(); for (int i = 0; i < keyDoorPermutationQueue.Count; i++) { int currentIteration = i; keyDoorTasks.Add(Enumerable.Range(1, Math.Max(1, Environment.ProcessorCount - 1)) .Select(_ => Task.Factory.StartNew(() => { foreach (var item in keyDoorPermutationQueue[currentIteration].GetConsumingEnumerable()) { IMutableDungeon dungeonData = GetDungeonData(); dungeonData.SetSmallKeyDoorState(item.Item1); dungeonData.SetBigKeyDoorState(item.Item3); int availableKeys = dungeonData.GetFreeKeys() + item.Item2 - item.Item1.Count; int availableKeysSequenceBreak = dungeonData.GetFreeKeysSequenceBreak() + item.Item2 - item.Item1.Count; bool sequenceBreak = item.Item4; if (availableKeysSequenceBreak == 0) { finalKeyDoorPermutationQueue.Add(item); DungeonDataQueue.Enqueue(dungeonData); continue; } if (availableKeys == 0) { finalKeyDoorPermutationQueue.Add(item); sequenceBreak = true; } var accessibleKeyDoors = dungeonData.GetAccessibleKeyDoors(); if (accessibleKeyDoors.Count == 0) { finalKeyDoorPermutationQueue.Add(item); DungeonDataQueue.Enqueue(dungeonData); continue; } foreach (var keyDoor in accessibleKeyDoors) { List <KeyDoorID> newPermutation = item.Item1.GetRange(0, item.Item1.Count); newPermutation.Add(keyDoor.Item1); keyDoorPermutationQueue[currentIteration + 1].Add( (newPermutation, item.Item2, item.Item3, sequenceBreak || keyDoor.Item2)); } DungeonDataQueue.Enqueue(dungeonData); } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)).ToArray()); } for (int i = 0; i < keyDoorTasks.Count; i++) { Task.WaitAll(keyDoorTasks[i]); keyDoorPermutationQueue[i].Dispose(); if (i + 1 < keyDoorPermutationQueue.Count) { keyDoorPermutationQueue[i + 1].CompleteAdding(); } else { finalKeyDoorPermutationQueue.CompleteAdding(); } } Task[] finalKeyDoorTasks = Enumerable.Range(1, Math.Max(1, Environment.ProcessorCount - 1)) .Select(_ => Task.Factory.StartNew(() => { foreach (var item in finalKeyDoorPermutationQueue.GetConsumingEnumerable()) { IMutableDungeon dungeonData = GetDungeonData(); dungeonData.SetSmallKeyDoorState(item.Item1); dungeonData.SetBigKeyDoorState(item.Item3); if (!dungeonData.ValidateKeyLayout(item.Item2, item.Item3)) { DungeonDataQueue.Enqueue(dungeonData); continue; } List <AccessibilityLevel> bossAccessibility = dungeonData.GetBossAccessibility(); var accessibility = dungeonData.GetItemAccessibility(item.Item2, item.Item3, item.Item4); resultQueue.Add( (bossAccessibility, accessibility.Item1, accessibility.Item2, accessibility.Item3)); DungeonDataQueue.Enqueue(dungeonData); } }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)).ToArray(); Task.WaitAll(finalKeyDoorTasks); finalKeyDoorPermutationQueue.Dispose(); resultQueue.CompleteAdding(); List <AccessibilityLevel> lowestBossAccessibilities = new List <AccessibilityLevel>(); List <AccessibilityLevel> highestBossAccessibilities = new List <AccessibilityLevel>(); for (int i = 0; i < Bosses.Count; i++) { lowestBossAccessibilities.Add(AccessibilityLevel.Normal); highestBossAccessibilities.Add(AccessibilityLevel.None); } AccessibilityLevel lowestAccessibility = AccessibilityLevel.Normal; AccessibilityLevel highestAccessibility = AccessibilityLevel.None; int highestAccessible = 0; foreach (var item in resultQueue.GetConsumingEnumerable()) { for (int i = 0; i < item.Item1.Count; i++) { if (item.Item1[i] < lowestBossAccessibilities[i] && !item.Item4) { lowestBossAccessibilities[i] = item.Item1[i]; } if (item.Item1[i] > highestBossAccessibilities[i]) { highestBossAccessibilities[i] = item.Item1[i]; } } if (item.Item2 < lowestAccessibility && !item.Item4) { lowestAccessibility = item.Item2; } if (item.Item2 > highestAccessibility) { highestAccessibility = item.Item2; } if (item.Item3 > highestAccessible) { highestAccessible = item.Item3; } } resultQueue.Dispose(); AccessibilityLevel finalAccessibility = highestAccessibility; if (finalAccessibility == AccessibilityLevel.Normal && lowestAccessibility < AccessibilityLevel.Normal) { finalAccessibility = AccessibilityLevel.SequenceBreak; } switch (finalAccessibility) { case AccessibilityLevel.None: { (Sections[0] as IDungeonItemSection).Accessibility = finalAccessibility; (Sections[0] as IDungeonItemSection).Accessible = 0; } break; case AccessibilityLevel.Inspect: case AccessibilityLevel.Partial: { (Sections[0] as IDungeonItemSection).Accessibility = finalAccessibility; (Sections[0] as IDungeonItemSection).Accessible = highestAccessible; } break; case AccessibilityLevel.SequenceBreak: case AccessibilityLevel.Normal: case AccessibilityLevel.Cleared: { (Sections[0] as IDungeonItemSection).Accessibility = finalAccessibility; (Sections[0] as IDungeonItemSection).Accessible = Sections[0].Available; } break; } for (int i = 0; i < Bosses.Count; i++) { if (highestBossAccessibilities[i] == AccessibilityLevel.Normal && lowestBossAccessibilities[i] != AccessibilityLevel.Normal) { highestBossAccessibilities[i] = AccessibilityLevel.SequenceBreak; } (Sections[i + 1] as IBossSection).Accessibility = highestBossAccessibilities[i]; } }
public static void compareProcedure(AccessibilityLevel actualLevel, AccessibilityLevel expectedLevel, string type = null) { Assert.IsTrue(actualLevel == expectedLevel, "Actual Level '" + actualLevel.ToString() + "' don't equal to Expected Level '" + expectedLevel.ToString() + "'"); }
public static void SetAccessibilityLevel(this CodeTypeDeclaration self, AccessibilityLevel accessibilityLevel) { self.TypeAttributes = (self.TypeAttributes & ~TypeAttributes.VisibilityMask) | (accessibilityLevel.GetTypeAttribute()); }
/// <summary> /// Updates the accessibility and number of accessible items for the contained sections. /// </summary> private void UpdateSectionAccessibilitySerial() { var keyDoorPermutationQueue = new List <BlockingCollection <(List <KeyDoorID>, int, bool, bool)> >(); var finalKeyDoorPermutationQueue = new BlockingCollection <(List <KeyDoorID>, int, bool, bool)>(); var resultQueue = new BlockingCollection < (List <AccessibilityLevel>, AccessibilityLevel, int, bool)>(); for (int i = 0; i <= SmallKeyDoors.Count; i++) { keyDoorPermutationQueue.Add( new BlockingCollection <(List <KeyDoorID>, int, bool, bool)>()); } List <int> smallKeyValues = GetSmallKeyValues(); List <bool> bigKeyValues = GetBigKeyValues(); foreach (int smallKeyValue in smallKeyValues) { foreach (bool bigKeyValue in bigKeyValues) { keyDoorPermutationQueue[0].Add( (new List <KeyDoorID>(), smallKeyValue, bigKeyValue, false)); } } keyDoorPermutationQueue[0].CompleteAdding(); for (int i = 0; i < keyDoorPermutationQueue.Count; i++) { foreach (var item in keyDoorPermutationQueue[i].GetConsumingEnumerable()) { IMutableDungeon dungeonData = GetDungeonData(); dungeonData.SetSmallKeyDoorState(item.Item1); dungeonData.SetBigKeyDoorState(item.Item3); int availableKeys = dungeonData.GetFreeKeys() + item.Item2 - item.Item1.Count; int availableKeysSequenceBreak = dungeonData.GetFreeKeysSequenceBreak() + item.Item2 - item.Item1.Count; bool sequenceBreak = item.Item4; if (availableKeysSequenceBreak == 0) { finalKeyDoorPermutationQueue.Add(item); DungeonDataQueue.Enqueue(dungeonData); continue; } if (availableKeys == 0) { finalKeyDoorPermutationQueue.Add(item); sequenceBreak = true; } var accessibleKeyDoors = dungeonData.GetAccessibleKeyDoors(); if (accessibleKeyDoors.Count == 0) { finalKeyDoorPermutationQueue.Add(item); DungeonDataQueue.Enqueue(dungeonData); continue; } foreach (var keyDoor in accessibleKeyDoors) { List <KeyDoorID> newPermutation = item.Item1.GetRange(0, item.Item1.Count); if (!accessibleKeyDoors.Exists(x => !x.Item2)) { finalKeyDoorPermutationQueue.Add(item); } newPermutation.Add(keyDoor.Item1); keyDoorPermutationQueue[i + 1].Add((newPermutation, item.Item2, item.Item3, sequenceBreak || keyDoor.Item2)); } DungeonDataQueue.Enqueue(dungeonData); } keyDoorPermutationQueue[i].Dispose(); if (i + 1 < keyDoorPermutationQueue.Count) { keyDoorPermutationQueue[i + 1].CompleteAdding(); } else { finalKeyDoorPermutationQueue.CompleteAdding(); } } foreach (var item in finalKeyDoorPermutationQueue.GetConsumingEnumerable()) { IMutableDungeon dungeonData = GetDungeonData(); dungeonData.SetSmallKeyDoorState(item.Item1); dungeonData.SetBigKeyDoorState(item.Item3); if (!dungeonData.ValidateKeyLayout(item.Item2, item.Item3)) { DungeonDataQueue.Enqueue(dungeonData); continue; } List <AccessibilityLevel> bossAccessibility = dungeonData.GetBossAccessibility(); var accessibility = dungeonData.GetItemAccessibility(item.Item2, item.Item3, item.Item4); resultQueue.Add( (bossAccessibility, accessibility.Item1, accessibility.Item2, accessibility.Item3)); DungeonDataQueue.Enqueue(dungeonData); } finalKeyDoorPermutationQueue.Dispose(); resultQueue.CompleteAdding(); List <AccessibilityLevel> lowestBossAccessibilities = new List <AccessibilityLevel>(); List <AccessibilityLevel> highestBossAccessibilities = new List <AccessibilityLevel>(); for (int i = 0; i < Bosses.Count; i++) { lowestBossAccessibilities.Add(AccessibilityLevel.Normal); highestBossAccessibilities.Add(AccessibilityLevel.None); } AccessibilityLevel lowestAccessibility = AccessibilityLevel.Normal; AccessibilityLevel highestAccessibility = AccessibilityLevel.None; int highestAccessible = 0; foreach (var item in resultQueue.GetConsumingEnumerable()) { for (int i = 0; i < item.Item1.Count; i++) { if (item.Item1[i] < lowestBossAccessibilities[i] && !item.Item4) { lowestBossAccessibilities[i] = item.Item1[i]; } if (item.Item1[i] > highestBossAccessibilities[i]) { highestBossAccessibilities[i] = item.Item1[i]; } } if (item.Item2 < lowestAccessibility && !item.Item4) { lowestAccessibility = item.Item2; } if (item.Item2 > highestAccessibility) { highestAccessibility = item.Item2; } if (item.Item3 > highestAccessible) { highestAccessible = item.Item3; } } resultQueue.Dispose(); AccessibilityLevel finalAccessibility = highestAccessibility; if (finalAccessibility == AccessibilityLevel.Normal && lowestAccessibility < AccessibilityLevel.Normal) { finalAccessibility = AccessibilityLevel.SequenceBreak; } switch (finalAccessibility) { case AccessibilityLevel.None: { (Sections[0] as IDungeonItemSection).Accessibility = finalAccessibility; (Sections[0] as IDungeonItemSection).Accessible = 0; } break; case AccessibilityLevel.Inspect: case AccessibilityLevel.Partial: { (Sections[0] as IDungeonItemSection).Accessibility = finalAccessibility; (Sections[0] as IDungeonItemSection).Accessible = highestAccessible; } break; case AccessibilityLevel.SequenceBreak: case AccessibilityLevel.Normal: case AccessibilityLevel.Cleared: { (Sections[0] as IDungeonItemSection).Accessibility = finalAccessibility; (Sections[0] as IDungeonItemSection).Accessible = Sections[0].Available; } break; } for (int i = 0; i < Bosses.Count; i++) { if (highestBossAccessibilities[i] == AccessibilityLevel.Normal && lowestBossAccessibilities[i] != AccessibilityLevel.Normal) { highestBossAccessibilities[i] = AccessibilityLevel.SequenceBreak; } (Sections[i + 1] as IBossSection).Accessibility = highestBossAccessibilities[i]; } }
public MarkdownableType(Type type, ILookup <string, XmlComment> commentLookup, AccessibilityLevel accessibilityLevel) { _type = type; _commentLookup = commentLookup; _accessibilityLevel = accessibilityLevel; }
public override string ToString() { StringBuilder sb = new StringBuilder(); foreach (var attr in Attributes) { sb.AppendLine(attr.ToString()); } if (!AccessibilityLevel.Equals(SGAccessibilityLevel.None)) { sb.Append($"{AccessibilityLevel} "); } if (IsStatic) { sb.Append("static "); } if (IsAbstract) { sb.Append("abstract "); } if (IsPartial) { sb.Append("partial "); } sb.Append($"class {ClassName}"); if (IsGeneric) { sb.Append("<"); sb.Append(String.Join(", ", GenericTypeNames)); sb.Append(">"); } if (!String.IsNullOrEmpty(BaseClass) || InterfaceImplementations.Count > 0) { sb.Append(" : "); if (!String.IsNullOrEmpty(BaseClass)) { sb.Append($"{BaseClass}"); if (InterfaceImplementations.Count > 0) { sb.Append(", "); } } sb.Append(String.Join(", ", InterfaceImplementations)); } sb.AppendLine(); sb.AppendLine("{"); foreach (SGClassProperty property in Properties) { foreach (string propertyLine in property.ToString().BreakIntoLines()) { sb.AppendLine($"\t{propertyLine}"); } } foreach (SGClassField field in Fields) { foreach (string fieldLine in field.ToString().BreakIntoLines()) { sb.AppendLine($"\t{fieldLine}"); } } foreach (SGClassConstructor constructor in Constructors) { foreach (string ctorLine in constructor.ToString().BreakIntoLines()) { sb.AppendLine($"\t{ctorLine}"); } } foreach (SGMethod method in Methods) { foreach (string methodLine in method.ToString().BreakIntoLines()) { sb.AppendLine($"\t{methodLine}"); } } foreach (SGClass nestedClass in NestedClasses) { foreach (string nestedClassLine in nestedClass.ToString().BreakIntoLines()) { sb.AppendLine($"\t{nestedClassLine}"); } } foreach (SGInterface nestedInterface in NestedInterfaces) { foreach (string nestedInterfaceLine in nestedInterface.ToString().BreakIntoLines()) { sb.AppendLine($"\t{nestedInterfaceLine}"); } } foreach (SGEnum nestedEnum in NestedEnums) { foreach (string nestedEnumLine in nestedEnum.ToString().BreakIntoLines()) { sb.AppendLine($"\t{nestedEnumLine}"); } } sb.AppendLine("}"); return(sb.ToString()); }
public void AccessibilityTests(RequirementType type, AccessibilityLevel expected) { Assert.Equal(expected, RequirementDictionary.Instance[type].Accessibility); }
public static bool IsPublic(this AccessibilityLevel accessibility) => accessibility is AccessibilityLevel.Public;
/// <summary> /// Updates the accessibility and number of accessible items for the contained sections /// using parallel operation. /// </summary> private void UpdateSectionAccessibility() { var keyDoorPermutationQueue = new List <BlockingCollection <IDungeonState> >(); var keyDoorTasks = new List <Task>(); var finalQueue = new BlockingCollection <IDungeonState>(); var resultInLogicQueue = new BlockingCollection <IDungeonResult>(); var resultOutOfLogicQueue = new BlockingCollection <IDungeonResult>(); for (int i = 0; i <= SmallKeyDoors.Count; i++) { keyDoorPermutationQueue.Add(new BlockingCollection <IDungeonState>()); } PopulateInitialDungeonStates(keyDoorPermutationQueue[0]); for (int i = 0; i < keyDoorPermutationQueue.Count; i++) { int currentIteration = i; keyDoorTasks.Add(Task.Factory.StartNew(() => { var dungeonData = GetDungeonData(); foreach (var item in keyDoorPermutationQueue[currentIteration].GetConsumingEnumerable()) { if (keyDoorPermutationQueue.Count > currentIteration + 1) { ProcessDungeonState(dungeonData, item, finalQueue, keyDoorPermutationQueue[currentIteration + 1]); } else { ProcessDungeonState(dungeonData, item, finalQueue, null); } } ReturnDungeonData(dungeonData); }, CancellationToken.None, TaskCreationOptions.None, _taskScheduler)); } for (int i = 0; i < keyDoorTasks.Count; i++) { keyDoorTasks[i].Wait(); keyDoorPermutationQueue[i].Dispose(); if (i + 1 < keyDoorPermutationQueue.Count) { keyDoorPermutationQueue[i + 1].CompleteAdding(); } else { finalQueue.CompleteAdding(); } } var finalKeyDoorTask = Task.Factory.StartNew(() => { var dungeonData = GetDungeonData(); foreach (var item in finalQueue.GetConsumingEnumerable()) { ProcessFinalDungeonState(dungeonData, item, resultInLogicQueue, resultOutOfLogicQueue); } ReturnDungeonData(dungeonData); }, CancellationToken.None, TaskCreationOptions.None, _taskScheduler); finalKeyDoorTask.Wait(); finalQueue.Dispose(); resultInLogicQueue.CompleteAdding(); resultOutOfLogicQueue.CompleteAdding(); List <AccessibilityLevel> lowestBossAccessibilities = new List <AccessibilityLevel>(); List <AccessibilityLevel> highestBossAccessibilities = new List <AccessibilityLevel>(); for (int i = 0; i < Bosses.Count; i++) { lowestBossAccessibilities.Add(AccessibilityLevel.Normal); highestBossAccessibilities.Add(AccessibilityLevel.None); } AccessibilityLevel lowestAccessibility = AccessibilityLevel.Normal; AccessibilityLevel highestAccessibility = AccessibilityLevel.None; int highestAccessible = 0; foreach (var result in resultInLogicQueue.GetConsumingEnumerable()) { for (int i = 0; i < result.BossAccessibility.Count; i++) { if (result.BossAccessibility[i] < lowestBossAccessibilities[i]) { lowestBossAccessibilities[i] = result.BossAccessibility[i]; } if (result.BossAccessibility[i] > highestBossAccessibilities[i]) { highestBossAccessibilities[i] = result.BossAccessibility[i]; } } if (result.Accessibility < lowestAccessibility) { lowestAccessibility = result.Accessibility; } if (result.Accessibility > highestAccessibility) { highestAccessibility = result.Accessibility; } if (result.Accessible > highestAccessible) { highestAccessible = result.Accessible; } } foreach (var result in resultOutOfLogicQueue.GetConsumingEnumerable()) { for (int i = 0; i < result.BossAccessibility.Count; i++) { if (result.BossAccessibility[i] > highestBossAccessibilities[i]) { highestBossAccessibilities[i] = result.BossAccessibility[i]; } } if (result.Accessibility > highestAccessibility) { highestAccessibility = result.Accessibility; } if (result.Accessible > highestAccessible) { highestAccessible = result.Accessible; } } resultInLogicQueue.Dispose(); resultOutOfLogicQueue.Dispose(); AccessibilityLevel finalAccessibility = highestAccessibility; if (finalAccessibility == AccessibilityLevel.Normal && lowestAccessibility < AccessibilityLevel.Normal) { finalAccessibility = AccessibilityLevel.SequenceBreak; } var firstSection = (Sections[0] as IDungeonItemSection) ?? throw new Exception("The first section is not a dungeon item section."); switch (finalAccessibility) { case AccessibilityLevel.None: case AccessibilityLevel.Inspect: { firstSection.Accessibility = finalAccessibility; firstSection.Accessible = 0; } break; case AccessibilityLevel.Partial: { firstSection.Accessibility = finalAccessibility; firstSection.Accessible = highestAccessible; } break; case AccessibilityLevel.SequenceBreak: case AccessibilityLevel.Normal: case AccessibilityLevel.Cleared: { firstSection.Accessibility = finalAccessibility; firstSection.Accessible = firstSection.Available; } break; } for (int i = 0; i < Bosses.Count; i++) { if (highestBossAccessibilities[i] == AccessibilityLevel.Normal && lowestBossAccessibilities[i] != AccessibilityLevel.Normal) { highestBossAccessibilities[i] = AccessibilityLevel.SequenceBreak; } var bossSection = (Sections[i + 1] as IBossSection) ?? throw new Exception($"Section {i + 1} is not a boss section."); bossSection.Accessibility = highestBossAccessibilities[i]; } }
/// <inheritdoc /> public bool Handle(MemberAttributes obj, Context ctx) { ctx.IsMemberAbstract = false; bool isPrivate = false; if (ctx.CurrentDeclarationType != DeclarationType.Interface) { AccessibilityLevel accessLevel = AccessibilityLevel.Default; try { accessLevel = obj.GetAccessibilityLevel(); } catch (ArgumentOutOfRangeException) { if (ctx.Options.DoConsistencyChecks) { throw new ConsistencyException("Invalid access level for member attributes"); } } if (accessLevel != AccessibilityLevel.Default) { ctx.Writer.Write(GetAccessibilityLevelKeyword(accessLevel, ctx)); ctx.Writer.Write(" "); } if (accessLevel == AccessibilityLevel.Private) { isPrivate = true; } } if (ctx.CurrentTypeMember != MemberTypes.Constructor) { if ((obj & MemberAttributes.VTableMask) == MemberAttributes.New && !string.IsNullOrEmpty(GetNewKeyword(ctx))) { ctx.Writer.Write(GetNewKeyword(ctx)); ctx.Writer.Write(" "); } } if ((obj & MemberAttributes.Overloaded) != 0 && !string.IsNullOrEmpty(GetOverloadedKeyword(ctx))) //TODO auto overload { if (ctx.CurrentTypeMember == MemberTypes.Method) { ctx.Writer.Write(GetOverloadedKeyword(ctx)); ctx.Writer.Write(" "); } } if (ctx.CurrentDeclarationType != DeclarationType.Interface && ctx.CurrentTypeMember != MemberTypes.Constructor) { if ((obj & MemberAttributes.ScopeMask) == MemberAttributes.Abstract) { if (ctx.CurrentTypeMember != MemberTypes.Field && ctx.CurrentTypeMember != MemberTypes.Event && !string.IsNullOrEmpty(GetAbstractKeyword(ctx))) { ctx.IsMemberAbstract = true; ctx.Writer.Write(GetAbstractKeyword(ctx) + " "); } } else if ((obj & MemberAttributes.ScopeMask) == MemberAttributes.Override) { if (ctx.CurrentTypeMember != MemberTypes.Field && ctx.CurrentTypeMember != MemberTypes.Event && !string.IsNullOrEmpty(GetOverrideKeyword(ctx))) { ctx.Writer.Write(GetOverrideKeyword(ctx) + " "); } } else if ((obj & MemberAttributes.ScopeMask) == MemberAttributes.Static) { if (!string.IsNullOrEmpty(GetStaticKeyword(ctx))) { ctx.Writer.Write(GetStaticKeyword(ctx) + " "); } } else if ((obj & MemberAttributes.ScopeMask) == MemberAttributes.Const) { if (ctx.CurrentTypeMember == MemberTypes.Field && !string.IsNullOrEmpty(GetConstKeyword(ctx))) { ctx.Writer.Write(GetConstKeyword(ctx) + " "); } } else if ((obj & MemberAttributes.ScopeMask) == MemberAttributes.Final || isPrivate) { if (ctx.CurrentTypeMember != MemberTypes.Field && ctx.CurrentTypeMember != MemberTypes.Event && !string.IsNullOrEmpty(GetFinalKeyword(ctx))) { ctx.Writer.Write(GetFinalKeyword(ctx) + " "); } } else if ((obj & MemberAttributes.ScopeMask) == 0 || !ctx.Options.DoConsistencyChecks) { if (ctx.CurrentTypeMember != MemberTypes.Field && !string.IsNullOrEmpty(GetNotFinalKeyword(ctx))) { ctx.Writer.Write(GetNotFinalKeyword(ctx) + " "); } } else { throw new ConsistencyException("Invalid scope for member attribute"); } } //TODO readonly return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="accessibility"> /// The accessibility level of the requirement. /// </param> public StaticRequirement(AccessibilityLevel accessibility) { Accessibility = accessibility; }