コード例 #1
0
        void ConvertParameters(IList <IParameter> outputList, IEnumerable <ParameterDeclaration> parameters)
        {
            foreach (ParameterDeclaration pd in parameters)
            {
                DefaultParameter p = new DefaultParameter(ConvertType(pd.Type), pd.Name);
                p.Region = MakeRegion(pd);
                ConvertAttributes(p.Attributes, pd.Attributes);
                switch (pd.ParameterModifier)
                {
                case ParameterModifier.Ref:
                    p.IsRef = true;
                    p.Type  = ByReferenceTypeReference.Create(p.Type);
                    break;

                case ParameterModifier.Out:
                    p.IsOut = true;
                    p.Type  = ByReferenceTypeReference.Create(p.Type);
                    break;

                case ParameterModifier.Params:
                    p.IsParams = true;
                    break;
                }
                if (!pd.DefaultExpression.IsNull)
                {
                    p.DefaultValue = ConvertConstantValue(p.Type, pd.DefaultExpression);
                }
                outputList.Add(p);
            }
        }
コード例 #2
0
        static ITypeReference ParseTypeName(string typeName, ref int pos)
        {
            string reflectionTypeName = typeName;

            if (pos == typeName.Length)
            {
                throw new ReflectionNameParseException(pos, "Unexpected end");
            }
            ITypeReference result;

            if (reflectionTypeName[pos] == '`')
            {
                // type parameter reference
                pos++;
                if (pos == reflectionTypeName.Length)
                {
                    throw new ReflectionNameParseException(pos, "Unexpected end");
                }
                if (reflectionTypeName[pos] == '`')
                {
                    // method type parameter reference
                    pos++;
                    int index = ReflectionHelper.ReadTypeParameterCount(reflectionTypeName, ref pos);
                    result = TypeParameterReference.Create(SymbolKind.Method, index);
                }
                else
                {
                    // class type parameter reference
                    int index = ReflectionHelper.ReadTypeParameterCount(reflectionTypeName, ref pos);
                    result = TypeParameterReference.Create(SymbolKind.TypeDefinition, index);
                }
            }
            else
            {
                // not a type parameter reference: read the actual type name
                List <ITypeReference> typeArguments = new List <ITypeReference>();
                int    typeParameterCount;
                string typeNameWithoutSuffix = ReadTypeName(typeName, ref pos, true, out typeParameterCount, typeArguments);
                result = new GetPotentiallyNestedClassTypeReference(typeNameWithoutSuffix, typeParameterCount);
                while (pos < typeName.Length && typeName[pos] == '.')
                {
                    pos++;
                    string nestedTypeName = ReadTypeName(typeName, ref pos, false, out typeParameterCount, typeArguments);
                    result = new NestedTypeReference(result, nestedTypeName, typeParameterCount);
                }
                if (typeArguments.Count > 0)
                {
                    result = new ParameterizedTypeReference(result, typeArguments);
                }
            }
            while (pos < typeName.Length)
            {
                switch (typeName[pos])
                {
                case '[':
                    int dimensions = 1;
                    do
                    {
                        pos++;
                        if (pos == typeName.Length)
                        {
                            throw new ReflectionNameParseException(pos, "Unexpected end");
                        }
                        if (typeName[pos] == ',')
                        {
                            dimensions++;
                        }
                    } while (typeName[pos] != ']');
                    result = new ArrayTypeReference(result, dimensions);
                    break;

                case '*':
                    result = new PointerTypeReference(result);
                    break;

                case '@':
                    result = new ByReferenceTypeReference(result);
                    break;

                default:
                    return(result);
                }
                pos++;
            }
            return(result);
        }
コード例 #3
0
        static void AppendTypeName(StringBuilder b, ITypeReference type, ITypeResolveContext context)
        {
            IType resolvedType = type as IType;

            if (resolvedType != null)
            {
                AppendTypeName(b, resolvedType);
                return;
            }
            GetClassTypeReference gctr = type as GetClassTypeReference;

            if (gctr != null)
            {
                if (!string.IsNullOrEmpty(gctr.Namespace))
                {
                    b.Append(gctr.Namespace);
                    b.Append('.');
                }
                b.Append(gctr.Name);
                if (gctr.TypeParameterCount > 0)
                {
                    b.Append('`');
                    b.Append(gctr.TypeParameterCount);
                }
                return;
            }
            NestedTypeReference ntr = type as NestedTypeReference;

            if (ntr != null)
            {
                AppendTypeName(b, ntr.DeclaringTypeReference, context);
                b.Append('.');
                b.Append(ntr.Name);
                if (ntr.AdditionalTypeParameterCount > 0)
                {
                    b.Append('`');
                    b.Append(ntr.AdditionalTypeParameterCount);
                }
                return;
            }
            ParameterizedTypeReference pt = type as ParameterizedTypeReference;

            if (pt != null && IsGetClassTypeReference(pt.GenericType))
            {
                AppendParameterizedTypeName(b, pt.GenericType, pt.TypeArguments, context);
                return;
            }
            ArrayTypeReference array = type as ArrayTypeReference;

            if (array != null)
            {
                AppendTypeName(b, array.ElementType, context);
                b.Append('[');
                if (array.Dimensions > 1)
                {
                    for (int i = 0; i < array.Dimensions; i++)
                    {
                        if (i > 0)
                        {
                            b.Append(',');
                        }
                        b.Append("0:");
                    }
                }
                b.Append(']');
                return;
            }
            PointerTypeReference ptr = type as PointerTypeReference;

            if (ptr != null)
            {
                AppendTypeName(b, ptr.ElementType, context);
                b.Append('*');
                return;
            }
            ByReferenceTypeReference brtr = type as ByReferenceTypeReference;

            if (brtr != null)
            {
                AppendTypeName(b, brtr.ElementType, context);
                b.Append('@');
                return;
            }
            if (context == null)
            {
                b.Append('?');
            }
            else
            {
                AppendTypeName(b, type.Resolve(context));
            }
        }