当前位置: 首页>>代码示例>>C#>>正文


C# Block.Flatten方法代码示例

本文整理汇总了C#中System.Web.Razor.Parser.SyntaxTree.Block.Flatten方法的典型用法代码示例。如果您正苦于以下问题:C# Block.Flatten方法的具体用法?C# Block.Flatten怎么用?C# Block.Flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Razor.Parser.SyntaxTree.Block的用法示例。


在下文中一共展示了Block.Flatten方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindModelType

        /// <summary>
        /// Tries to find the model type from the document
        /// So documents using @model will actually be able to reference the model type
        /// </summary>
        /// <param name="block">The document</param>
        /// <param name="passedModelType">The model type from the base class</param>
        /// <returns>The model type, if discovered, or the passedModelType if not</returns>
        private static Type FindModelType(Block block, Type passedModelType)
        {
            var modelBlock =
                block.Flatten().FirstOrDefault(b => b.CodeGenerator.GetType() == typeof(CSharpModelCodeGenerator));

            if (modelBlock == null)
            {
                return passedModelType ?? typeof(object);
            }

            if (string.IsNullOrEmpty(modelBlock.Content))
            {
                return passedModelType ?? typeof(object);
            }

            var discoveredModelType = modelBlock.Content.Trim();

            var modelType = Type.GetType(discoveredModelType);

            if (modelType != null)
            {
                return modelType;
            }

            modelType = AppDomainAssemblyTypeScanner.Types.FirstOrDefault(t => t.FullName == discoveredModelType);

            if (modelType != null)
            {
                return modelType;
            }

            modelType = AppDomainAssemblyTypeScanner.Types.FirstOrDefault(t => t.Name == discoveredModelType);

            if (modelType != null)
            {
                return modelType;
            }

            throw new NotSupportedException(string.Format("Unable to discover CLR Type for model by the name of {0}. Try using a fully qualified type name and ensure that the assembly is added to the configuration file.", discoveredModelType));
        }
开发者ID:half-ogre,项目名称:Nancy,代码行数:47,代码来源:RazorViewEngine.cs

示例2: FindModelType

        /// <summary>
        /// Tries to find the model type from the document
        /// So documents using @model will actually be able to reference the model type
        /// </summary>
        /// <param name="block">The document</param>
        /// <param name="passedModelType">The model type from the base class</param>
        /// <param name="modelCodeGenerator">The model code generator</param>
        /// <returns>The model type, if discovered, or the passedModelType if not</returns>
        private static Type FindModelType(Block block, Type passedModelType, Type modelCodeGenerator)
        {
            var modelBlock =
                block.Flatten().FirstOrDefault(b => b.CodeGenerator.GetType() == modelCodeGenerator);

            if (modelBlock == null)
            {
                return passedModelType ?? typeof(object);
            }

            if (string.IsNullOrEmpty(modelBlock.Content))
            {
                return passedModelType ?? typeof(object);
            }

            var discoveredModelType = modelBlock.Content.Trim();

            var modelType = Type.GetType(discoveredModelType);

            if (modelType != null)
            {
                return modelType;
            }

            modelType = AppDomainAssemblyTypeScanner.Types.FirstOrDefault(t => t.FullName == discoveredModelType);

            if (modelType != null)
            {
                return modelType;
            }

            modelType = AppDomainAssemblyTypeScanner.Types.FirstOrDefault(t => t.Name == discoveredModelType);

            if (modelType != null)
            {
                return modelType;
            }

            throw new NotSupportedException(string.Format(
                                                "Unable to discover CLR Type for model by the name of {0}.\n\nTry using a fully qualified type name and ensure that the assembly is added to the configuration file.\n\nAppDomain Assemblies:\n\t{1}.\n\nCurrent ADATS assemblies:\n\t{2}.\n\nAssemblies in directories\n\t{3}",
                                                discoveredModelType,
                                                AppDomain.CurrentDomain.GetAssemblies().Select(a => a.FullName).Aggregate((n1, n2) => n1 + "\n\t" + n2),
                                                AppDomainAssemblyTypeScanner.Assemblies.Select(a => a.FullName).Aggregate((n1, n2) => n1 + "\n\t" + n2),
                                                GetAssembliesInDirectories().Aggregate((n1, n2) => n1 + "\n\t" + n2)));
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:53,代码来源:RazorViewEngine.cs

示例3: EvaluateParseTree

        public static void EvaluateParseTree(TestContext context, Block actualRoot, Block expectedRoot) {
            // Evaluate the result
            ErrorCollector collector = new ErrorCollector();
            SourceLocationTracker tracker = new SourceLocationTracker();

            // Link all the nodes
            Span first = null;
            Span previous = null;
            foreach (Span span in expectedRoot.Flatten()) {
                if(first == null) {
                    first = span;
                }
                span.Previous = previous;
                if (previous != null) {
                    previous.Next = span;
                }
                previous = span;
            }
            Span.ClearCachedStartPoints(first);

            if (expectedRoot == null) {
                Assert.IsNull(actualRoot, "Expected an empty document.  Actual: {0}", actualRoot);
            }
            else {
                Assert.IsNotNull(actualRoot, "Expected a valid document, but it was empty");
                EvaluateSyntaxTreeNode(collector, tracker, actualRoot, expectedRoot);
                if (collector.Success) {
                    if (context != null) {
                        context.WriteLine("Parse Tree Validation Succeeded:\r\n{0}", collector.Message);
                    }
                }
                else {
                    Assert.Fail("\r\n{0}", collector.Message);
                }
            }
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:36,代码来源:ParserTestBase.cs


注:本文中的System.Web.Razor.Parser.SyntaxTree.Block.Flatten方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。