private static TypeDefinitionName Translate <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Type type, IOutput output, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder)
        {
            Type parent;

            if (mdDecoder.IsNested(type, out parent))
            {
                TypeDefinitionName parentDef = Translate(parent, output, mdDecoder);

                TypeDefinitionName nested = TypeDefinitionName.FromName(0, mdDecoder.IsStruct(type), parentDef, mdDecoder.Name(type));
                return(nested);
            }

            string moduleName = mdDecoder.DeclaringModuleName(type);

            if (moduleName == null)
            {
                // can't translate this as a type definition
                output.WriteLine("Can't translate type {0} as a type definition", mdDecoder.Name(type));
                throw new NotImplementedException();
            }

            Microsoft.Research.DataStructures.IIndexable <Type> formals;
            string[] args;
            if (mdDecoder.IsGeneric(type, out formals, true))
            {
                args = TranslateTypeFormals(formals, output, mdDecoder);
            }
            else
            {
                args = new string[0];
            }
            return(TypeDefinitionName.FromName(ShortAssemblyName.FromName(mdDecoder.DeclaringModuleName(type)), 0, mdDecoder.IsStruct(type), mdDecoder.Namespace(type), mdDecoder.Name(type), args));
        }
Beispiel #2
0
        protected static void CanonicalTypeDefName(Type type, StringBuilder sb, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> decoder)
        {
            Type parentType;

            if (decoder.IsNested(type, out parentType))
            {
                CanonicalTypeDefName(parentType, sb, decoder);
                sb.Append('/');
            }
            else
            {
                string ns = decoder.Namespace(type);
                if (ns != null && ns != "")
                {
                    sb.AppendFormat("{0}.", ns);
                }
            }
            sb.AppendFormat("{0}", decoder.Name(type));
        }