public async Task <List <KeyValuePair <TMapperOutputKey, TMapperOutputValue> > > RunTasks <TMapperOutputKey, TMapperOutputValue>() { await Task.WhenAll((IEnumerable <Task>) MapperTasks); // concat all keyvalue pairs var allKeyValuePairsForNode = new List <List <KeyValuePair <TMapperOutputKey, TMapperOutputValue> > >(); foreach (var mapperTask in MapperTasks) { var resultProperty = RuntimeReflectionExtensions.GetRuntimeProperty(mapperTask.GetType(), "Result").GetMethod; var result = (List <KeyValuePair <TMapperOutputKey, TMapperOutputValue> >)resultProperty.Invoke(mapperTask, new object[] { }); allKeyValuePairsForNode.Add(result); } var flatternList = allKeyValuePairsForNode.SelectMany(x => x.ToList()).ToList(); if (_configurator.TypeOfCombiner != null) { var combiner = (IReducer)Activator.CreateInstance((Type)_configurator.TypeOfCombiner); var combineMethod = RuntimeReflectionExtensions.GetRuntimeMethods(_configurator.TypeOfCombiner).Single(m => m.Name == "Combine" && m.IsPublic && m.GetParameters().Any()); var combineTask = (Task <List <KeyValuePair <TMapperOutputKey, TMapperOutputValue> > >)combineMethod.Invoke(combiner, new object[] { combiner.GetHashCode().ToString(), flatternList }); return(combineTask.Result); } return(flatternList); }
public Hybrid(IWebBrowserWrapper browser, object module) { this._Browser = browser; _Browser.ScriptNotify += browser_ScriptNotify; this._Module = module; foreach (var method in RuntimeReflectionExtensions.GetRuntimeMethods(module.GetType())) { if ("webViewSaid" == method.Name) { var args = method.GetParameters(); if (args.Length == 2) { _WebViewSaid = method; break; } } } if (_WebViewSaid == null) { throw new InvalidOperationException("module must have a webViewSaid(string, string) method"); } }
public static IEnumerable <MethodInfo> GetRuntimeMethods(this Type type) { #if UNITY_METRO && !UNITY_EDITOR return(RuntimeReflectionExtensions.GetRuntimeMethods(type)); #else return(type.GetMethods()); #endif }
public void GetRuntimeMethods() { var types = GetTypes(); Assert.Throws <ArgumentNullException>(() => { RuntimeReflectionExtensions.GetRuntimeMethods(null); }); List <String> methods = new List <String>(); foreach (TypeInfo type in types) { if (!type.Namespace.Equals("MethodDefinitions", StringComparison.Ordinal)) { continue; } methods.Clear(); methods.AddRange((IEnumerable <String>)type.GetDeclaredField("DeclaredMethodNames").GetValue(null)); methods.AddRange((IEnumerable <String>)type.GetDeclaredField("InheritedMethodNames").GetValue(null)); if (type.GetDeclaredField("NewMethodNames") != null) { methods.AddRange((IEnumerable <String>)type.GetDeclaredField("NewMethodNames").GetValue(null)); } //inherited from object methods.Add("System.String ToString()"); methods.Add("Boolean Equals(System.Object)"); methods.Add("Int32 GetHashCode()"); methods.Add("System.Type GetType()"); methods.Add("Void Finalize()"); methods.Add("System.Object MemberwiseClone()"); foreach (MethodInfo mi in type.AsType().GetRuntimeMethods()) { if (methods.Remove(mi.ToString())) { continue; } Assert.False(true, String.Format("Type: {0}, Method: {1} is not expected", type, mi)); } foreach (String methodName in methods) { Assert.False(true, String.Format("Method: {0} cannot be found", methodName)); } } }
public void GetRuntimeMethods() { var types = GetTypes(); Assert.Throws <ArgumentNullException>(() => { RuntimeReflectionExtensions.GetRuntimeMethods(null); }); List <string> methods = new List <string>(); foreach (TypeInfo type in types) { if (!type.Namespace.Equals("MethodDefinitions", StringComparison.Ordinal)) { continue; } methods.Clear(); methods.AddRange((IEnumerable <string>)type.GetDeclaredField("DeclaredMethodNames").GetValue(null)); methods.AddRange((IEnumerable <string>)type.GetDeclaredField("InheritedMethodNames").GetValue(null)); if (type.GetDeclaredField("NewMethodNames") != null) { methods.AddRange((IEnumerable <string>)type.GetDeclaredField("NewMethodNames").GetValue(null)); } //inherited from object methods.Add("System.String ToString()"); methods.Add("Boolean Equals(System.Object)"); methods.Add("Int32 GetHashCode()"); methods.Add("System.Type GetType()"); methods.Add("Void Finalize()"); methods.Add("System.Object MemberwiseClone()"); Assert.All(type.AsType().GetRuntimeMethods(), m => Assert.True(methods.Remove(m.ToString()))); Assert.Empty(methods); } }
public NativeObjectHolder(object o, bool isGwt) { this.Obj = o; Methods = new Dictionary <string, MethodInfo>(); var t = Obj.GetType(); // We don't need to traverse our way up the full type hierarchy because all available methods are included in GetRuntimeMethods if (!Names.Any(t.FullName.StartsWith)) { foreach (var method in RuntimeReflectionExtensions.GetRuntimeMethods(t)) { try { if (method.IsPublic && !Names.Any(method.DeclaringType.FullName.StartsWith) && !method.IsAbstract) { var methodNameForJS = method.Name; var parameterInfo = method.GetParameters(); var numParams = parameterInfo.Length; if (isGwt) { for (var i = 0; i < numParams; i++) { methodNameForJS += "_"; } } Methods.Add(methodNameForJS, method); } } catch (Exception e) { Debug.WriteLine(e.ToString()); } } } }
static ObjectHelper() { MemberwiseCloneFnc = RuntimeReflectionExtensions .GetRuntimeMethods(typeof(object)) .First((MethodInfo m) => m.Name == "MemberwiseClone"); }