static string GetSignatureForDoc(TypeSpec type) { var tp = type as TypeParameterSpec; if (tp != null) { int c = 0; type = type.DeclaringType; while (type != null && type.DeclaringType != null) { type = type.DeclaringType; c += type.MemberDefinition.TypeParametersCount; } var prefix = tp.IsMethodOwned ? "``" : "`"; return(prefix + (c + tp.DeclaredPosition)); } var pp = type as PointerContainer; if (pp != null) { return(GetSignatureForDoc(pp.Element) + "*"); } ArrayContainer ap = type as ArrayContainer; if (ap != null) { return(GetSignatureForDoc(ap.Element) + ArrayContainer.GetPostfixSignature(ap.Rank)); } if (TypeManager.IsGenericType(type)) { string g = type.MemberDefinition.Namespace; if (g != null && g.Length > 0) { g += '.'; } int idx = type.Name.LastIndexOf('`'); g += (idx < 0 ? type.Name : type.Name.Substring(0, idx)) + '{'; int argpos = 0; foreach (TypeSpec t in TypeManager.GetTypeArguments(type)) { g += (argpos++ > 0 ? "," : String.Empty) + GetSignatureForDoc(t); } g += '}'; return(g); } string name = type.GetMetaInfo().FullName != null?type.GetMetaInfo().FullName : type.Name; return(name.Replace("+", ".").Replace('&', '@')); }
// // Returns the MethodBase for "Invoke" from a delegate type, this is used // to extract the signature of a delegate. // public static MethodInfo GetInvokeMethod(CompilerContext ctx, Type container_type, Type delegate_type) { Type dt = delegate_type; Type[] g_args = null; if (TypeManager.IsGenericType(delegate_type)) { g_args = TypeManager.GetTypeArguments(delegate_type); delegate_type = TypeManager.DropGenericTypeArguments(delegate_type); } Delegate d = TypeManager.LookupDelegate(delegate_type); MethodInfo invoke; if (d != null) { #if GMCS_SOURCE if (g_args != null) { invoke = TypeBuilder.GetMethod(dt, d.InvokeBuilder); #if MS_COMPATIBLE ParametersCompiled p = (ParametersCompiled)d.Parameters.InflateTypes(g_args, g_args); TypeManager.RegisterMethod(invoke, p); #endif return(invoke); } #endif return(d.InvokeBuilder); } Expression ml = Expression.MemberLookup(ctx, container_type, null, dt, "Invoke", Location.Null); MethodGroupExpr mg = ml as MethodGroupExpr; if (mg == null) { ctx.Report.Error(-100, Location.Null, "Internal error: could not find Invoke method!"); // FIXME: null will cause a crash later return(null); } invoke = (MethodInfo)mg.Methods[0]; #if MS_COMPATIBLE if (g_args != null) { AParametersCollection p = TypeManager.GetParameterData(invoke); p = p.InflateTypes(g_args, g_args); TypeManager.RegisterMethod(invoke, p); return(invoke); } #endif return(invoke); }
static bool CheckType(Type ret, out Type original_iterator_type, out bool is_enumerable) { original_iterator_type = null; is_enumerable = false; if (ret == TypeManager.ienumerable_type) { original_iterator_type = TypeManager.object_type; is_enumerable = true; return(true); } if (ret == TypeManager.ienumerator_type) { original_iterator_type = TypeManager.object_type; is_enumerable = false; return(true); } if (!TypeManager.IsGenericType(ret)) { return(false); } Type[] args = TypeManager.GetTypeArguments(ret); if (args.Length != 1) { return(false); } Type gt = TypeManager.DropGenericTypeArguments(ret); if (gt == TypeManager.generic_ienumerable_type) { original_iterator_type = args [0]; is_enumerable = true; return(true); } if (gt == TypeManager.generic_ienumerator_type) { original_iterator_type = args [0]; is_enumerable = false; return(true); } return(false); }
public static ConstructorInfo GetConstructor(CompilerContext ctx, Type container_type, Type delegate_type) { Type dt = delegate_type; Type[] g_args = null; if (TypeManager.IsGenericType(delegate_type)) { g_args = TypeManager.GetTypeArguments(delegate_type); delegate_type = TypeManager.DropGenericTypeArguments(delegate_type); } Delegate d = TypeManager.LookupDelegate(delegate_type); if (d != null) { #if GMCS_SOURCE if (g_args != null) { return(TypeBuilder.GetConstructor(dt, d.ConstructorBuilder)); } #endif return(d.ConstructorBuilder); } Expression ml = Expression.MemberLookup(ctx, container_type, null, dt, ConstructorInfo.ConstructorName, MemberTypes.Constructor, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, Location.Null); MethodGroupExpr mg = ml as MethodGroupExpr; if (mg == null) { ctx.Report.Error(-100, Location.Null, "Internal error: could not find delegate constructor!"); // FIXME: null will cause a crash later return(null); } return((ConstructorInfo)mg.Methods[0]); }