public void ExceptionTest() { NamedObjectCollection <NamedTestObject> collection = new NamedObjectCollection <NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo1", 2)); }
public void ExceptionTest() { NamedObjectCollection<NamedTestObject> collection = new NamedObjectCollection<NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo1", 2)); }
public void TryGetValueTest() { NamedObjectCollection <NamedTestObject> collection = new NamedObjectCollection <NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); NamedTestObject namedObject; Assert.IsTrue(collection.TryGet("foo2", out namedObject)); Assert.AreEqual(2, namedObject.Value); Assert.IsFalse(collection.TryGet("not existing", out namedObject)); Assert.IsNull(namedObject); // Test with other comparer and without internal Dictionary. collection = new NamedObjectCollection <NamedTestObject>(StringComparer.InvariantCultureIgnoreCase, 5); Assert.IsFalse(collection.TryGet("notExisting", out namedObject)); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); Assert.IsTrue(collection.TryGet("foo2", out namedObject)); Assert.AreEqual(2, namedObject.Value); Assert.IsFalse(collection.TryGet("notExisting", out namedObject)); }
/// <summary> /// Adds a varying particle parameter. /// </summary> /// <typeparam name="T">The type of the parameter value.</typeparam> /// <param name="name">The name of the parameter (e.g. "Color", "Position", etc.).</param> /// <returns>The existing or newly created particle parameter.</returns> /// <remarks> /// If the collection does not contain a particle parameter with the given /// <paramref name="name"/>, a new varying particle parameter is added. If the collection /// contains a varying particle parameter with the given <paramref name="name"/>, then only the /// existing particle parameter is returned. If the collection contains a uniform particle /// parameter with the given <paramref name="name"/>, then the existing particle parameter is /// removed and replaced by a new varying particle parameter. /// </remarks> /// <exception cref="ArgumentNullException"> /// <paramref name="name"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="name"/> is empty. /// </exception> /// <exception cref="ParticleSystemException"> /// A particle parameter with the given name was found but the parameter type cannot be cast to /// type <typeparamref name="T"/>. /// </exception> public IParticleParameter <T> AddVarying <T>(string name) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("The particle parameter name must not be empty.", "name"); } IParticleParameter <T> parameter = Get <T>(name, true); T defaultValue = default(T); if (parameter is UniformParticleParameter <T> ) { // Remove uniform parameter, but keep default value. defaultValue = parameter.DefaultValue; _collection.Remove(name); } else if (parameter != null) { return(parameter); } parameter = new VaryingParticleParameter <T>(name, ParticleSystem.MaxNumberOfParticles); parameter.DefaultValue = defaultValue; _collection.Add(parameter); OnChanged(EventArgs.Empty); return(parameter); }
public void BasicsTest() { NamedObjectCollection<NamedTestObject> collection = new NamedObjectCollection<NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); Assert.AreEqual(1, collection["foo1"].Value); Assert.AreEqual(2, collection["foo2"].Value); Assert.AreEqual(1, collection[0].Value); Assert.AreEqual(2, collection[1].Value); }
public void Add_should_allow_multiple_with_same_implicit_name() { var t = new NamedObjectCollection <UriParser>(); var item1 = new HttpStyleUriParser(); var item2 = new HttpStyleUriParser(); t.Add(item1); t.Add(item2); Assert.HasCount(2, t); }
public void BasicsTest() { NamedObjectCollection <NamedTestObject> collection = new NamedObjectCollection <NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); Assert.AreEqual(1, collection["foo1"].Value); Assert.AreEqual(2, collection["foo2"].Value); Assert.AreEqual(1, collection[0].Value); Assert.AreEqual(2, collection[1].Value); }
public void Add_should_not_use_implicit_name_on_second_instance() { var t = new NamedObjectCollection <UriParser>(); var item1 = new HttpStyleUriParser(); var item2 = new HttpStyleUriParser(); t.Add(item1); t.Add(item2); Assert.Equal(new [] { "System.HttpStyleUriParser" }, t.GetNames(item1)); Assert.Empty(t.GetNames(item2)); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ConsoleCommandInterpreter"/> class. /// </summary> /// <param name="console">The <see cref="IConsole"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="console"/> is <see langword="null"/>. /// </exception> public ConsoleCommandInterpreter(IConsole console) { if (console == null) throw new ArgumentNullException("console"); Console = console; Commands = new NamedObjectCollection<ConsoleCommand>(); // Add default built-in commands. //Commands.Add(new ConsoleCommand("add", "Prints the sum of two variables: add <value1> <value2>.", Add)); Commands.Add(new ConsoleCommand("clear", "Clears the console.", Clear)); Commands.Add(new ConsoleCommand("gc", "Forces a full garbage collection.", CollectGarbage)); Commands.Add(new ConsoleCommand("parse", "Prints the command and its arguments (for debugging the console).", ParseCommand)); }
/// <summary> /// Initializes a new instance of the <see cref="ConsoleCommandInterpreter"/> class. /// </summary> /// <param name="console">The <see cref="IConsole"/>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="console"/> is <see langword="null"/>. /// </exception> public ConsoleCommandInterpreter(IConsole console) { if (console == null) throw new ArgumentNullException("console"); Console = console; Commands = new NamedObjectCollection<ConsoleCommand>(); // Add default built-in commands. //Commands.Add(new ConsoleCommand("add", "Prints the sum of two variables: add <value1> <value2>.", Add)); Commands.Add(new ConsoleCommand("clear", "Clears the console.", Clear)); Commands.Add(new ConsoleCommand("gc", "Forces a full garbage collection.", CollectGarbage)); Commands.Add(new ConsoleCommand("parse", "Prints the command and its arguments (for debugging the console).", ParseCommand)); }
public void GetEnumerator() { NamedObjectCollection <NamedTestObject> collection = new NamedObjectCollection <NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); int i = 0; foreach (var item in collection) { i++; Assert.AreEqual(i, item.Value); } }
/// <summary> /// Searches the entire area within control of the country and finds the closest /// and highest priority job for this worker. /// </summary> /// <returns>A <see cref="WorkerActionInfo"/> object with information regarding /// the location and type of work to perform. For more inforation, see the /// <see cref="WorkerActionInfo"/> object.</returns> protected virtual WorkerActionInfo FindCellToImprove() { City next = this.parentCity; GameRoot root = GameRoot.Instance; GridCell currentCell = root.Grid.GetCell(this.Coordinates); WorkerActionInfo info = new WorkerActionInfo(WorkerAction.None, currentCell); if (next == null) { next = currentCell.FindClosestDomesticCity(ParentCountry); } else { NamedObjectCollection <City> exceptions = new NamedObjectCollection <City>(); bool found = false; while (!found) { info = next.RetrieveWorkItem(); if (info.WorkerAction != WorkerAction.None) { found = true; break; } else { exceptions.Add(next); } next = currentCell.FindClosestDomesticCity(ParentCountry, exceptions); } } return(info); }
private NamedObjectCollection <Field> ConvertToLowerInvariant(NamedObjectCollection <Field> columnNames) { if (columnNames != null) { NamedObjectCollection <Field> columnNamesInLower = new NamedObjectCollection <Field>(); columnNamesInLower = columnNames; int selectedIndex = 1; DataRowView item; string[] selectedViewFields = new string[lbxFields.SelectedItems.Count + 1]; selectedViewFields[0] = fieldName; for (int i = 0; i < lbxFields.Items.Count; i++) { item = (DataRowView)lbxFields.Items[i]; if (lbxFields.GetSelected(i)) { selectedViewFields[selectedIndex] = item[lbxFields.DisplayMember].ToString(); DataRow selectRow = item.Row; selectedFields.Add(page.GetView().GetFieldById(int.Parse((selectRow[ColumnNames.FIELD_ID].ToString())))); selectedIndex++; } } return(columnNamesInLower); } return(columnNames); }
public void TestConstructorWithComparer() { var collection = new NamedObjectCollection <NamedTestObject>(StringComparer.InvariantCultureIgnoreCase); collection.Add(new NamedTestObject("foo1", 1)); Assert.IsTrue(collection.Contains("FOO1")); }
public void Add_should_add_using_full_type_name() { var t = new NamedObjectCollection <UriParser>(); var item = new HttpStyleUriParser(); t.Add(item); Assert.Same(item, t["System.HttpStyleUriParser"]); }
public void Add_should_add_using_implicit_and_explicit_names() { var t = new NamedObjectCollection <UriParser>(); var item = new HttpStyleUriParser(); t.Add("http", item); Assert.Same(item, t["System.HttpStyleUriParser"]); Assert.Same(item, t["http"]); }
public void Move() { NamedObjectCollection <NamedTestObject> collection = new NamedObjectCollection <NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); collection.Add(new DerivedNamedTestObject("foo3", 3)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(-1, 1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(1, -1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(3, 1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(1, 3)); collection.Move(1, 1); Assert.AreEqual(2, collection[1].Value); collection.Move(0, 2); Assert.AreEqual(2, collection[0].Value); Assert.AreEqual(3, collection[1].Value); Assert.AreEqual(1, collection[2].Value); }
public void GenericTryGetValueTest() { NamedObjectCollection<NamedTestObject> collection = new NamedObjectCollection<NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); collection.Add(new DerivedNamedTestObject("foo3", 3)); NamedTestObject namedObject; Assert.IsTrue(collection.TryGet<NamedTestObject>("foo2", out namedObject)); Assert.AreEqual(2, namedObject.Value); Assert.IsTrue(collection.TryGet<NamedTestObject>("foo3", out namedObject)); Assert.AreEqual(3, namedObject.Value); DerivedNamedTestObject derivedObject; Assert.IsFalse(collection.TryGet<DerivedNamedTestObject>("not existing", out derivedObject)); Assert.IsNull(derivedObject); Assert.IsFalse(collection.TryGet<DerivedNamedTestObject>("foo2", out derivedObject)); Assert.IsNull(derivedObject); Assert.IsTrue(collection.TryGet<DerivedNamedTestObject>("foo3", out derivedObject)); Assert.AreEqual(3, derivedObject.Value); // Test with other comparer and without internal Dictionary. collection = new NamedObjectCollection<NamedTestObject>(StringComparer.InvariantCultureIgnoreCase, 5); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); collection.Add(new DerivedNamedTestObject("foo3", 3)); Assert.IsFalse(collection.TryGet<DerivedNamedTestObject>("not existing", out derivedObject)); Assert.IsNull(derivedObject); Assert.IsFalse(collection.TryGet<DerivedNamedTestObject>("foo2", out derivedObject)); Assert.IsNull(derivedObject); Assert.IsTrue(collection.TryGet<DerivedNamedTestObject>("foo3", out derivedObject)); Assert.AreEqual(3, derivedObject.Value); }
public void Clear_should_remove_names() { NamedObjectCollection <ImplicityNamed> t = new NamedObjectCollection <ImplicityNamed>(); var item = new ImplicityNamed { Name = "a" }; t.Add(item); t.Clear(); Assert.Equal(0, t.Count); Assert.Null(t["a"]); }
public void Add_should_add_by_implicit_name_nominal() { NamedObjectCollection <ImplicityNamed> t = new NamedObjectCollection <ImplicityNamed>(); var item = new ImplicityNamed { Name = "a" }; t.Add(item); Assert.Same(item, t["a"]); Assert.True(t.Contains("a")); Assert.True(t.Contains(item)); }
/// <summary> /// Attempts to steal a random technolgy from the foreign country. /// </summary> /// <returns></returns> public EspionageResult StealTechnology() { if (!this.hasEmbassy) { throw new InvalidOperationException(ServerResources.EmbassyRequired); } if (!this.hasSpy) { throw new InvalidOperationException(ServerResources.SpyRequired); } if (this.foreignCountry.Government.Fallback) { return(EspionageResult.ImmuneToEspionage); } NamedObjectCollection <Technology> candidateTechs = new NamedObjectCollection <Technology>(); Technology stolenTech; int randIdx = RandomNumber.UpTo(75); if (randIdx >= 75) { //failure. bool spyCaught; //50 percent chance of spy being caught randIdx = RandomNumber.UpTo(50); spyCaught = (randIdx >= 50); if (spyCaught) { this.hasSpy = false; this.foreignCountry.CaptureSpy(this, EspionageAction.StealTechnology, false, null); return(EspionageResult.SpyCaught); } else { return(EspionageResult.Failure); } } foreach (Technology foreignTech in this.foreignCountry.AcquiredTechnologies) { if (!this.parentCountry.AcquiredTechnologies.Contains(foreignTech)) { candidateTechs.Add(foreignTech); } } randIdx = RandomNumber.UpTo(candidateTechs.Count - 1); stolenTech = candidateTechs[randIdx]; this.parentCountry.AcquiredTechnologies.Add(stolenTech); return(EspionageResult.Success); }
/// <summary> /// Returns the closest explored foreign city of that has been explored /// by the parent country. /// </summary> /// <param name="parentCountry">The parent country. Foreign cities will only be /// returned if they have been explored by the parent country</param> /// <param name="foreignCountry">The country to search for the forieign cities</param> /// <returns></returns> public City FindClosestForeignCity(Country parentCountry, Country foreignCountry) { if (parentCountry == null) { throw new ArgumentNullException("parentCountry"); } if (foreignCountry == null) { throw new ArgumentNullException("foreignCountry"); } NamedObjectCollection <City> discoveredCities = new NamedObjectCollection <City>(); City closest = null; int closestDistance = 0; int deltaX, deltaY; int distance; GameRoot root = GameRoot.Instance; //what cities do they know about? foreach (City city in foreignCountry.Cities) { GridCell cityCell = root.Grid.GetCell(city.Coordinates); if (cityCell.HasBeenExploredBy(parentCountry)) { discoveredCities.Add(city); } } //of the "known" cities, which one is closest? foreach (City city in discoveredCities) { deltaX = Math.Abs(city.Coordinates.X - this.Coordinates.X); deltaY = Math.Abs(city.Coordinates.Y - this.Coordinates.Y); distance = (int)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)); if ((closest == null) || (distance < closestDistance)) { closestDistance = distance; closest = city; } } return(closest); }
public void Move() { NamedObjectCollection<NamedTestObject> collection = new NamedObjectCollection<NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); collection.Add(new DerivedNamedTestObject("foo3", 3)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(-1, 1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(1, -1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(3, 1)); Assert.Throws(typeof(ArgumentOutOfRangeException), () => collection.Move(1, 3)); collection.Move(1, 1); Assert.AreEqual(2, collection[1].Value); collection.Move(0, 2); Assert.AreEqual(2, collection[0].Value); Assert.AreEqual(3, collection[1].Value); Assert.AreEqual(1, collection[2].Value); }
/// <summary> /// Builds the completion data from the given list. /// </summary> /// <param name="keywordCategories">The keyword categories.</param> /// <param name="stateCategories">The state categories.</param> /// <param name="includeConstants"><c>true</c> to include constant in the completion data.</param> /// <param name="includeSnippets"><c>true</c> to include snippets in the completion data.</param> /// <returns></returns> private ICompletionData[] BuildCompletionData(IEnumerable<IEnumerable<NamedCompletionData>> keywordCategories, IEnumerable<IEnumerable<NamedCompletionData>> stateCategories, bool includeConstants, bool includeSnippets) { List<ICompletionData> completionData = new List<ICompletionData>(); if (includeSnippets) { // Add Snippets foreach (SnippetCompletionData snippet in Snippets.Values) completionData.Add(new SnippetCompletionData(snippet.Text, snippet.Description, MultiColorGlyphs.Snippet, snippet.Snippet)); } // Add Keywords foreach (IEnumerable<NamedCompletionData> keywords in keywordCategories) foreach (NamedCompletionData keyword in keywords) completionData.Add(keyword); // Add Effect States: // Different state groups can have the same states. // Merge them into a single NamedObjectCollection first, to avoid duplications. NamedObjectCollection<NamedCompletionData> stateCompletionData = new NamedObjectCollection<NamedCompletionData>(); foreach (IEnumerable<NamedCompletionData> states in stateCategories) foreach (NamedCompletionData state in states) if (!stateCompletionData.Contains(state.Name)) stateCompletionData.Add(state); foreach (NamedCompletionData state in stateCompletionData) completionData.Add(state); // Merge constants and state values NamedObjectCollection<NamedCompletionData> constants = new NamedObjectCollection<NamedCompletionData>(); if (includeConstants) foreach (ConstantCompletionData constant in Constants) constants.Add(constant); foreach (StateCompletionData state in stateCompletionData) foreach (string stateValue in state.AllowedValues) if (!constants.Contains(stateValue)) constants.Add(EffectStateValues[stateValue]); foreach (NamedCompletionData constant in constants) completionData.Add(constant); return completionData.ToArray(); }
/// <summary> /// Identifies the source code region at the given offset. /// </summary> /// <param name="document">The document.</param> /// <param name="startOffset">The start offset where to start the search.</param> /// <param name="targetOffset">The target offset where the region shall be evaluated.</param> /// <param name="identifiers">The collected identifiers.</param> /// <param name="fields">The collected field identifiers.</param> /// <returns> /// The method returns the identified source code region. /// </returns> /// <remarks> /// <para> /// If there is no region at <paramref name="targetOffset"/> the method returns /// <see cref="ShaderRegion.Default"/>. In this the caller needs to decide what region it /// actually is. (When <see cref="IdentifyRegion(ITextSource,int,int,NamedObjectCollection{NamedCompletionData},NamedObjectCollection{NamedCompletionData})"/> /// is called with a <paramref name="startOffset"/> of 0 then it is <see cref="ShaderRegion.Global"/>.) /// </para> /// <para> /// This method calls itself recursively. First identifies the outermost region, then it /// recursively refines the search and returns the innermost region. /// </para> /// </remarks> private ShaderRegion IdentifyRegion(ITextSource document, int startOffset, int targetOffset, NamedObjectCollection<NamedCompletionData> identifiers, NamedObjectCollection<NamedCompletionData> fields) { int offset = startOffset; bool collectIdentifiers = (identifiers != null); while (offset < document.TextLength && offset < targetOffset) { char c = document.GetCharAt(offset); switch (c) { case '/': // Skip comments if (offset + 1 < document.TextLength) { char nextChar = document.GetCharAt(offset + 1); if (nextChar == '/') { // Line comment offset = SkipLineComment(document, offset + 2); if (targetOffset <= offset) return ShaderRegion.LineComment; } else if (nextChar == '*') { // Block comment offset = SkipBlockComment(document, offset + 2); if (targetOffset < offset) return ShaderRegion.BlockComment; } else { // No comment ++offset; } } else { // End of file -> Skip past end to terminate algorithm. ++offset; } break; case '"': // Skip strings offset = SkipString(document, offset + 1); if (targetOffset < offset) return ShaderRegion.String; break; case '\'': // Skip character literals offset = SkipCharacterLiteral(document, offset + 1); if (targetOffset < offset) return ShaderRegion.CharacterLiteral; break; case '{': // Identify the current block int startOffsetOfBlock = offset; ShaderRegion region = IdentifyBlockAt(document, offset); offset = TextUtilities.FindClosingBracket(document, offset + 1, '{', '}'); if (offset == -1 || targetOffset < offset) { // Let's identify the region inside this block. (Recursion!) ShaderRegion innerRegion = IdentifyRegion(document, startOffsetOfBlock + 1, targetOffset, identifiers, fields); if (region == ShaderRegion.TechniqueOrPass10 && innerRegion == ShaderRegion.TechniqueOrPass) { // Return the more specific return ShaderRegion.TechniqueOrPass10; } if (innerRegion == ShaderRegion.Default || innerRegion == ShaderRegion.Unknown) { // The inner region is unknown or same as outer region return region; } // Return the more specific inner region. return innerRegion; } ++offset; break; case '<': // Check whether this is an annotation if (IsStartOfAnnotation(document, offset)) { int startOffsetOfAnnotation = offset; offset = TextUtilities.FindClosingBracket(document, offset + 1, '<', '>'); if (offset == -1 || targetOffset <= offset) { // Let's identify the region inside the annotation. (Recursion!) ShaderRegion innerRegion = IdentifyRegion(document, startOffsetOfAnnotation + 1, targetOffset, identifiers, fields); if (innerRegion == ShaderRegion.Default || innerRegion == ShaderRegion.Unknown) { // The inner region is unknown or same as outer region return ShaderRegion.Annotation; } // Return the more specific inner region. return innerRegion; } ++offset; } else { ++offset; } break; default: if (Char.IsLetter(c) || c == '_') { if (collectIdentifiers) { string identifier = TextUtilities.GetIdentifierAt(document, offset); if (!String.IsNullOrEmpty(identifier) && !_intelliSense.FullLookupTable.Contains(identifier)) { if (offset > 0 && document.GetCharAt(offset - 1) == '.') { if (!fields.Contains(identifier)) fields.Add(new GuessCompletionData(identifier)); } else { if (!identifiers.Contains(identifier)) identifiers.Add(new GuessCompletionData(identifier)); } } } offset = SkipIdentifier(document, offset); } else if (Char.IsDigit(c)) { offset = SkipNumber(document, offset); if (targetOffset <= offset) { return ShaderRegion.Default; } } else { ++offset; } break; } } return ShaderRegion.Default; }
public void TestConstructorWithComparer() { var collection = new NamedObjectCollection<NamedTestObject>(StringComparer.InvariantCultureIgnoreCase); collection.Add(new NamedTestObject("foo1", 1)); Assert.IsTrue(collection.Contains("FOO1")); }
/// <summary> /// Identifies the source code region at the given offset. /// </summary> /// <param name="document">The document.</param> /// <param name="startOffset">The start offset where to start the search.</param> /// <param name="targetOffset">The target offset where the region shall be evaluated.</param> /// <param name="identifiers">The collected identifiers.</param> /// <param name="fields">The collected field identifiers.</param> /// <returns> /// The method returns the identified source code region. /// </returns> /// <remarks> /// <para> /// If there is no region at <paramref name="targetOffset"/> the method returns /// <see cref="ShaderRegion.Default"/>. In this the caller needs to decide what region it /// actually is. (When <see cref="IdentifyRegion(ITextSource,int,int,NamedObjectCollection{NamedCompletionData},NamedObjectCollection{NamedCompletionData})"/> /// is called with a <paramref name="startOffset"/> of 0 then it is <see cref="ShaderRegion.Global"/>.) /// </para> /// <para> /// This method calls itself recursively. First identifies the outermost region, then it /// recursively refines the search and returns the innermost region. /// </para> /// </remarks> private ShaderRegion IdentifyRegion(ITextSource document, int startOffset, int targetOffset, NamedObjectCollection <NamedCompletionData> identifiers, NamedObjectCollection <NamedCompletionData> fields) { int offset = startOffset; bool collectIdentifiers = (identifiers != null); while (offset < document.TextLength && offset < targetOffset) { char c = document.GetCharAt(offset); switch (c) { case '/': // Skip comments if (offset + 1 < document.TextLength) { char nextChar = document.GetCharAt(offset + 1); if (nextChar == '/') { // Line comment offset = SkipLineComment(document, offset + 2); if (targetOffset <= offset) { return(ShaderRegion.LineComment); } } else if (nextChar == '*') { // Block comment offset = SkipBlockComment(document, offset + 2); if (targetOffset < offset) { return(ShaderRegion.BlockComment); } } else { // No comment ++offset; } } else { // End of file -> Skip past end to terminate algorithm. ++offset; } break; case '"': // Skip strings offset = SkipString(document, offset + 1); if (targetOffset < offset) { return(ShaderRegion.String); } break; case '\'': // Skip character literals offset = SkipCharacterLiteral(document, offset + 1); if (targetOffset < offset) { return(ShaderRegion.CharacterLiteral); } break; case '{': // Identify the current block int startOffsetOfBlock = offset; ShaderRegion region = IdentifyBlockAt(document, offset); offset = TextUtilities.FindClosingBracket(document, offset + 1, '{', '}'); if (offset == -1 || targetOffset < offset) { // Let's identify the region inside this block. (Recursion!) ShaderRegion innerRegion = IdentifyRegion(document, startOffsetOfBlock + 1, targetOffset, identifiers, fields); if (region == ShaderRegion.TechniqueOrPass10 && innerRegion == ShaderRegion.TechniqueOrPass) { // Return the more specific return(ShaderRegion.TechniqueOrPass10); } if (innerRegion == ShaderRegion.Default || innerRegion == ShaderRegion.Unknown) { // The inner region is unknown or same as outer region return(region); } // Return the more specific inner region. return(innerRegion); } ++offset; break; case '<': // Check whether this is an annotation if (IsStartOfAnnotation(document, offset)) { int startOffsetOfAnnotation = offset; offset = TextUtilities.FindClosingBracket(document, offset + 1, '<', '>'); if (offset == -1 || targetOffset <= offset) { // Let's identify the region inside the annotation. (Recursion!) ShaderRegion innerRegion = IdentifyRegion(document, startOffsetOfAnnotation + 1, targetOffset, identifiers, fields); if (innerRegion == ShaderRegion.Default || innerRegion == ShaderRegion.Unknown) { // The inner region is unknown or same as outer region return(ShaderRegion.Annotation); } // Return the more specific inner region. return(innerRegion); } ++offset; } else { ++offset; } break; default: if (Char.IsLetter(c) || c == '_') { if (collectIdentifiers) { string identifier = TextUtilities.GetIdentifierAt(document, offset); if (!String.IsNullOrEmpty(identifier) && !_intelliSense.FullLookupTable.Contains(identifier)) { if (offset > 0 && document.GetCharAt(offset - 1) == '.') { if (!fields.Contains(identifier)) { fields.Add(new GuessCompletionData(identifier)); } } else { if (!identifiers.Contains(identifier)) { identifiers.Add(new GuessCompletionData(identifier)); } } } } offset = SkipIdentifier(document, offset); } else if (Char.IsDigit(c)) { offset = SkipNumber(document, offset); if (targetOffset <= offset) { return(ShaderRegion.Default); } } else { ++offset; } break; } } return(ShaderRegion.Default); }
/// <summary> /// Get all groups on a given page as a NamedObjectCollection /// </summary> /// <param name="page">The page the field group belongs to</param> /// <returns>FieldGroup</returns> public NamedObjectCollection<GroupField> GetGroupFields(Page page) { NamedObjectCollection<GroupField> groups = new NamedObjectCollection<GroupField>(); try { DataTable table = GetGroupsForPage(page.Id); foreach (DataRow row in table.Rows) { groups.Add(new GroupField(row, page)); } } catch (Exception ex) { throw new GeneralException("Could not retrieve field groups", ex); } return (groups); }
/// <summary> /// Builds the completion data from the given list. /// </summary> /// <param name="keywordCategories">The keyword categories.</param> /// <param name="stateCategories">The state categories.</param> /// <param name="includeConstants"><c>true</c> to include constant in the completion data.</param> /// <param name="includeSnippets"><c>true</c> to include snippets in the completion data.</param> /// <returns></returns> private ICompletionData[] BuildCompletionData(IEnumerable <IEnumerable <NamedCompletionData> > keywordCategories, IEnumerable <IEnumerable <NamedCompletionData> > stateCategories, bool includeConstants, bool includeSnippets) { List <ICompletionData> completionData = new List <ICompletionData>(); if (includeSnippets) { // Add Snippets foreach (SnippetCompletionData snippet in Snippets.Values) { completionData.Add(new SnippetCompletionData(snippet.Text, snippet.Description, MultiColorGlyphs.Snippet, snippet.Snippet)); } } // Add Keywords foreach (IEnumerable <NamedCompletionData> keywords in keywordCategories) { foreach (NamedCompletionData keyword in keywords) { completionData.Add(keyword); } } // Add Effect States: // Different state groups can have the same states. // Merge them into a single NamedObjectCollection first, to avoid duplications. NamedObjectCollection <NamedCompletionData> stateCompletionData = new NamedObjectCollection <NamedCompletionData>(); foreach (IEnumerable <NamedCompletionData> states in stateCategories) { foreach (NamedCompletionData state in states) { if (!stateCompletionData.Contains(state.Name)) { stateCompletionData.Add(state); } } } foreach (NamedCompletionData state in stateCompletionData) { completionData.Add(state); } // Merge constants and state values NamedObjectCollection <NamedCompletionData> constants = new NamedObjectCollection <NamedCompletionData>(); if (includeConstants) { foreach (ConstantCompletionData constant in Constants) { constants.Add(constant); } } foreach (StateCompletionData state in stateCompletionData) { foreach (string stateValue in state.AllowedValues) { if (!constants.Contains(stateValue)) { constants.Add(EffectStateValues[stateValue]); } } } foreach (NamedCompletionData constant in constants) { completionData.Add(constant); } return(completionData.ToArray()); }
/// <summary> /// Gets a collection of renderable <see cref="Epi.Fields"/> on an <see cref="Epi.Page"/> /// </summary> /// <param name="page"><see cref="Epi.Page"/></param> /// <returns>A named object collection of renderable <see cref="Epi.Fields"/>.</returns> public NamedObjectCollection<Field> GetFieldsOnPage(Page page) { NamedObjectCollection<Field> pageFields = new NamedObjectCollection<Field>(); foreach (Field field in page.Fields) { if (field is RenderableField) { RenderableField renderableField = field as RenderableField; if (renderableField.Page.Id == page.Id) { pageFields.Add(renderableField); } } } return pageFields; }
public void GetEnumerator() { NamedObjectCollection<NamedTestObject> collection = new NamedObjectCollection<NamedTestObject>(); collection.Add(new NamedTestObject("foo1", 1)); collection.Add(new NamedTestObject("foo2", 2)); int i = 0; foreach(var item in collection) { i++; Assert.AreEqual(i, item.Value); } }