예제 #1
0
        private static Type?GetGeneratorInterfaceModelType(SetupInfo setupInfo)
        {
            var generatorSetup = setupInfo.Setup.GeneratorSetups?.FirstOrDefault();

            if (generatorSetup != null)
            {
                var interfaceType = generatorSetup.Generator?.Type.GetGenericInterface(typeof(IGenerator <, , , , ,>));
                return(DefaultImplementation.GetDefaultImplementationType(interfaceType?.GenericTypeArguments.ElementAtOrDefault(3)));
            }

            return(null);
        }
        public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            JObject item = JObject.Load(reader);
            var     generatorTypeObject = item[GeneratorPropertyName];

            if (generatorTypeObject != null)
            {
                var generatorType = TypeAssemblyLoader.GetType(generatorTypeObject.Value <string>());
                var interfaceType = generatorType?.GetGenericInterface(typeof(IGenerator <, , , , ,>));
                if (interfaceType != null)
                {
                    var generatorSetupType = typeof(GeneratorSetup);
                    if (interfaceType.GenericTypeArguments.Length >= 3 && typeof(IGeneratorSetup).GetTypeInfo().IsAssignableFrom(interfaceType.GenericTypeArguments[1].GetTypeInfo()))
                    {
                        generatorSetupType = interfaceType.GenericTypeArguments[1];
                    }

                    if (generatorSetupType?.IsAbstract != false)
                    {
                        generatorSetupType = DefaultImplementation.GetDefaultImplementationType(generatorSetupType);
                    }

                    if (generatorSetupType?.IsAbstract != false)
                    {
                        generatorSetupType = objectType;
                    }

                    this.isActive           = true;
                    this.lastGeneratorSetup = (IGeneratorSetup?)item.ToObject(generatorSetupType, serializer);
                    this.isActive           = false;
                    return(this.lastGeneratorSetup);
                }

                throw new JsonReaderException($"Error: The generator type: {generatorType} is invalid or is a type that does not implement {typeof(IGenerator<,,,>)}, {typeof(IGenerator<,,,,>)} or {typeof(IGenerator<,,,,,>)}.");
            }

            if (this.lastGeneratorSetup != null)
            {
                this.isActive = true;
                var newObject = item.ToObject(this.lastGeneratorSetup.GetType(), serializer);
                this.isActive = false;
                return(newObject);
            }

            throw new JsonReaderException("Error: No generator setup was specified and no previous generator setup was found.");
        }
예제 #3
0
        public static Type?GetSetupTypeFromInterface(JToken token, Type genericInterfaceType, int setupTypeIndex)
        {
            var setupType     = TypeAssemblyLoader.GetType(token.Value <string>());
            var interfaceType = setupType?.GetGenericInterface(genericInterfaceType);

            if (interfaceType != null)
            {
                var defaultImplementationType = DefaultImplementation.GetDefaultImplementationType(interfaceType.GenericTypeArguments[setupTypeIndex]);
                if (defaultImplementationType != null)
                {
                    return(defaultImplementationType);
                }

                throw new JsonReaderException($"Error: No instantiable setup type was found for {setupType}.");
            }

            return(null);
        }
예제 #4
0
        private static Type?GetModelProviderInterfaceModelType(Type?modelProviderType)
        {
            var modelProviderInterfaceType = modelProviderType?.GetGenericInterface(ModelProviderInterfaceType);

            return(DefaultImplementation.GetDefaultImplementationType(modelProviderInterfaceType?.GenericTypeArguments[2]));
        }