Manos.Mvc.RazorViewTemplate.CheckDoesModelTypeMatch C# (CSharp) Method

CheckDoesModelTypeMatch() private method

private CheckDoesModelTypeMatch ( Type type, Type modelType ) : void
type System.Type
modelType System.Type
return void
        void CheckDoesModelTypeMatch(Type type, Type modelType)
        {
            if (type.IsGenericType)
            {
                if (type.GetGenericTypeDefinition() == typeof(View<>))
                {
                    if (modelType == null)
                    {
                        throw new InvalidOperationException(string.Format("The strongly typed view {0} expects a model type of {1} but was passed null.", ViewFile, type.GetGenericArguments()[0]));
                    }
                    if (!type.GetGenericArguments()[0].IsAssignableFrom(modelType))
                    {
                        throw new InvalidOperationException(string.Format("The strongly typed view {0} expects a model type of {1} but was passed model of type {2}.", ViewFile, type.GetGenericArguments()[0], modelType));
                    }

                    return;
                }
            }

            if (type == typeof(View))
                return;

            // Recurse
            CheckDoesModelTypeMatch(type.BaseType, modelType);
        }