public void Build_With_One_Generic_returns_valid_GenericMethodAccessor(Type genericType)
        {
            var method = _GenericMethodAccessorSimple.Build <Type>(genericType);
            var res    = method.Invoke();

            res.Should().Be(genericType);
        }
示例#2
0
        public void Get_returns_valid_GenericMethodAccessor(Type genericType)
        {
            var method = _GenericMethodAccessor.Build <Type>(genericType);
            var res    = method.Invoke();

            res.Should().Be(genericType);
        }
        public void Build_With_Two_Generics_returns_valid_GenericMethodAccessor(Type genericType, Type genericType2)
        {
            var expected = Tuple.Create(genericType, genericType2);
            var method   = _GenericMethodAccessorDouble.Build <Tuple <Type, Type> >(genericType, genericType2);
            var res      = method.Invoke();

            res.Should().Be(expected);
        }
示例#4
0
        private Func <IGlueFactory, object, IJsCsGlue> GetConverter(Type type, object @object)
        {
            if (type.IsEnum)
            {
                return(BuildEnum);
            }

            var simpleType = type.GetInterfaceGenericType(Types.SimpleCommand);

            if (simpleType != null)
            {
                var builder = _SimpleFactory.Build <IJsCsGlue>(simpleType);
                return((fact, obj) => builder.Invoke(fact, obj));
            }

            if (@object is ISimpleCommand)
            {
                return(BuildSimpleCommand);
            }

            simpleType = type.GetInterfaceGenericType(Types.GenericCommand);
            if (simpleType != null)
            {
                var builder = _CommandFactory.Build <IJsCsGlue>(simpleType);
                return((fact, obj) => builder.Invoke(fact, obj));
            }

            switch (@object)
            {
            case ICommandWithoutParameter _:
                return(BuildCommandWithoutParameter);

            case ICommand _:
                return(BuildCommand);
            }

            simpleType = type.GetInterfaceGenericType(Types.ResultCommand);
            if (simpleType != null)
            {
                var builder = _ResultCommandFactory.Build <IJsCsGlue>(simpleType);
                return((fact, obj) => builder.Invoke(fact, obj));
            }

            var types = type.GetInterfaceGenericTypes(Types.ResultCommandWithTArg);

            if (types != null)
            {
                var builder = _ResultCommandWithTArgFactory.Build <IJsCsGlue>(types.Item1, types.Item2);
                return((fact, obj) => builder.Invoke(fact, obj));
            }

            var stringDictionaryValueType = type.GetDictionaryStringValueType();

            if (stringDictionaryValueType != null)
            {
                var objectDictionaryBuilder = new GlueObjectDictionaryBuilder(this, stringDictionaryValueType);
                return(objectDictionaryBuilder.Convert);
            }

            switch (@object)
            {
            case DynamicObject _:
                return(GlueObjectDynamicBuilder.Convert);

            case IList _:
                return(new GlueCollectionsBuilder(this, type).ConvertList);

            case ICollection _:
                return(new GlueCollectionsBuilder(this, type).ConvertCollection);

            case IEnumerable _:
                return(new GlueCollectionsBuilder(this, type).ConvertEnumerable);
            }

            var objectBuilder = new GlueObjectBuilder(this, _Logger, type);

            return(objectBuilder.Convert);
        }