public string GetPageLayout(PageLayoutKind kind, string layoutName)
        {
            PageLayoutDescriptorCollection pageLayoutDescriptors = this.PageLayoutDescriptors.GetByKind(kind);

            foreach (PageLayoutDescriptor pageLayoutDescriptor in pageLayoutDescriptors)
            {
                if (pageLayoutDescriptor.Name == layoutName)
                {
                    return(pageLayoutDescriptor.RelativePath);
                }
            }

            return("");
        }
Exemple #2
0
        public PageLayoutDescriptorCollection GetByKind(PageLayoutKind kind)
        {
            PageLayoutDescriptorCollection pageLayoutDescriptors = new PageLayoutDescriptorCollection();

            foreach (PageLayoutDescriptor pageLayoutDescriptor in this)
            {
                if (pageLayoutDescriptor.Kind == kind)
                {
                    pageLayoutDescriptors.Add(pageLayoutDescriptor);
                }
            }

            return(pageLayoutDescriptors);
        }
        private void Initialize()
        {
            ViewsFeature viewsFeature = new ViewsFeature();

            this.ApplicationPartManager.PopulateFeature(viewsFeature);

            IEnumerable <CompiledViewDescriptor> compiledViewDescriptors = viewsFeature.ViewDescriptors;

            foreach (CompiledViewDescriptor compiledViewDescriptor in compiledViewDescriptors)
            {
                PropertyInfo piName;

                if (compiledViewDescriptor.Type.BaseType.IsGenericType)
                {
                    Type genericTypeDefinition = compiledViewDescriptor.Type.BaseType.GetGenericTypeDefinition();

                    PageLayoutKind pageLayoutKind = PageLayoutKind.None;

                    if (genericTypeDefinition == typeof(BlankLayout <>))
                    {
                        pageLayoutKind = PageLayoutKind.Blank;
                    }
                    else if (genericTypeDefinition == typeof(HeaderAndFooterLayout <>))
                    {
                        pageLayoutKind = PageLayoutKind.HeaderAndFooter;
                    }

                    if (pageLayoutKind != PageLayoutKind.None)
                    {
                        piName = compiledViewDescriptor.Type.GetProperty("Name", BindingFlags.Public | BindingFlags.Static);

                        string name = (string)piName.GetValue(null, null);

                        this.PageLayoutDescriptors.Add(name, pageLayoutKind, compiledViewDescriptor.RelativePath);

                        continue;
                    }
                }
            }
        }
 public PageLayoutDescriptor(string name, PageLayoutKind kind, string relativePath)
 {
     this.Name         = name;
     this.Kind         = kind;
     this.RelativePath = relativePath;
 }
Exemple #5
0
 public void Add(string name, PageLayoutKind kind, string relativePath)
 {
     this.Add(new PageLayoutDescriptor(name, kind, relativePath));
 }