public IMethodReference Map(IMethodSymbol methodSymbol) { Contract.Requires(methodSymbol != null); IMethodReference mr = null; if (!methodSymbolCache.TryGetValue(methodSymbol, out mr)) { List <IParameterTypeInformation> ps = methodSymbol.Parameters.Length == 0 ? null : new List <IParameterTypeInformation>(); if (methodSymbol.IsGenericMethod && methodSymbol.ConstructedFrom != methodSymbol) { var gArgs = new List <ITypeReference>(); foreach (var a in methodSymbol.TypeArguments) { gArgs.Add(Map(a)); } mr = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference() { CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis, ContainingType = Map(methodSymbol.ContainingType), GenericArguments = gArgs, GenericMethod = Map(methodSymbol.ConstructedFrom), GenericParameterCount = (ushort)methodSymbol.TypeParameters.Length, InternFactory = this.host.InternFactory, Name = this.nameTable.GetNameFor(methodSymbol.Name), Parameters = ps, Type = Map(methodSymbol.ReturnType), }; } else { var m = new Microsoft.Cci.MutableCodeModel.MethodReference(); // IMPORTANT: Have to add it to the cache before doing anything else because it may // get looked up if it is generic and a parameter's type involves the generic // method parameter. this.methodSymbolCache.Add(methodSymbol, m); m.CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis; m.ContainingType = Map(methodSymbol.ContainingType); m.InternFactory = this.host.InternFactory; m.Name = this.nameTable.GetNameFor(methodSymbol.Name); m.Parameters = ps; m.Type = Map(methodSymbol.ReturnType); mr = m; } foreach (var p in methodSymbol.Parameters) { var p_prime = new ParameterTypeInformation() { ContainingSignature = mr, Index = (ushort)p.Ordinal, Type = Map(p.Type), }; ps.Add(p_prime); } } return(mr); }
internal Microsoft.Cci.IParameterTypeInformation Translate(ParameterSymbol param, bool needDeclaration) { System.Diagnostics.Debug.Assert(ReferenceEquals(param, param.OriginalDefinition) || !param.Equals(param.OriginalDefinition)); if (!ReferenceEquals(param, param.OriginalDefinition)) { return(param); } else if (!needDeclaration) { Symbol container = param.ContainingSymbol; bool containerIsGeneric = false; if (container.Kind == SymbolKind.Method) { if (((MethodSymbol)container).IsGeneric) { containerIsGeneric = true; } else { containerIsGeneric = IsGenericType(container.ContainingType); } } else { containerIsGeneric = IsGenericType(container.ContainingType); } if (containerIsGeneric) { object reference; Microsoft.Cci.IParameterTypeInformation paramRef; if (genericInstanceMap.TryGetValue(param, out reference)) { return((Microsoft.Cci.IParameterTypeInformation)reference); } paramRef = new ParameterTypeInformation(param); genericInstanceMap.Add(param, paramRef); return(paramRef); } } return(param); }
internal Microsoft.Cci.IParameterTypeInformation Translate(ParameterSymbol param, bool needDeclaration) { System.Diagnostics.Debug.Assert(ReferenceEquals(param, param.OriginalDefinition) || !param.Equals(param.OriginalDefinition)); if (!ReferenceEquals(param, param.OriginalDefinition)) { return param; } else if (!needDeclaration) { Symbol container = param.ContainingSymbol; bool containerIsGeneric = false; if (container.Kind == SymbolKind.Method) { if (((MethodSymbol)container).IsGeneric) { containerIsGeneric = true; } else { containerIsGeneric = IsGenericType(container.ContainingType); } } else { containerIsGeneric = IsGenericType(container.ContainingType); } if (containerIsGeneric) { object reference; Microsoft.Cci.IParameterTypeInformation paramRef; if (genericInstanceMap.TryGetValue(param, out reference)) { return (Microsoft.Cci.IParameterTypeInformation)reference; } paramRef = new ParameterTypeInformation(param); genericInstanceMap.Add(param, paramRef); return paramRef; } } return param; }
public IMethodReference Map(R.IMethodSymbol methodSymbol) { Contract.Requires(methodSymbol != null); IMethodReference mr = null; if (!methodSymbolCache.TryGetValue(methodSymbol, out mr)) { List<IParameterTypeInformation> ps = methodSymbol.Parameters.Count == 0 ? null : new List<IParameterTypeInformation>(); if (methodSymbol.IsGenericMethod && methodSymbol.ConstructedFrom != methodSymbol) { var gArgs = new List<ITypeReference>(); foreach (var a in methodSymbol.TypeArguments){ gArgs.Add(Map(a)); } mr = new Microsoft.Cci.MutableCodeModel.GenericMethodInstanceReference() { CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis, ContainingType = Map(methodSymbol.ContainingType), GenericArguments = gArgs, GenericMethod = Map(methodSymbol.ConstructedFrom), GenericParameterCount = (ushort) methodSymbol.TypeParameters.Count, InternFactory = this.host.InternFactory, Name = this.nameTable.GetNameFor(methodSymbol.Name), Parameters = ps, Type = Map(methodSymbol.ReturnType), }; } else { var m = new Microsoft.Cci.MutableCodeModel.MethodReference(); // IMPORTANT: Have to add it to the cache before doing anything else because it may // get looked up if it is generic and a parameter's type involves the generic // method parameter. this.methodSymbolCache.Add(methodSymbol, m); m.CallingConvention = methodSymbol.IsStatic ? CallingConvention.Default : CallingConvention.HasThis; m.ContainingType = Map(methodSymbol.ContainingType); m.InternFactory = this.host.InternFactory; m.Name = this.nameTable.GetNameFor(methodSymbol.Name); m.Parameters = ps; m.Type = Map(methodSymbol.ReturnType); mr = m; } foreach (var p in methodSymbol.Parameters) { var p_prime = new ParameterTypeInformation() { ContainingSignature = mr, Index = (ushort)p.Ordinal, Type = Map(p.Type), }; ps.Add(p_prime); } } return mr; }