Example #1
0
        public void RegisterNamedType(INamedType type, string targetPath = null)
        {
            string        metadataName  = type.ConstructedFromType.FullName;
            ExtractedType extractedType = CreateExtractedType(type, targetPath);

            _extractedTypes.Add(metadataName, extractedType);
        }
Example #2
0
        public TypeDescriptor LookupType(IType type)
        {
            if (type is INamedType namedType)
            {
                // "User defined" types
                string metadataName = namedType.ConstructedFromType.FullName;
                if (_extractedTypes.ContainsKey(metadataName))
                {
                    ExtractedType extractedType = _extractedTypes[metadataName];
                    if (extractedType is ExtractedEnumType enumType)
                    {
                        return(new ExtractedEnumTypeDescriptor(namedType, enumType.UseExtendedSyntax, extractedType.TargetPath));
                    }
                    else
                    {
                        return(new NamedReferenceTypeDescriptor(namedType, this, extractedType.TargetPath));
                    }
                }

                // Anonymous type
                else if (namedType.Flags.IsAnonymousType)
                {
                    return(new AnonymousTypeDescriptor(namedType, this));
                }

                // Non extracted type
                else if (namedType.Flags.IsEnum)
                {
                    return(new NonExtractedEnumTypeDescriptor(namedType));
                }

                // Nullable types
                else if (namedType.Flags.IsNullable)
                {
                    return(new NullableTypeDescriptor(namedType, this));
                }

                // List types
                else if (namedType.Flags.IsList)
                {
                    return(new ListTypeDescriptor(namedType, this));
                }

                // Dictionary type
                else if (namedType.Flags.IsDictionary)
                {
                    return(new DictionaryTypeDescriptor(namedType, this));
                }

                // System types- TODO: cache these - flyweight
                else if (s_stringTypes.Contains(metadataName))
                {
                    if (_stringType == null)
                    {
                        _stringType = new StringTypeDescriptor(namedType);
                    }
                    return(_stringType);
                }
                else if (s_numericTypes.Contains(metadataName))
                {
                    if (_numericType == null)
                    {
                        _numericType = new NumericTypeDescriptor(namedType);
                    }
                    return(_numericType);
                }
                else if (s_booleanTypes.Contains(metadataName))
                {
                    if (_booleanType == null)
                    {
                        _booleanType = new BooleanTypeDescriptor(namedType);
                    }
                    return(_booleanType);
                }
                else if (s_datetimeTypes.Contains(metadataName))
                {
                    if (_dateTimeType == null)
                    {
                        _dateTimeType = new DateTimeTypeDescriptor(namedType);
                    }
                    return(_dateTimeType);
                }
            }
            else if (type is ITypeParameter)
            {
                return(new TypeParameterDescriptor(type));
            }
            else if (type is IArrayType array)
            {
                return(new ArrayTypeDescriptor(array, this));
            }

            return(new UnknownTypeDescriptor());
        }