protected TestBase()
            {
                _typeCache    = Substitute.For <ITypeCache>();
                _referenceMap = Substitute.For <IReferenceMap>();
                _converter    = new FrameworkToJsiiConverter(_typeCache);

                IServiceCollection serviceCollection = new ServiceCollection();

                serviceCollection.AddSingleton <ITypeCache>(_typeCache);
                serviceCollection.AddSingleton <IReferenceMap>(_referenceMap);
                serviceCollection.AddSingleton <IFrameworkToJsiiConverter>(_converter);
                serviceCollection.AddSingleton <IClient>(Substitute.For <IClient>());
                serviceCollection.AddTransient <IClient>(sp => Substitute.For <IClient>());

                IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

                ServiceContainer.ServiceProviderOverride = serviceProvider;

                _typeCache.GetClassType("myClassFqn").Returns(typeof(TestClass));
                _typeCache.GetEnumType("myEnumFqn").Returns(typeof(TestEnum));
            }
예제 #2
0
        bool TryConvertCustomType(IReferenceMap referenceMap, object value, bool isOptional, string fullyQualifiedName, out object result)
        {
            if (IsReferenceType())
            {
                return(TryConvertClass(referenceMap, value, out result));
            }

            if (_types.GetEnumType(fullyQualifiedName) != null)
            {
                return(TryConvertEnum(value, isOptional, fullyQualifiedName, out result));
            }

            result = null;
            return(false);

            bool IsReferenceType()
            {
                return
                    (_types.GetClassType(fullyQualifiedName) != null ||
                     _types.GetInterfaceType(fullyQualifiedName) != null ||
                     _types.GetProxyType(fullyQualifiedName) != null);
            }
        }