/// <summary> /// Merges two NamedVariableScopes together. It works like this: <list type="bullet"> /// <item><description>If this is the same type or more specific than /// <paramref name="otherScope"/>, then create a new merged NamedScope from /// <paramref name="otherScope"/>and this.</description></item> <item><description>If /// <paramref name="otherScope"/>is more specific than this, call /// <c>otherScope.Merge</c></description></item> </list> /// </summary> /// <param name="otherScope">The scope to merge with</param> /// <returns>The new merged scope; null if they couldn't be merged</returns> public virtual INamedScope Merge(INamedScope otherScope) { INamedScope mergedScope = null; if (otherScope != null) { if (otherScope.CanBeMergedInto(this)) { // this and other scope can be merged normally either they are the same type or // this is a subclass of NamedScope and otherScope is a NamedScope mergedScope = new NamedScope(this); mergedScope.AddFrom(otherScope); } else if (this.CanBeMergedInto(otherScope) && !otherScope.CanBeMergedInto(this)) { // this is a NamedScope and otherScope is a subclass useful information (type, // method, or namespace data) are in otherScope mergedScope = otherScope.Merge(this); } } return(mergedScope); }
/// <summary> /// Merges this namespace definition with /// <paramref name="otherScope"/>. This happens when <c>otherScope.CanBeMergedInto(this)</c> /// evaluates to true. /// </summary> /// <param name="otherScope">the scope to merge with</param> /// <returns>a new namespace definition from this and otherScope, or null if they couldn't /// be merged.</returns> public override INamedScope Merge(INamedScope otherScope) { NamespaceDefinition mergedScope = null; if (otherScope != null) { if (otherScope.CanBeMergedInto(this)) { mergedScope = new NamespaceDefinition(this); mergedScope.AddFrom(otherScope); } } return(mergedScope); }
/// <summary> /// Merges this type definition with /// <paramref name="otherScope"/>. This happens when <c>otherScope.CanBeMergedInto(this)</c> /// evaluates to true. /// </summary> /// <param name="otherScope">the scope to merge with</param> /// <returns>a new type definition from this and otherScope, or null if they couldn't be /// merged</returns> public override INamedScope Merge(INamedScope otherScope) { ITypeDefinition mergedScope = null; if (otherScope != null) { if (otherScope.CanBeMergedInto(this)) { mergedScope = new TypeDefinition(this); mergedScope.AddFrom(otherScope); if (mergedScope.Accessibility == AccessModifier.None) { mergedScope.Accessibility = otherScope.Accessibility; } } } return(mergedScope as INamedScope); }