System.Web.UI.Page.CreateHtmlTextWriterFromType C# (CSharp) Метод

CreateHtmlTextWriterFromType() публичный статический Метод

public static CreateHtmlTextWriterFromType ( TextWriter tw, Type writerType ) : System.Web.UI.HtmlTextWriter
tw System.IO.TextWriter
writerType System.Type
Результат System.Web.UI.HtmlTextWriter
	public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
	{
		Type htmlTextWriterType = typeof (HtmlTextWriter);
		
		if (!htmlTextWriterType.IsAssignableFrom (writerType)) {
			throw new HttpException (String.Format ("Type '{0}' cannot be assigned to HtmlTextWriter", writerType.FullName));
		}

		ConstructorInfo constructor = writerType.GetConstructor (new Type [] { typeof (TextWriter) });
		if (constructor == null) {
			throw new HttpException (String.Format ("Type '{0}' does not have a consturctor that takes a TextWriter as parameter", writerType.FullName));
		}

		return (HtmlTextWriter) Activator.CreateInstance(writerType, tw);
	}

Usage Example

Пример #1
0
        private string GetCssStyleRenderString(Type htmlTextWriterType)
        {
            // Nothing to do if no styles are registered.
            if (_registeredStyleInfo == null)
            {
                return(null);
            }

            // Create an empty cssStringWriter
            StringWriter cssStringWriter = new StringWriter(CultureInfo.CurrentCulture);

            // Create a new HtmlTextWriter, with the same type as the current one
            HtmlTextWriter cssHtmlTextWriter =
                Page.CreateHtmlTextWriterFromType(cssStringWriter, htmlTextWriterType);

            CssTextWriter cssWriter = new CssTextWriter(cssHtmlTextWriter);

            foreach (SelectorStyleInfo si in _registeredStyleInfo)
            {
                HtmlHead.RenderCssRule(cssWriter, si.selector, si.style, si.urlResolver);
            }

            // Return the css style rendered string
            return(cssStringWriter.ToString());
        }
All Usage Examples Of System.Web.UI.Page::CreateHtmlTextWriterFromType
Page