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)); }
public static TypeName AttributeName(string name) { return(TypeDefinitionName.FromName( AssemblyName, -1, false, RootNamespace, name + "Attribute").SelfInstantiation); }
private static TypeName TypeName(string name) { SafeDebug.AssumeNotNullOrEmpty(name, "name"); return(TypeDefinitionName.FromName( AssemblyName, -1, false, RootNamespace, name).SelfInstantiation); }
static MethodDefinitionName Translate <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Method method, IOutput output, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder) { Type declaringType = mdDecoder.DeclaringType(method); TypeDefinitionName tdefName = Translate(declaringType, output, mdDecoder); TypeName resultTdefName = TranslateToTypeName(mdDecoder.ReturnType(method), output, mdDecoder); ParameterDefinitionName[] argTdefNames = Translate(mdDecoder.Parameters(method), method, output, mdDecoder); var name = mdDecoder.Name(method); if (name == "Finalize") { name = "~" + mdDecoder.Name(declaringType).Split(new char[] { '`' }, 2)[0]; } return(MethodDefinitionName.FromTypeMethod(0, tdefName, mdDecoder.IsStatic(method), name, null, resultTdefName, argTdefNames)); }
private static TypeName TranslateToTypeName <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Type type, IOutput output, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder) { // case analysis over kind of type we have here. if (mdDecoder.IsArray(type)) { TypeName elementType = TranslateToTypeName(mdDecoder.ElementType(type), output, mdDecoder); return(elementType.SzArrayType); } if (mdDecoder.IsManagedPointer(type)) { TypeName elementType = TranslateToTypeName(mdDecoder.ElementType(type), output, mdDecoder); return(elementType.ManagedPointerType); } if (mdDecoder.IsUnmanagedPointer(type)) { TypeName elementType = TranslateToTypeName(mdDecoder.ElementType(type), output, mdDecoder); return(elementType.PointerType); } if (mdDecoder.IsFormalTypeParameter(type)) { return(TypeName.MakeGenericTypeParameter(mdDecoder.NormalizedFormalTypeParameterIndex(type))); } if (mdDecoder.IsMethodFormalTypeParameter(type)) { return(TypeName.MakeGenericMethodParameter(mdDecoder.MethodFormalTypeParameterIndex(type))); } Microsoft.Research.DataStructures.IIndexable <Type> typeArgs; if (mdDecoder.IsSpecialized(type, out typeArgs)) { TypeDefinitionName genericType = Translate(mdDecoder.Unspecialized(type), output, mdDecoder); TypeName[] typeArgNames = Translate(typeArgs, output, mdDecoder); return(genericType.Instantiate(typeArgNames)); } // TODO: handle optional/required modifiers and generic type instances and type parameters TypeDefinitionName tdef = Translate(type, output, mdDecoder); return(tdef.Instantiate()); }
static TypeName MakeTypeName(string name, string @namespace = null, ShortAssemblyName assembly = null) { SafeDebug.AssumeNotNullOrEmpty(name, "name"); return(TypeDefinitionName.FromName(assembly ?? Assembly_XunitCore, -1, false, @namespace ?? Namespace_Xunit, name).SelfInstantiation); }