Exemple #1
0
        public virtual InsType VisitNamed(InsNamedType type, TArgument argument)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (type.DeclaringType != null)
            {
                var declaringType = (InsNamedType)type.DeclaringType.Apply(this, argument);

                if (declaringType == type.DeclaringType)
                {
                    return(type);
                }

                return(new InsNamedType(type.Name, declaringType));
            }
            else
            {
                var assembly = type.Assembly == null ? null : VisitAssembly(type.Assembly, argument);

                if (assembly == type.Assembly)
                {
                    return(type);
                }

                return(new InsNamedType(type.Name, assembly));
            }
        }
            static InsAssembly?AssemblyFromNamed(InsNamedType type)
            {
                while (type.DeclaringType != null)
                {
                    type = type.DeclaringType;
                }

                return(type.Assembly);
            }
            InsType ParseUnqualified(ref int index, InsAssembly?assembly)
            {
                var identifier = ParseIdentifier(ref index);
                var baseType   = new InsNamedType(identifier, assembly);

                while (TryReadChar(ref index, '+'))
                {
                    AssertNotEOF(index);
                    identifier = ParseIdentifier(ref index);
                    baseType   = new InsNamedType(identifier, baseType);
                }

                InsType type;

                if (index + 1 < _buffer.Length &&
                    _buffer[index] == '[' &&
                    _buffer[index + 1] != ']' &&
                    _buffer[index + 1] != ',' &&
                    _buffer[index + 1] != '*')
                {
                    var typeArguments = ParseTypeArguments(ref index);
                    type = new InsGenericType(baseType, typeArguments);
                }
                else
                {
                    type = baseType;
                }

                while (index < _buffer.Length)
                {
                    var c = _buffer[index];

                    if (c == '*')
                    {
                        type = new InsPointerType(type);
                        index++;
                    }
                    else if (c == '[')
                    {
                        type = ParseArrayDetails(ref index, type);
                    }
                    else
                    {
                        break;
                    }
                }

                if (TryReadChar(ref index, '&'))
                {
                    type = new InsByRefType(type);
                }

                return(type);
            }
            public StringBuilder VisitNamed(InsNamedType type, StringBuilder builder)
            {
                if (type.DeclaringType != null)
                {
                    type.DeclaringType.Apply(this, builder);
                    builder.Append('+');
                }

                WriteIdentifier(type.Name, builder);

                return(builder);
            }
Exemple #5
0
 internal InsGenericType(InsNamedType definition, ImmutableArray <InsType> typeArguments)
 {
     Definition    = definition ?? throw new ArgumentNullException(nameof(definition));
     TypeArguments = typeArguments;
 }
 public InsAssembly?VisitNamed(InsNamedType type, object argument) => AssemblyFromNamed(type);
 public static InsNamedType NestedType(InsNamedType declaringType, string name)
 => new InsNamedType(name, declaringType);
 public static InsGenericType Generic(InsNamedType definition, ImmutableArray <InsType> typeArguments)
 => new InsGenericType(definition, typeArguments);
 public static InsGenericType Generic(InsNamedType definition, params InsType[] typeArguments)
 => Generic(definition, ImmutableArray.Create(typeArguments));