Calyptus.Mvc.WebFormsViewFactory.GetMasterInstance C# (CSharp) Method

GetMasterInstance() protected static method

protected static GetMasterInstance ( IViewTemplate template, IView parent ) : IView
template IViewTemplate
parent IView
return IView
		protected static IView GetMasterInstance(IViewTemplate template, IView parent)
		{
			Type templateType = template.GetType();

			if (_masterTypeCache == null) _masterTypeCache = new Dictionary<Type, string>();

			string viewPath;
			if (!_masterTypeCache.TryGetValue(templateType, out viewPath))
			{
				lock (_masterTypeCache)
				{
					viewPath = GetMasterType(templateType);
					_masterTypeCache.Add(templateType, viewPath);
				}
			}
			if (viewPath == null)
				return null;

			ViewMaster master;
			ViewPage parentPage = parent as ViewPage;
			if (parentPage != null)
			{
				parentPage.MasterPageFile = viewPath;
				master = parentPage.Master;
			}
			else
			{
				ViewMaster parentMaster = parent as ViewMaster;
				if (parentMaster != null)
				{
					parentMaster.MasterPageFile = viewPath;
					master = parentMaster.Master;
				}
				else
					throw new Exception("Expected ViewMaster or ViewPage");
			}
			master.SetTemplate(template);
			return master;
		}
		#endregion