Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static PropertyInfo GetRuntimeProperty(this Type type, string name)
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(RuntimeReflectionExtensions.GetRuntimeProperty(type, name));
#else
            return(type.GetProperty(name));
#endif
        }
Exemplo n.º 3
0
        public static PropertyInfo GetRuntimeProperty(Type source, string name)
        {
#if NET35 || NET40
            return(source.GetProperty(name));
#else
            return(RuntimeReflectionExtensions.GetRuntimeProperty(source, name));
#endif
        }
Exemplo n.º 4
0
        public void GetRuntimeProperty()
        {
            var types = GetTypes();

            AssertExtensions.Throws <ArgumentNullException>("type", () =>
            {
                RuntimeReflectionExtensions.GetRuntimeProperty(default(Type), "foo");
            });

            AssertExtensions.Throws <ArgumentNullException>("name", () =>
            {
                typeof(RuntimeReflectionExtensionsTests).GetRuntimeProperty(null);
            });

            Assert.Null(typeof(TestType).GetRuntimeProperty(""));

            List <string> properties = new List <string>();

            foreach (TypeInfo type in types)
            {
                if (!type.Namespace.Equals("PropertyDefinitions", StringComparison.Ordinal))
                {
                    continue;
                }

                properties.Clear();
                properties.AddRange((IEnumerable <string>)type.GetDeclaredField("PublicPropertyNames").GetValue(null));

                foreach (string propertyName in properties)
                {
                    bool exceptionExpected = propertyName.Equals("Item");

                    // Slight duplication of code her to allow use of Assert.Throws
                    if (exceptionExpected == true)
                    {
                        Assert.Throws <AmbiguousMatchException>(() =>
                        {
                            PropertyInfo pi = type.AsType().GetRuntimeProperty(propertyName);
                        });
                    }
                    else
                    {
                        PropertyInfo pi = type.AsType().GetRuntimeProperty(propertyName);
                        Assert.NotNull(pi);
                    }
                }
            }

            Assert.Equal(typeof(TestType).GetProperty("Length"), typeof(TestType).GetRuntimeProperty("Length"));
        }