Exemplo n.º 1
0
 public bool? IsExposedMember(Member member) {
     if (member.Name.Name == name) {
         return (exposed);
     } else {
         return (null);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Checks for less-than-visible member references in an expression.
        /// </summary>
        public override void VisitMemberBinding(MemberBinding binding)
        {
            if (binding == null) return;

            Member mem = binding.BoundMember;
            if (mem != null)
            {
                Field f = mem as Field;
                bool specPublic = false;

                if (f != null)
                {
                    specPublic = IsSpecPublic(f);
                }
                
                if (!specPublic && !HelperMethods.IsCompilerGenerated(mem))
                {
                    // F: It seems there is some type-state like invariant here justifying why this.AsThisMemeber != null
                    Contract.Assume(this.AsThisMember != null);
                    
                    if (!HelperMethods.IsReferenceAsVisibleAs(mem, this.AsThisMember))
                    {
                        this.memberInErrorFound = mem;
                        return;
                    }
                }
            }

            base.VisitMemberBinding(binding);
        }
Exemplo n.º 3
0
        public override bool IsExposedMember(Member member) {

            // member of delegates are not exposed
            TypeNode type = member.DeclaringType;
            if (type.NodeType == NodeType.DelegateNode) return (false);

            // accessor methods for properties and events are not exposed
            if (member.IsSpecialName && (member.NodeType == NodeType.Method)) {
                string name = member.Name.Name;
                if (NameContains(name, "get_")) return (false);
                if (NameContains(name, "set_")) return (false);
                if (NameContains(name, "add_")) return (false);
                if (NameContains(name, "remove_")) return (false);
                if (NameContains(name, "raise_")) return (false);
            }

            // the value field of enumerations is not exposed
            if (member.IsSpecialName && (type.NodeType == NodeType.EnumNode) && (member.NodeType == NodeType.Field)) {
                string name = member.Name.Name;
                if (name == "value__") return (false);
            }

            // members marked as compiler-generated are not exposed
            if (ListContainsAttribute(member.Attributes, "System.Runtime.CompilerServices.CompilerGeneratedAttribute")) {
                return (false);
            }

            // okay, passed all tests, so member is exposed
            return (base.IsExposedMember(member));

        }
Exemplo n.º 4
0
        // exposure logic for artibrary APIs
        // call the appropriate particular exposure logic

        public virtual bool IsExposedApi(Member api) {

            Namespace space = api as Namespace;
            if (space != null) return (IsExposedNamespace(space));

            TypeNode type = api as TypeNode;
            if (type != null) return (IsExposedType(type));

            return (IsExposedMember(api));
        }
Exemplo n.º 5
0
 public void CheckModelfieldAdmissibility(ModelfieldContract mfC) {
   this.DeclaringMfC = mfC;
   this.DeclaringMember = mfC.Modelfield;
   if (this.DeclaringMember is Property)
     this.DeclaringMember = (this.DeclaringMember as Property).Getter; //references to the modelfield have been resolved as bindings to this getter
   foreach (Expression satExpr in mfC.SatisfiesList) {
     StateStack = new System.Collections.Stack();
     ResetCurrentState();
     this.VisitExpression(satExpr);
   }
 }
Exemplo n.º 6
0
        public virtual string GetApiName(Member api) {

            Namespace space = api as Namespace;
            if (space != null) return (GetNamespaceName(space));

            TypeNode type = api as TypeNode;
            if (type != null) return (GetTypeName(type));

            return (GetMemberName(api));

        }
Exemplo n.º 7
0
        public virtual Member VisitMemberReference(Member member)
        {
            if(member == null)
                return null;

            TypeNode specializedType = this.VisitTypeReference(member.DeclaringType);

            if(specializedType == member.DeclaringType || specializedType == null)
                return member;

            return Specializer.GetCorrespondingMember(member, specializedType);
        }
Exemplo n.º 8
0
        public bool? IsExposedMember(Member member) {
            //Console.WriteLine("DEBUG: typeFilter.IsExposedMember");
            TypeNode type = ReflectionUtilities.GetTemplateType(member.DeclaringType);
            if (IsExposedType(type) != null) {
                foreach (MemberFilter memberFilter in memberFilters) {
                    bool? result = memberFilter.IsExposedMember(member);
                    if (result != null) return (result);
                }

                return (exposed); //return the type's exposed setting
            } else {
                return (null);
            }
        }
Exemplo n.º 9
0
        //=====================================================================

        /// <summary>
        /// Check to see if the member is exposed or not by this entry
        /// </summary>
        /// <param name="member">The member to check</param>
        /// <returns>Null if the member is not represented by this entry, true if it is and it is exposed or
        /// false if it is and it is not exposed.</returns>
        public bool? IsExposedMember(Member member)
        {
            // Try for an exact match first
            if(member.Name.Name == name)
                return exposed;

            // !EFW - If the member name contains "<" and our name contains "{", this is probably a
            // generic using the XML comments syntax member ID so try for a match that way too.
            if(member.Name.Name.IndexOf('<') != -1 && name.IndexOf('{') != -1 &&
              member.Name.Name.Replace('<', '{').Replace('>', '}') == name)
                return exposed;

            return null;
        }
Exemplo n.º 10
0
        private static string GetName(Member entity) {

            using (TextWriter writer = new StringWriter()) {

                TypeNode type = entity as TypeNode;
                if (type != null) {
                    writer.Write("T:");
                    WriteType(type, writer);
                    return (writer.ToString());
                }

                switch (entity.NodeType) {
                    case NodeType.Namespace:
                        writer.Write("N:");
                        WriteNamespace(entity as Namespace, writer);
                        break;
                    case NodeType.Field:
                        writer.Write("F:");
                        WriteField(entity as Field, writer);
                        break;
                    case NodeType.Property:
                        writer.Write("P:");
                        WriteProperty(entity as Property, writer);
                        break;
                    case NodeType.Method:
                        writer.Write("M:");
                        WriteMethod(entity as Method, writer);
                        break;
                    case NodeType.InstanceInitializer:
                        writer.Write("M:");
                        WriteConstructor(entity as InstanceInitializer, writer);
                        break;
                    case NodeType.StaticInitializer:
                        writer.Write("M:");
                        WriteStaticConstructor(entity as StaticInitializer, writer);
                        break;
                    case NodeType.Event:
                        writer.Write("E:");
                        WriteEvent(entity as Event, writer);
                        break;
                }

                return (writer.ToString());

            }

        }
        public override bool IsExposedMember(Member member)
        {
            if (member == null) throw new ArgumentNullException("member");
            TypeNode type = member.DeclaringType;
            // if the member isn't visible, we certainly won't expose it...
            if (!member.IsVisibleOutsideAssembly && !(protectedSealedVisible && type.IsSealed && (member.IsFamily || member.IsFamilyOrAssembly)))
                return (false);
            // ...but there are also some visible members we won't expose.
            // member of delegates are not exposed
            if (type.NodeType == NodeType.DelegateNode) return (false);
            // accessor methods for properties and events are not exposed
            if (member.IsSpecialName && (member.NodeType == NodeType.Method))
            {
                string name = member.Name.Name;
                if (NameContains(name, "get_")) return (false);
                if (NameContains(name, "set_")) return (false);
                if (NameContains(name, "add_")) return (false);
                if (NameContains(name, "remove_")) return (false);
                if (NameContains(name, "raise_")) return (false);
            }

            // the value field of enumerations is not exposed
            if (member.IsSpecialName && (type.NodeType == NodeType.EnumNode) && (member.NodeType == NodeType.Field))
            {
                string name = member.Name.Name;
                if (name == "value__") return (false);
            }

            // protected members of sealed types are not exposed
            // change of plan -- yes they are
            // if (type.IsSealed && (member.IsFamily || member.IsFamilyOrAssembly)) return(false);

            // One more test to deal with a wierd case: a private method is an explicit implementation for
            // a property accessor, but is not marked with the special name flag. To find these, test for
            // the accessibility of the methods they implement
            if (member.IsPrivate && member.NodeType == NodeType.Method)
            {
                Method method = (Method)member;
                MethodList implements = method.ImplementedInterfaceMethods;
                if ((implements.Count > 0) && (!IsExposedMember(implements[0]))) return (false);
            }

            // okay, passed all tests, the member is exposed as long as the filters allow it
            return (base.IsExposedMember(member));
        }
Exemplo n.º 12
0
        public bool? IsExposedMember(Member member) {
            //Console.WriteLine("DEBUG: namespaceFilter.isExposedMemeber");
            TypeNode type = ReflectionUtilities.GetTemplateType(member.DeclaringType);
            Namespace space = ReflectionUtilities.GetNamespace(type);
            if (IsExposedNamespace(space) != null) {
                foreach (TypeFilter typeFilter in typeFilters) {
                    bool? result = typeFilter.IsExposedMember(member);
                    if (result != null) return (result);
                }

                //no filters matched this method, check if the type is exposed
                bool? typeIsExposed = IsExposedType(type);
                if (typeIsExposed != null) return typeIsExposed;

                return (exposed); //if the namespace is exposed
            } else {
                return (null);
            }
        }
Exemplo n.º 13
0
        public static Member GetTemplateMember(Member member) {

            if (member == null) throw new ArgumentNullException("member");

            // if the containing type isn't generic, the member is the template member
            TypeNode type = member.DeclaringType;
            if (!type.IsGeneric) return (member);

            // if the containing type isn't specialized, the member is the template member
            if (!IsSpecialized(type)) return (member);

            // get the template type, and look for members with the same name
            TypeNode template = ReflectionUtilities.GetTemplateType(member.DeclaringType);
            Identifier name = member.Name;
            MemberList candidates = template.GetMembersNamed(name);

            // if no candidates, say so (this shouldn't happen)
            if (candidates.Count == 0) throw new InvalidOperationException("No members in the template had the name found in the specialization. This is not possible, but apparently it happened.");

            // if only one candidate, return it
            if (candidates.Count == 1) return (candidates[0]);

            // multiple candidates, so now we need to compare parameters
            ParameterList parameters = GetParameters(member);

            for (int i = 0; i < candidates.Count; i++) {
                Member candidate = candidates[i];

                // candidate must be same kind of node
                if (candidate.NodeType != member.NodeType) continue;

                // if parameters match, this is the one
                if (ParametersMatch(parameters, GetParameters(candidate))) return (candidate);

            }

            Console.WriteLine(member.DeclaringType.FullName);
            Console.WriteLine(member.FullName);
            throw new InvalidOperationException("No members in the template matched the parameters of the specialization. This is not possible.");
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        public override string GetMemberName(Member member)
        {
            StringBuilder sb = new StringBuilder();

            switch(member.NodeType)
            {
                case NodeType.Field:
                    sb.Append("F:");
                    WriteField((Field)member, sb);
                    break;

                case NodeType.Property:
                    sb.Append("P:");
                    WriteProperty((Property)member, sb);
                    break;

                case NodeType.Event:
                    sb.Append("E:");
                    WriteEvent((Event)member, sb);
                    break;

                case NodeType.Method:
                    sb.Append("M:");
                    WriteMethod((Method)member, sb);
                    break;

                case NodeType.InstanceInitializer:
                    sb.Append("M:");
                    WriteConstructor((InstanceInitializer)member, sb);
                    break;

                case NodeType.StaticInitializer:
                    sb.Append("M:");
                    WriteStaticConstructor((StaticInitializer)member, sb);
                    break;
            }

            return sb.ToString();
        }
Exemplo n.º 15
0
        public override string GetMemberName(Member member) {

            using (TextWriter writer = new StringWriter()) {

                switch (member.NodeType) {
                    case NodeType.Field:
                        writer.Write("F:");
                        WriteField((Field)member, writer);
                        break;
                    case NodeType.Property:
                        writer.Write("P:");
                        WriteProperty((Property)member, writer);
                        break;
                    case NodeType.Method:
                        writer.Write("M:");
                        WriteMethod((Method)member, writer);
                        break;
                    case NodeType.InstanceInitializer:
                        writer.Write("M:");
                        WriteConstructor((InstanceInitializer)member, writer);
                        break;
                    case NodeType.StaticInitializer:
                        writer.Write("M:");
                        WriteStaticConstructor((StaticInitializer)member, writer);
                        break;
                    case NodeType.Event:
                        writer.Write("E:");
                        WriteEvent((Event)member, writer);
                        break;
                }

                return (writer.ToString());

            }

        }
Exemplo n.º 16
0
    private void WriteDeclarationSourceContext(Member m, char definitionStart) {
      int startLine = m.SourceContext.StartLine;
      int startPos = m.SourceContext.StartPos;
      GetAttributesStartPos(m.Attributes, ref startLine, ref startPos);
      int defStartPos = m.SourceContext.SourceText.IndexOf(definitionStart);

      int declEnd;
      if (defStartPos >= 0) {
        // found definition start.
        declEnd = m.SourceContext.StartPos + defStartPos;
      }
      else {
        // no open brace, meaning it's probably abstract and we should include the whole thing
        // in the declaration.
        declEnd = m.SourceContext.EndPos;
      }
      SourceContext declEndContext = m.SourceContext;
      declEndContext.EndPos = declEnd;

      this.writer.WriteAttributeString("declStartLine", startLine.ToString());
      this.writer.WriteAttributeString("declEndLine", declEndContext.EndLine.ToString());
      this.writer.WriteAttributeString("declStartPos", startPos.ToString());
      this.writer.WriteAttributeString("declEndPos", declEnd.ToString());
    }
Exemplo n.º 17
0
    void AddReadAllGroup(Class serializer, Block block, TypeNode type, StatementList statements, Identifier reader, 
      Expression target, Expression required, Expression result, ArrayList members, Member mixedMember) {

      // todo: keep track of which members have been read and report error on duplicates
      MethodCall read = new MethodCall(new QualifiedIdentifier(reader, Identifier.For("Read")), new ExpressionList());

      Local sb = new Local(SystemTypes.StringBuilder);
      bool isMixed = mixedMember != null;
      if (isMixed) {
        statements.Add(new AssignmentStatement(sb,
          new Construct(new MemberBinding(null, SystemTypes.StringBuilder), new ExpressionList(), SystemTypes.StringBuilder)));
      }

      Block whileBody = new Block(new StatementList());
      BinaryExpression notEndTag = new BinaryExpression(
        new QualifiedIdentifier(reader, Identifier.For("NodeType")) ,
        new QualifiedIdentifier(Identifier.For("XmlNodeType"), Identifier.For("EndElement")), NodeType.Ne);
      BinaryExpression notEOF = new BinaryExpression(
        new QualifiedIdentifier(reader, Identifier.For("EOF")), Literal.True, NodeType.Ne);
      While w = new While(new BinaryExpression(notEndTag, notEOF, NodeType.And), whileBody);
      statements.Add(w);

      Local nameLocal = new Local(Identifier.For("name"),SystemTypes.String,block);
      Local nsLocal = new Local(Identifier.For("ns"),SystemTypes.String,block);
      Local nodeType = new Local(Identifier.For("nodeType"),Runtime.XmlNodeType,block);

      whileBody.Statements.Add(new AssignmentStatement(nameLocal, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
      whileBody.Statements.Add(new AssignmentStatement(nsLocal, new QualifiedIdentifier(reader, Identifier.For("NamespaceURI"))));
      whileBody.Statements.Add(new AssignmentStatement(nodeType, new QualifiedIdentifier(reader, Identifier.For("NodeType"))));
      
      Block childBlock = whileBody;

      if (isMixed) {
        // Append the text node to the current StringBuilder contents.
        childBlock = new Block(new StatementList());
        If ifText = new If(IsTextNode(nodeType), new Block(new StatementList()), childBlock);

        whileBody.Statements.Add(ifText);
        ExpressionList args = new ExpressionList();
        args.Add(new QualifiedIdentifier(reader, Identifier.For("Value")));
        ifText.TrueBlock.Statements.Add(new ExpressionStatement(new MethodCall(
          new QualifiedIdentifier(sb, Identifier.For("Append")), args)));
        ifText.TrueBlock.Statements.Add(new ExpressionStatement(read)); // advance to next node
      }      

      If ifElement = new If(new BinaryExpression(nodeType,
        new QualifiedIdentifier(Identifier.For("XmlNodeType"), Identifier.For("Element")), NodeType.Eq),
        new Block(new StatementList()), new Block(new StatementList()));
      childBlock.Statements.Add(ifElement);
      childBlock = ifElement.TrueBlock;

      //AddConsoleWrite(statements, new Literal("name=",SystemTypes.String));
      //AddConsoleWriteLine(statements, nameLocal);
      //AddConsoleWrite(statements, new Literal("nodeType=",SystemTypes.String));
      //AddConsoleWriteLine(statements, nodeType);

      foreach (NamedNode childNode in members) {
        if (!(childNode.Member is Field || childNode.Member is Property)) {
          AddError(statements, reader, RuntimeError.SerializationOfTypeNotSupported, 
            new Literal(childNode.Member.GetType().FullName, SystemTypes.String));
        } else {
          Expression mb = GetMemberBinding(target, childNode.Member);
          childBlock = AddReadChild(block, childBlock.Statements, childNode.Name, childNode.TypeNode, mb, reader, result, true, false).FalseBlock;
          // todo: throw error if child is required. (e.g. NonEmptyIEnumerable...)
        }
      }
      // if it isn't any of the expected elements then throw an error.
      AddError(childBlock.Statements, reader, RuntimeError.NoSuchMember,
        new Expression[2]{new Literal(tempChecker.GetTypeName(type),SystemTypes.String), nameLocal});

      // If it's not an element then consume it anyway to keep the reader advancing.
      // Probably a comment or PI or something.
      ifElement.FalseBlock.Statements.Add(new ExpressionStatement(new MethodCall(
        new QualifiedIdentifier(reader, Identifier.For("Skip")), new ExpressionList())));

      if (isMixed) {
        statements.Add(new AssignmentStatement(GetMemberBinding(target, mixedMember), 
          new MethodCall(new QualifiedIdentifier(sb, Identifier.For("ToString")), new ExpressionList())));         
      }
      statements.Add(new AssignmentStatement(result, Literal.True));

    }
Exemplo n.º 18
0
 MemberBinding GetMemberBinding(Expression source, Member m, TypeNode t) {
   MemberBinding src = new MemberBinding(source, m);
   src.Type = t;
   return src;
 }
Exemplo n.º 19
0
    void AddWriteMember(Member child, Identifier name, StatementList statements, TypeNode referringType, Expression src, Identifier writer, bool emptyElementOnNull) {

      src = GetMemberBinding(src, child);
      TypeNode type = src.Type;
      if (type == null) return;

      if (type.Template == SystemTypes.GenericBoxed) {
        statements = AddCheckForNull(statements, Duplicate(src, referringType), type);
        type = Checker.GetCollectionElementType(type);  
        src = CastTo(src, type);//unbox it
      }

      if (child.IsAnonymous) {
        if (type is TypeAlias) {
          TypeAlias alias = (TypeAlias)type;
          src = CastTo(src, alias.AliasedType); //unbox it
          AddWriteElement(statements, referringType, writer, alias.Name, src, alias.AliasedType, emptyElementOnNull);
        } else if (!AddWriteSimpleType(type, statements, referringType, writer, src, Literal.Null, Literal.Null)) {
          if (type is TupleType || type is TypeUnion || IsStream(type)) {
            AddCallSerializer(type, statements, src, writer, Literal.Null, Literal.Null);
          } else {
            AddWriteElement(statements, referringType, writer, type.Name, src, type, emptyElementOnNull);
          }
        }
          
      } else if (type is TypeAlias) {
        TypeAlias alias = (TypeAlias)type;
        src = CastTo(src, alias.AliasedType); //unbox it
        AddWriteElement(statements, referringType, writer, name, src, alias.AliasedType, emptyElementOnNull);
      } else {
        AddWriteElement(statements, referringType, writer, name, src, type, emptyElementOnNull);
      }
    }
Exemplo n.º 20
0
 void AddReadOptional(Block block, StatementList statements, Member mem, Expression target, Identifier reader, Expression result) {
   TypeNode boxed = Checker.GetMemberType(mem);
   TypeNode type = Checker.GetCollectionElementType(boxed);
   statements.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(reader, Identifier.For("MoveToContent")), new ExpressionList())));
   Local nameLocal = new Local(Identifier.For("name"),SystemTypes.String, block);
   Local nsLocal = new Local(Identifier.For("ns"),SystemTypes.String, block);
   statements.Add(new AssignmentStatement(nameLocal, new QualifiedIdentifier(reader, Identifier.For("LocalName"))));
   statements.Add(new AssignmentStatement(nsLocal, new QualifiedIdentifier(reader, Identifier.For("NamespaceURI"))));
   StringBuilder expecting = new StringBuilder();
   Expression isFound = null;
   if (mem.IsAnonymous) {
     isFound = IsStartOf(block, type, statements, nameLocal, nsLocal, expecting);    
   } else {
     ExpressionList args = new ExpressionList();
     args.Add(new Literal(mem.Name.Name, SystemTypes.String));
     isFound = new MethodCall(new QualifiedIdentifier(reader, Identifier.For("IsStartElement")), args);
   }
   StatementList trueStatements = new StatementList();
   If ifIsFound = new If(isFound, new Block(trueStatements), null);
   statements.Add(ifIsFound);
   
   if (!AddReadSimpleType(type, trueStatements, reader, target, result, false)) {
     Local localRequired = new Local(Identifier.Empty,SystemTypes.Boolean,block);
     statements.Add(new AssignmentStatement(localRequired, Literal.True));
     AddCallDeserializer(type, trueStatements, reader, target, localRequired, result);            
   } 
 }
Exemplo n.º 21
0
 MemberBinding GetMemberBinding(Expression source, Member m) {
   MemberBinding src = new MemberBinding(source, m);
   src.Type = Checker.GetMemberType(m);
   return src;
 }
Exemplo n.º 22
0
        internal static void TryAddDebuggerBrowsableNeverAttribute(Member member, System.AttributeTargets targets)
        {
            Contract.Requires(member != null);

            try
            {
                if (HelperMethods.debuggerBrowsableAttributeNode == null) return;
                if (HelperMethods.debuggerBrowsableStateType == null) return;
                var ctor = HelperMethods.debuggerBrowsableAttributeNode.GetConstructor(HelperMethods.debuggerBrowsableStateType);
                var args = new ExpressionList(Literal.Int32Zero);
                var attribute = new AttributeNode(new MemberBinding(null, ctor), args, targets);
                member.Attributes.Add(attribute);
            }
            catch
            { }
        }
Exemplo n.º 23
0
        internal static void TryAddCompilerGeneratedAttribute(Member member, System.AttributeTargets targets)
        {
          Contract.Requires(member != null);

            if (HelperMethods.compilerGeneratedAttributeNode == null) return;
            Member compilerGenerated = HelperMethods.compilerGeneratedAttributeNode.GetConstructor();
            AttributeNode compilerGeneratedAttribute = new AttributeNode(new MemberBinding(null, compilerGenerated), null, targets);
            member.Attributes.Add(compilerGeneratedAttribute);
        }
Exemplo n.º 24
0
 /// <summary>
 /// This is used to visit a member
 /// </summary>
 /// <param name="member">The member to visit</param>
 protected virtual void VisitMember(Member member)
 {
     this.VisitEntity(member);
 }
Exemplo n.º 25
0
 /// <summary>
 /// This method can be overridden in derived classes to handle common tasks that should occur before an
 /// API member of any kind is visited.
 /// </summary>
 /// <param name="entity">The entity to be visited</param>
 /// <remarks>The default implementation does nothing</remarks>
 protected virtual void VisitEntity(Member entity)
 {
 }
Exemplo n.º 26
0
 public override bool LanguageSpecificSupression(Member m){
   Debug.Assert(m != null);
   Method meth = m as Method;
   if (meth != null && meth.Name.UniqueIdKey == StandardIds.Finalize.UniqueIdKey && meth.ReturnType == SystemTypes.Void && (meth.Parameters == null || meth.Parameters.Count == 0))
     return true;
   return false;
 }
Exemplo n.º 27
0
 /// <summary>
 /// This method is used to get the member name
 /// </summary>
 /// <param name="space">The member for which to get the name</param>
 /// <returns>The member name</returns>
 public abstract string GetMemberName(Member member);
Exemplo n.º 28
0
        public static Module AssemblyOf(Member m)
        {
            Contract.Requires(m != null);

            TypeNode t = m as TypeNode;
            if (t == null)
            {
                t = m.DeclaringType;
                Contract.Assume(t != null, "non-types must have a declaring type");
            }

            while (t.DeclaringType != null)
            {
                t = t.DeclaringType;
            }

            return t.DeclaringModule;
        }
Exemplo n.º 29
0
 public static Member GetCorrespondingMember(Member/*!*/ member, TypeNode/*!*/ specializedType)
 {
     //member belongs to a structural type based on a type parameter.
     //return the corresponding member from the structural type based on the type argument.
     if (member.DeclaringType == null) { Debug.Fail(""); return null; }
     MemberList unspecializedMembers = member.DeclaringType.Members;
     MemberList specializedMembers = specializedType.Members;
     if (unspecializedMembers == null || specializedMembers == null) { Debug.Assert(false); return null; }
     int unspecializedOffset = 0;
     int specializedOffset = 0;
     //The offsets can become > 0 when the unspecialized type and/or specialized type is imported from another assembly 
     //(and the unspecialized type is in fact a partially specialized type.)
     for (int i = 0, n = specializedMembers == null ? 0 : specializedMembers.Count; i < n; i++)
     {
         Member unspecializedMember = unspecializedMembers[i - unspecializedOffset];
         Member specializedMember = specializedMembers[i - specializedOffset];
         if (unspecializedMember != null && specializedMember == null && unspecializedOffset == i &&
           !(unspecializedMember is TypeParameter || unspecializedMember is ClassParameter))
         {
             unspecializedOffset++; continue; //Keep current unspecialized member, skip over null specialized member
         }
         if (unspecializedMember == null && specializedMember != null && specializedOffset == i &&
           !(specializedMember is TypeParameter || specializedMember is ClassParameter))
         {
             specializedOffset++; continue; //Keep current specialized member, skip over null
         }
         if (unspecializedMember == member)
         {
             Debug.Assert(specializedMember != null);
             return specializedMember;
         }
     }
     Debug.Assert(false);
     return null;
 }
Exemplo n.º 30
0
 public override string GetInstanceMemberSignature(Member mem)
 {
     Field f = mem as Field;
     Method m = mem as Method;
     TypeNode mType = f != null ? f.Type : m != null ? m.ReturnType : null;
     string mName = mem.Name.ToString();
     return this.GetTypeName(mType) + " this." + mName;
 }