public override INode Visit(IMethod source, IMethod data) { DomMethod result = CreateInstance(source, data); Visit(source, result, data); foreach (ITypeParameter tp in source.TypeParameters) { if (!typeTable.ContainsKey(tp.Name)) { result.AddTypeParameter(Visit(tp, data)); } } result.MethodModifier = source.MethodModifier; if (source.Parameters != null) { foreach (IParameter parameter in source.Parameters) { result.Add((IParameter)parameter.AcceptVisitor(this, data)); } } return(result); }
public void ResolveExtensionMethods() { // Console.WriteLine (" --- Resolve extension"); // Console.WriteLine ("---Args:"); // foreach (var arg in arguments) // Console.WriteLine (arg); // Console.WriteLine ("---GenArgs:"); // if (genericArguments != null) { // foreach (var arg in genericArguments) // Console.WriteLine (arg); // } else { // Console.WriteLine ("<null>"); // } Debug.Assert(originalMethods.Count == methods.Count); for (int i = 0; i < originalMethods.Count; i++) { if (originalMethods[i] is ExtensionMethod) // Extension methods are already resolved & instantiated. { methods[i] = originalMethods[i]; } else if (!StaticUsage && originalMethods[i].IsExtension && Type != null) { methods[i] = new ExtensionMethod(Type, originalMethods[i], genericArguments, arguments); } else { methods[i] = DomMethod.CreateInstantiatedGenericMethod(originalMethods[i], genericArguments, arguments); } } // Console.WriteLine ("-- end resolve extension."); }
public static DomType CreateDelegate(ICompilationUnit compilationUnit, string name, DomLocation location, IReturnType type, IEnumerable <IParameter> parameters) { DomType result = new DomType(); result.compilationUnit = compilationUnit; result.Name = name; result.classType = MonoDevelop.Projects.Dom.ClassType.Delegate; DomMethod delegateMethod = new DomMethod("Invoke", Modifiers.None, MethodModifier.None, location, DomRegion.Empty, type); delegateMethod.Add(parameters); result.Add(delegateMethod); return(result); }
public virtual INode Visit(IMethod source, T data) { DomMethod result = CreateInstance(source, data); Visit(source, result, data); foreach (ITypeParameter tp in source.TypeParameters) { result.AddTypeParameter(Visit(tp, data)); } result.MethodModifier = source.MethodModifier; foreach (IParameter parameter in source.Parameters) { result.Add((IParameter)parameter.AcceptVisitor(this, data)); } return(result); }
public IMethod Extends(ProjectDom dom, IType type) { if (dom == null || type == null || Parameters.Count == 0 || !IsExtension) { return(null); } string extensionTableKey = this.HelpUrl + "/" + type.FullName; if (Name.StartsWith("ForEachWithIndex")) { Console.WriteLine("table key:" + extensionTableKey); } lock (extensionTable) { if (extensionTable.ContainsKey(extensionTableKey)) { return(extensionTable[extensionTableKey]); } if (type.BaseType != null && type.BaseType.FullName == "System.Array" && Parameters[0].ReturnType.ArrayDimensions > 0) { IReturnType elementType = null; foreach (IReturnType returnType in type.BaseTypes) { if (returnType.FullName == "System.Collections.Generic.IList" && returnType.GenericArguments.Count > 0) { elementType = returnType.GenericArguments[0]; break; } } if (elementType != null) { IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod(this, new IReturnType[] {}, new IReturnType[] { elementType }); instMethod = new ExtensionMethod(type, instMethod, null, null); extensionTable.Add(extensionTableKey, instMethod); return(instMethod); } } foreach (IType baseType in dom.GetInheritanceTree(type)) { IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod(this, new IReturnType[] {}, new IReturnType[] { new DomReturnType(baseType) }); string baseTypeFullName = baseType is InstantiatedType ? ((InstantiatedType)baseType).UninstantiatedType.FullName : baseType.FullName; // compare the generic arguments. if (instMethod.Parameters[0].ReturnType.FullName == baseTypeFullName && Parameters[0].ReturnType.ArrayDimensions == 0 && Parameters[0].ReturnType.PointerNestingLevel == 0) { if (instMethod.Parameters[0].ReturnType.GenericArguments.Count > 0) { InstantiatedType instType = baseType as InstantiatedType; if (instType == null || instType.GenericParameters.Count != instMethod.Parameters[0].ReturnType.GenericArguments.Count) { continue; } bool genericArgumentsAreEqual = true; for (int i = 0; i < instMethod.Parameters[0].ReturnType.GenericArguments.Count; i++) { if (Name.StartsWith("ForEachWithIndex")) { Console.WriteLine(instMethod.Parameters[0].ReturnType.GenericArguments[i].DecoratedFullName + " --- " + instType.GenericParameters[i].DecoratedFullName); } if (instMethod.Parameters[0].ReturnType.GenericArguments[i].DecoratedFullName != instType.GenericParameters[i].DecoratedFullName) { genericArgumentsAreEqual = false; break; } } if (!genericArgumentsAreEqual) { continue; } } //ExtensionMethod result = new ExtensionMethod (baseType, this, null, null); instMethod = new ExtensionMethod(type, instMethod, null, null); extensionTable.Add(extensionTableKey, instMethod); //Console.WriteLine ("ext. method:" + instMethod); return(instMethod); } } // Console.WriteLine ("null"); extensionTable.Add(extensionTableKey, null); return(null); } }
public ExtensionMethod(IType extensionType, IMethod originalMethod, IList <IReturnType> genericArguments, IEnumerable <IReturnType> methodArguments) { if (extensionType == null) { throw new ArgumentNullException("extensionType"); } if (originalMethod == null) { throw new ArgumentNullException("originalMethod"); } this.DeclaringType = extensionType; List <IReturnType> args = new List <IReturnType> (); if (extensionType.FullName.EndsWith("[]")) { foreach (IReturnType returnType in extensionType.BaseTypes) { if (returnType.FullName == "System.Collections.Generic.IList" && returnType.GenericArguments.Count > 0) { args.Add(returnType.GenericArguments[0]); break; } } if (args.Count == 0) { args.Add(new DomReturnType(extensionType)); } } else if (extensionType is InstantiatedType) { InstantiatedType instType = (InstantiatedType)extensionType; DomReturnType uninstantiatedReturnType = new DomReturnType(instType.UninstantiatedType.FullName); foreach (IReturnType genArg in instType.GenericParameters) { uninstantiatedReturnType.AddTypeParameter(genArg); } args.Add(uninstantiatedReturnType); } else { args.Add(new DomReturnType(extensionType)); } if (methodArguments != null) { args.AddRange(methodArguments); } // Console.WriteLine ("Create Extension method from:"); // Console.WriteLine ("ext type:" + args[0]); // Console.WriteLine (originalMethod); this.method = DomMethod.CreateInstantiatedGenericMethod(originalMethod, genericArguments, args); // skip first parameter. for (int i = 1; i < method.Parameters.Count; i++) { Add(method.Parameters[i]); } foreach (ITypeParameter par in method.TypeParameters) { AddTypeParameter(par); } this.ExtensionType = extensionType; this.OriginalMethod = originalMethod; //Console.WriteLine (this); //Console.WriteLine ("oOoOoOoOoOoOoOoOoOoOoOoOoOoO"); }