Ejemplo n.º 1
0
            public ImmutableNode <string> Visit(TopLevelTypeReference topLevelTypeReference)
            {
                if (topLevelTypeReference.Namespace == "System")
                {
                    switch (topLevelTypeReference.Name)
                    {
                    case "Void":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Void]);

                    case "Boolean":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Boolean]);

                    case "Char":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Char]);

                    case "SByte":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.SByte]);

                    case "Byte":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Byte]);

                    case "Int16":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Int16]);

                    case "UInt16":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.UInt16]);

                    case "Int32":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Int32]);

                    case "UInt32":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.UInt32]);

                    case "Int64":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Int64]);

                    case "UInt64":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.UInt64]);

                    case "Single":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Single]);

                    case "Double":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Double]);

                    case "String":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.String]);

                    case "Object":
                        return(PrimitiveTypesByCode[(int)PrimitiveTypeCode.Object]);

                    case "Decimal":
                        return(DecimalPrimitiveType);
                    }
                }
                return(AddNamespace(topLevelTypeReference, BuildNameWithArity(topLevelTypeReference.Name)));
            }
        private static MetadataTypeReference GetTypeFromTypeReferenceHandle(MetadataReader reader, TypeReferenceHandle handle)
        {
            var nestedTypeNames = new List <StringHandle>();

            var type = reader.GetTypeReference(handle);

            while (type.ResolutionScope.Kind == HandleKind.TypeReference)
            {
                nestedTypeNames.Add(type.Name);
                type = reader.GetTypeReference((TypeReferenceHandle)type.ResolutionScope);
            }

            MetadataAssemblyReference assemblyReference;

            switch (type.ResolutionScope.Kind)
            {
            case HandleKind.ModuleReference:
                assemblyReference = null;
                break;

            case HandleKind.AssemblyReference:
                assemblyReference = reader.GetAssemblyReference((AssemblyReferenceHandle)type.ResolutionScope)
                                    .GetAssemblyName(reader);
                break;

            default:
                throw new NotImplementedException();
            }

            MetadataTypeReference current = new TopLevelTypeReference(
                assemblyReference,
                reader.GetString(type.Namespace),
                reader.GetString(type.Name));

            for (var i = nestedTypeNames.Count - 1; i >= 0; i--)
            {
                current = new NestedTypeReference(current, reader.GetString(nestedTypeNames[i]));
            }

            return(current);
        }
Ejemplo n.º 3
0
 private ImmutableNode <string> AddNamespace(TopLevelTypeReference topLevelTypeReference, ImmutableNode <string> name)
 {
     return(currentNamespace == topLevelTypeReference.Namespace || string.IsNullOrEmpty(topLevelTypeReference.Namespace) ? name :
            new ImmutableNode <string>(new ImmutableNode <string>(null, topLevelTypeReference.Namespace, null), ".", name));
 }