Example #1
0
        // if a member is a member of an instantiated class search for the 'real' uninstantiated member
        // ex. List<string> a; a.Count<-;  should search for List<T>.Count instead of List<string>.Count
        static IMember GetUnderlyingMember(IMember member)
        {
            if (member == null)
            {
                return(null);
            }

            if (member.DeclaringType is InstantiatedType && member.ReturnType != null)
            {
                IType uninstantiatedType = ((InstantiatedType)member.DeclaringType).UninstantiatedType;
                foreach (IMember realMember in uninstantiatedType.SearchMember(member.Name, true))
                {
                    if (realMember.ReturnType == null)
                    {
                        continue;
                    }
                    if (realMember.MemberType == member.MemberType)
                    {
                        switch (member.MemberType)
                        {
                        case MemberType.Method:
                            if (((IMethod)member).TypeParameters.Count != ((IMethod)realMember).TypeParameters.Count)
                            {
                                continue;
                            }
                            if (!DomMethod.ParameterListEquals(((IMethod)member).Parameters, ((IMethod)realMember).Parameters))
                            {
                                continue;
                            }
                            break;

                        case MemberType.Property:
                            if (!DomMethod.ParameterListEquals(((IProperty)member).Parameters, ((IProperty)realMember).Parameters))
                            {
                                continue;
                            }
                            break;
                        }
                        return(realMember);
                    }
                }
            }
            return(member);
        }
            void AppendModifiers(StringBuilder result, CSharpCodeGenerator.CodeGenerationOptions options, IMember member)
            {
                generator.AppendIndent(result);
                if (options.ExplicitDeclaration || options.ImplementingType.ClassType == ClassType.Interface)
                {
                    return;
                }
                result.Append(GetModifiers(options.ImplementingType, member));

                bool isFromInterface = false;

                if (member.DeclaringType != null && member.DeclaringType.ClassType == ClassType.Interface)
                {
                    isFromInterface = true;
                    if (options.ImplementingType != null)
                    {
                        foreach (IType type in options.ImplementingType.SourceProjectDom.GetInheritanceTree(options.ImplementingType))
                        {
                            if (type.ClassType == ClassType.Interface)
                            {
                                continue;
                            }
                            if (type.SearchMember(member.Name, true).Any(m => m.Name == member.Name && member.MemberType == m.MemberType && DomMethod.ParameterListEquals(member.Parameters, m.Parameters)))
                            {
                                isFromInterface = false;
                                break;
                            }
                        }
                    }
                }
                if (!isFromInterface && ((member.Modifiers & Modifiers.Virtual) == Modifiers.Virtual ||
                                         (member.Modifiers & Modifiers.Abstract) == Modifiers.Abstract))
                {
                    result.Append("override ");
                }
            }