示例#1
0
        public ITypeInfo[] GetGenericArguments()
        {
            if (!NullabilityInfo.IsEmpty() && this.HasItem())
            {
                return new ITypeInfo[] { new TypeInfo(Type.GetGenericArguments()[0], NullabilityInfo.ForItem()) }
            }
            ;

            var args            = Type.GetGenericArguments();
            var argsNullability = NullabilityInfo.ForGenericArguments(NullabilityInfo, args);

            return(args.Select((x, i) => (ITypeInfo) new TypeInfo(x, argsNullability[i])).ToArray());
        }
        public static NullabilityInfo[] ForGenericArguments(NullabilityInfo nullabilityInfo, Type[] args)
        {
            if (nullabilityInfo.NullableInfo == null || nullabilityInfo.NullableInfo.Length < 2)
            {
                return(args.Select(x => new NullabilityInfo(nullabilityInfo.NullableContext, nullabilityInfo.NullableInfo)).ToArray());
            }

            var result = new List <NullabilityInfo>();
            var index  = 1;

            foreach (var arg in args)
            {
                var argsLength = GetGenericArgumentsToSkip(arg);
                result.Add(argsLength == 0
                               ? Empty
                               : new NullabilityInfo(
                               nullabilityInfo.NullableContext,
                               nullabilityInfo.NullableInfo.Skip(index).Take(argsLength).ToArray()
                               )
                           );
                index += argsLength;
            }
            return(result.ToArray());
        }
示例#3
0
 private TypeInfo(Type type, IAttributeProvider memberInfo)
 {
     Type            = type;
     Member          = memberInfo;
     NullabilityInfo = NullabilityInfo.From(memberInfo);
 }
示例#4
0
 private TypeInfo(Type type, NullabilityInfo nullabilityInfo)
 {
     Type            = type;
     NullabilityInfo = nullabilityInfo;
 }
示例#5
0
 public bool CanBeNull(NullabilityMode nullabilityMode)
 {
     return(!this.NeverNull() && NullabilityInfo.CanBeNull(nullabilityMode));
 }
示例#6
0
 public ITypeInfo GetElementType()
 {
     return(new TypeInfo(Type.GetElementType(), NullabilityInfo.ForItem()));
 }
 private RoslynTypeInfo(ITypeSymbol typeSymbol, IAttributeProvider memberInfo)
 {
     TypeSymbol      = typeSymbol;
     Member          = memberInfo;
     NullabilityInfo = NullabilityInfo.FromRoslyn(memberInfo);
 }
 private RoslynTypeInfo(ITypeSymbol typeSymbol, NullabilityInfo nullabilityInfo)
 {
     TypeSymbol      = typeSymbol;
     NullabilityInfo = nullabilityInfo;
 }