示例#1
0
        protected override string GetTypeName(TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
        {
            int n = type.Name.IndexOf("`");

            if (n >= 0)
            {
                return(type.Name.Substring(0, n));
            }
            return(type.Name);
        }
示例#2
0
        protected override string GetTypeName(TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = true, bool isTypeofOperator = false)
        {
            GenericInstanceType genType = type as GenericInstanceType;

            if (IsSpecialGenericNullableValueType(genType))
            {
                return(AppendSpecialGenericNullableValueTypeName(new StringBuilder(), genType, context, appendGeneric, useTypeProjection).ToString());
            }

            return(base.GetTypeName(type, context, appendGeneric, useTypeProjection));
        }
        protected override StringBuilder AppendArrayTypeName(StringBuilder buf, TypeReference type,
                                                             IAttributeParserContext context)
        {
            buf.Append("winrt::array_view <");

            var item = type is TypeSpecification spec ? spec.ElementType : type.GetElementType();

            _AppendTypeName(buf, item, context);
            AppendHat(buf, item);

            if (type is ArrayType arrayType)
            {
                int rank = arrayType.Rank;
                if (rank > 1)
                {
                    buf.AppendFormat(", {0}", rank);
                }
            }

            buf.Append(">");

            return(buf);
        }
        private StringBuilder AppendType(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(type);
            bool insertNested          = false;
            int  prevParamCount        = 0;

            foreach (var decl in decls)
            {
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;
                base.AppendTypeName(buf, decl, context);
                int argCount = DocUtils.GetGenericArgumentCount(decl);
                int numArgs  = argCount - prevParamCount;
                prevParamCount = argCount;
                if (numArgs > 0)
                {
                    buf.Append('`').Append(numArgs);
                }
            }
            return(buf);
        }
 protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
 {
     if (!AddTypeCount)
     {
         base.AppendGenericType(buf, type, context);
     }
     else
     {
         AppendType(buf, type, context);
     }
     return(buf);
 }
示例#6
0
        protected override StringBuilder AppendPointerTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            TypeSpecification spec = type as TypeSpecification;

            _AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context);
            AppendHat(buf, type);
            buf.Append(PointerModifier);
            return(buf);
        }
示例#7
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int  argIndex = 0;
            int  previouslyAppliedCount = 0;
            bool insertNested           = false;

            foreach (var decl in decls)
            {
                TypeReference declDef;
                try
                {
                    declDef = decl.Resolve() ?? decl;
                }
                catch
                {
                    //Resolve() can fail as sometimes Cecil understands types as .net
                    //needs to ignore those errors
                    declDef = decl;
                }

                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;
                AppendTypeName(buf, declDef, context);
                int argumentCount      = DocUtils.GetGenericArgumentCount(declDef);
                int countLeftUnapplied = argumentCount - previouslyAppliedCount;
                previouslyAppliedCount = argumentCount;
                var lastItem = decls.Last();
                if (countLeftUnapplied > 0 &&
                    (appendGeneric
                     //this is to add generic syntax for parent classes in declaration of nested class
                     //eg, ref class MyList<T>::Helper -> needs to add <T> to MyList class
                     || decls.Count >= 2 && decl != lastItem)
                    )
                {
                    buf.Append(GenericTypeContainer[0]);
                    var origState = MemberFormatterState;
                    MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters;

                    var item = genArgs[argIndex++];
                    _AppendTypeName(buf, item, context, useTypeProjection: useTypeProjection);
                    if (declDef.GenericParameters.All(x => x.FullName != item.FullName))
                    {
                        AppendHat(buf, item, AppendHatOnReturn);
                    }

                    for (int i = 1; i < countLeftUnapplied; ++i)
                    {
                        var newItem = genArgs[argIndex++];
                        _AppendTypeName(buf.Append(", "), newItem, context);
                        if (declDef.GenericParameters.All(x => x.FullName != newItem.FullName))
                        {
                            //add hat only for non-generic types
                            AppendHat(buf, newItem);
                        }
                    }
                    MemberFormatterState = origState;
                    buf.Append(GenericTypeContainer[1]);
                }
            }
            return(buf);
        }
示例#8
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            string typeFullName = type.FullName;

            if (string.IsNullOrWhiteSpace(typeFullName))
            {
                return(buf);
            }

            string cppType = GetCppType(typeFullName);

            if (cppType != null)
            {
                return(buf.Append(cppType));
            }

            return(base.AppendTypeName(buf, type, context));
        }
示例#9
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            if (type is GenericParameter)
            {
                AppendGenericParameterConstraints(buf, (GenericParameter)type).Append(type.Name);
                return(buf);
            }

            string s = GetBuiltinType(type.FullName);

            if (s != null)
            {
                return(buf.Append(s));
            }
            return(base.AppendTypeName(buf, type, context));
        }
