Beispiel #1
0
 internal static Exception InvalidInterfaceType(String parameterName, Type interfaceType)
 => Logger.Fatal.ArgumentFormat(
     parameterName,
     SR.ResolveResultFactory_PropertyTypeUnknownInterface,
     interfaceType,
     String.Join(", ", KnownPropertyTypeDefinitions.Select(t => t.Name))
     );
Beispiel #2
0
        private static ResolvedPropertyTypeInfo Parse(TypeInfo propertyTypeInfo, Boolean throwException)
        {
            if (propertyTypeInfo == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(propertyTypeInfo));
            }

            if (!propertyTypeInfo.IsGenericType)
            {
                if (!throwException)
                {
                    return(null);
                }

                throw Logger.Fatal.ArgumentFormat(
                          nameof(propertyTypeInfo),
                          SR.ResolveResultFactory_PropertyTypeNotGeneric,
                          propertyTypeInfo
                          );
            }

            var interfaceType = propertyTypeInfo.GetGenericTypeDefinition();

            if (!KnownPropertyTypeDefinitions.Contains(interfaceType))
            {
                if (!throwException)
                {
                    return(null);
                }

                throw InvalidInterfaceType(nameof(propertyTypeInfo), interfaceType);
            }

            return(new ResolvedPropertyTypeInfo()
            {
                InterfaceType = interfaceType,
                ResolvedType = propertyTypeInfo.GenericTypeArguments.First(),
            });
        }