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)); }
public void TestConstructorWithComparer() { var collection = new NamedObjectCollection <NamedTestObject>(StringComparer.InvariantCultureIgnoreCase); collection.Add(new NamedTestObject("foo1", 1)); Assert.IsTrue(collection.Contains("FOO1")); }
/// <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); }
/// <summary> /// Determines whether the collection contains a particle parameter with the given name. /// </summary> /// <param name="name">The name of the parameter (e.g. "Color", "Position", etc.).</param> /// <returns> /// <see langword="true"/> if a particle parameter with the given name exists; otherwise, /// <see langword="false"/>. /// </returns> public bool Contains(string name) { return(_collection.Contains(name)); }
/// <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> /// 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(); }
public void TestConstructorWithComparer() { var collection = new NamedObjectCollection<NamedTestObject>(StringComparer.InvariantCultureIgnoreCase); collection.Add(new NamedTestObject("foo1", 1)); Assert.IsTrue(collection.Contains("FOO1")); }