示例#10
0
        private StringBuilder AppendGenericParameterConstraints(StringBuilder buf, GenericParameter type, IAttributeParserContext context)
        {
            if (MemberFormatterState != MemberFormatterState.WithinGenericTypeParameters)
            {
                return(buf);
            }
            GenericParameterAttributes attrs = type.Attributes;
            bool isout = (attrs & GenericParameterAttributes.Covariant) != 0;
            bool isin  = (attrs & GenericParameterAttributes.Contravariant) != 0;

            if (isin)
            {
                buf.Append("In ");
            }
            else if (isout)
            {
                buf.Append("Out ");
            }
            return(buf);
        }
示例#11
0
        protected override StringBuilder AppendSpecialGenericNullableValueTypeName(StringBuilder buf, GenericInstanceType genInst, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = true)
        {
            if (genInst.Name.StartsWith("Nullable`") && genInst.HasGenericArguments)
            {
                var underlyingTypeName = GetTypeName(genInst.GenericArguments.First(), context, appendGeneric, useTypeProjection);
                buf.Append(underlyingTypeName + "?");

                return(buf);
            }

            if (genInst.Name.StartsWith("ValueTuple`"))
            {
                buf.Append("(");
                var genArgList = new List <string> ();
                foreach (var item in genInst.GenericArguments)
                {
                    var isNullableType = false;
                    if (!item.IsValueType)
                    {
                        isNullableType = context.IsNullable();
                    }

                    var underlyingTypeName = GetTypeName(item, context, appendGeneric, useTypeProjection) + GetTypeNullableSymbol(item, isNullableType);
                    genArgList.Add(underlyingTypeName);
                }
                buf.Append(string.Join(",", genArgList));
                buf.Append(")");

                return(buf);
            }

            return(buf);
        }
示例#12
0
        protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            ByReferenceType reftype = type as ByReferenceType;

            return(AppendTypeName(buf, reftype?.ElementType, context));
        }
示例#13
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int  argIdx = 0;
            int  displayedInParentArguments = 0;
            bool insertNested = false;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;

                bool isTuple = IsTuple(type)
                               // If this is a declaration of `Tuple` type
                               // treat it as an ordinary type
                               && !(type is TypeDefinition);
                bool isFSharpFunction = IsFSharpFunction(type);
                if (!isTuple && !isFSharpFunction)
                {
                    AppendTypeName(buf, declDef, context);
                }

                int argumentCount            = DocUtils.GetGenericArgumentCount(declDef);
                int notYetDisplayedArguments = argumentCount - displayedInParentArguments;
                displayedInParentArguments = argumentCount;// nested TypeReferences have parents' generic arguments, but we shouldn't display them
                if (notYetDisplayedArguments > 0)
                {
                    if (!isTuple && !isFSharpFunction)
                    {
                        buf.Append(GenericTypeContainer[0]);
                    }
                    if (isFSharpFunction && genericParameterState == GenericParameterState.WithinTuple)
                    {
                        buf.Append("(");
                    }
                    var origState = MemberFormatterState;
                    var genericParameterStateOrigState = genericParameterState;
                    MemberFormatterState  = MemberFormatterState.WithinGenericTypeParameters;
                    genericParameterState = isTuple ? GenericParameterState.WithinTuple : GenericParameterState.None;

                    for (int i = 0; i < notYetDisplayedArguments; ++i)
                    {
                        if (i > 0)
                        {
                            buf.Append(isTuple ? " * " : isFSharpFunction ? " -> " : ", ");
                        }
                        var genArg           = genArgs[argIdx++];
                        var genericParameter = genArg as GenericParameter;
                        if (genericParameter != null && IsFlexibleType(genericParameter))
                        {
                            buf.Append("#");// replace genericParameter which is a flexible type with its constraint type
#if NEW_CECIL
                            _AppendTypeName(buf, genericParameter.Constraints[0].ConstraintType, context, useTypeProjection: useTypeProjection);
#else
                            _AppendTypeName(buf, genericParameter.Constraints[0], context, useTypeProjection: useTypeProjection);
#endif
                        }
                        else
                        {
                            _AppendTypeName(buf, genArg, context);
                        }
                    }
                    MemberFormatterState  = origState;
                    genericParameterState = genericParameterStateOrigState;

                    if (MemberFormatterState == MemberFormatterState.None)
                    {
                        AppendConstraints(buf,
                                          genArgs.GetRange(0, notYetDisplayedArguments)
                                          .SafeCast <GenericParameter>()
                                          .ToList());
                    }
                    if (!isTuple && !isFSharpFunction)
                    {
                        buf.Append(GenericTypeContainer[1]);
                    }
                    if (isFSharpFunction && genericParameterState == GenericParameterState.WithinTuple)
                    {
                        buf.Append(")");
                    }
                }
            }
            return(buf);
        }
