예제 #1
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            var args = TypeArguments
                       .Select(r => r.ToString())
                       .DelimitWith(", ", null, "<", ">");

            return(Name + args + Suffix);
        }
예제 #2
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = (Name != null ? Name.GetHashCode() : 0);
         foreach (var typeArgument in TypeArguments.Select(x => x.Value))
         {
             hashCode = (hashCode * 397) ^ typeArgument.GetHashCode();
         }
         hashCode ^= OriginalDefinitionSyntax.GetHashCode();
         return(hashCode);
     }
 }
예제 #3
0
        public override IType WithSubstitutedTypes(ISet <Substitution> typeMap)
        {
            var typeArguments = TypeArguments.Select(x => new Lazy <IType>(() => x.Value.WithSubstitutedTypes(typeMap))).ToImmutableArray();

            return(new StructType(originalSyntax: OriginalDefinitionSyntax,
                                  typeArguments: typeArguments,
                                  typeArgumentsNames: typeArguments.Select(x => x.Value.Name).ToImmutableArray(),
                                  inlinedTypes: InlinedTypes.Select(type => new Lazy <IType>(() => type.Value.WithSubstitutedTypes(typeMap))).ToImmutableArray(),
                                  fields: Fields.Select(field => new Lazy <Field>(() => new Field(originalSyntax: field.Value.OriginalSyntax,
                                                                                                  originalOwnerSyntax: field.Value.OriginalOwnerSyntax,
                                                                                                  type: field.Value.Type.WithSubstitutedTypes(typeMap)))).ToImmutableArray(),
                                  this));
        }
예제 #4
0
 public bool Equals(StructType other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(string.Equals(Name, other.Name) &&
            TypeArguments.Select(x => x.Value).SequenceEqual(other.TypeArguments.Select(x => x.Value)) &&
            OriginalDefinitionSyntax.Equals(other.OriginalDefinitionSyntax));
 }
예제 #5
0
        /// <summary>
        /// Attempt to create the type that corresponds to that description.
        /// </summary>
        public Type Resolve()
        {
#if __PCL__
            throw new PlatformNotSupportedException("PCL");
#else
            var type = KnownAssemblies.GetType(Fullname, AssemblyName);
            if (type == null)
            {
                return(null);
            }
            if (TypeArguments.Count > 0)
            {
                if (!type.GetTypeInfo().IsGenericTypeDefinition || type.GetTypeInfo().GetGenericArguments().Length != TypeArguments.Count)
                {
                    return(null);
                }
                var args = TypeArguments.Select(x => x.Resolve()).ToArray();
                if (args.Any(x => x == null))
                {
                    return(null);
                }
                type = type.MakeGenericType(args);
            }
            if (PointerCount > 0)
            {
                int pc = PointerCount;
                while (pc-- > 0)
                {
                    type = type.MakePointerType();
                }
            }
            foreach (var rank in ArrayRanks)
            {
                if (rank == 1)
                {
                    type = type.MakeArrayType();
                }
                else
                {
                    type = type.MakeArrayType(rank);
                }
            }
            return(type);
#endif
        }
예제 #6
0
        private string GetTypeArgumentText()
        {
            var typeParam = TypeArguments.Select(argument => argument.NameWithTypeArguments).ToList();

            return(typeParam.Count != 0 ? "<" + string.Join(", ", typeParam) + ">" : "");
        }