示例#14
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            if (type == null)
            {
                return(buf);
            }

            string fSharpType = GetFSharpType(type);

            if (fSharpType != null)
            {
                return(buf.Append(fSharpType));
            }

            if (type.IsGenericParameter)
            {
                return(buf.Append(GetGenericName(type.Name)));
            }

            return(base.AppendTypeName(buf, type, context));
        }
示例#15
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            bool first = true;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (!first)
                {
                    buf.Append(NestedTypeSeparator);
                }
                first = false;
                AppendTypeName(buf, declDef, context);
            }
            buf.Append('<');
            first = true;
            foreach (TypeReference arg in GetGenericArguments(type))
            {
                if (!first)
                {
                    buf.Append(", ");
                }
                first = false;
                _AppendTypeName(buf, arg, context);
            }
            buf.Append('>');
            return(buf);
        }
 protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
 {
     if (type is GenericParameter)
     {
         int l = buf.Length;
         if (genDeclType != null)
         {
             IList <GenericParameter> genArgs = genDeclType.GenericParameters;
             for (int i = 0; i < genArgs.Count; ++i)
             {
                 if (genArgs[i].Name == type.Name)
                 {
                     buf.Append('`').Append(i);
                     break;
                 }
             }
         }
         if (genDeclMethod != null)
         {
             IList <GenericParameter> genArgs = null;
             if (genDeclMethod.IsGenericMethod())
             {
                 genArgs = genDeclMethod.GenericParameters;
                 for (int i = 0; i < genArgs.Count; ++i)
                 {
                     if (genArgs[i].Name == type.Name)
                     {
                         buf.Append("``").Append(i);
                         break;
                     }
                 }
             }
         }
         if ((genDeclType == null && genDeclMethod == null) || buf.Length == l)
         {
             // Probably from within an explicitly implemented interface member,
             // where CSC uses parameter names instead of indices (why?), e.g.
             // MyList`2.Mono#DocTest#Generic#IFoo{A}#Method``1(`0,``0) instead of
             // MyList`2.Mono#DocTest#Generic#IFoo{`0}#Method``1(`0,``0).
             buf.Append(type.Name);
         }
     }
     else
     {
         base.AppendTypeName(buf, type, context);
         if (AddTypeCount)
         {
             int numArgs = type.GenericParameters.Count;
             if (type.DeclaringType != null)
             {
                 numArgs -= type.GenericParameters.Count;
             }
             if (numArgs > 0)
             {
                 buf.Append('`').Append(numArgs);
             }
         }
     }
     return(buf);
 }
 protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
 {
     return(base.AppendRefTypeName(buf, type, context).Append(RefTypeModifier));
 }
示例#18
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int  argIdx = 0;
            int  displayedInParentArguments = 0;
            bool insertNested = false;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (insertNested)
                {
                    buf.Append(NestedTypeSeparator);
                }
                insertNested = true;

                AppendTypeName(buf, declDef, context);

                int argumentCount            = DocUtils.GetGenericArgumentCount(declDef);
                int notYetDisplayedArguments = argumentCount - displayedInParentArguments;
                displayedInParentArguments = argumentCount;// nested TypeReferences have parents' generic arguments, but we shouldn't display them
                if (notYetDisplayedArguments > 0)
                {
                    buf.Append(GenericTypeContainer[0]);
                    var origState = MemberFormatterState;
                    MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters;
                    for (int i = 0; i < notYetDisplayedArguments; ++i)
                    {
                        if (i > 0)
                        {
                            buf.Append(", ");
                        }
                        var genArg = genArgs[argIdx++];
                        _AppendTypeName(buf, genArg, context, useTypeProjection: useTypeProjection);
                        var genericParameter = genArg as GenericParameter;
                        if (genericParameter != null)
                        {
                            AppendConstraints(buf, genericParameter);
                        }
                    }
                    MemberFormatterState = origState;
                    buf.Append(GenericTypeContainer[1]);
                }
            }
            return(buf);
        }
示例#19
0
        protected override StringBuilder AppendTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            if (type is GenericParameter)
            {
                return(AppendGenericParameterConstraints(buf, (GenericParameter)type, context).Append(type.Name));
            }
            string t = type.FullName;

            if (!t.StartsWith("System."))
            {
                return(base.AppendTypeName(buf, type, context));
            }

            string s = GetVBType(t);

            if (s != null)
            {
                context.NextDynamicFlag();
                return(buf.Append(s));
            }

            return(base.AppendTypeName(buf, type, context));
        }
示例#20
0
        protected override StringBuilder AppendRefTypeName(StringBuilder buf, TypeReference type, IAttributeParserContext context)
        {
            TypeSpecification spec = type as TypeSpecification;

            return(_AppendTypeName(buf, spec != null ? spec.ElementType : type.GetElementType(), context).Append(RefTypeModifier));
        }