XamlBuildProvider.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Xaml.Hosting / System / Xaml / Hosting / XamlBuildProvider.cs / 1305376 / XamlBuildProvider.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.Xaml.Hosting 
{
    using System; 
    using System.Xml; 
    using System.Web;
    using System.Web.Hosting; 
    using System.Web.Compilation;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.IO; 
    using System.Xaml;
    using System.Diagnostics.CodeAnalysis; 
    using System.Runtime; 
    using System.Reflection;
    using System.Text; 

    [BuildProviderAppliesTo(BuildProviderAppliesTo.Web)]
    public class XamlBuildProvider : BuildProvider
    { 
        [Fx.Tag.Throws(typeof(TypeLoadException), "The type resolution of the root element failed.")]
        public override Type GetGeneratedType(CompilerResults results) 
        { 
            try
            { 
                using (Stream xamlStream = base.OpenStream())
                {
                    XmlReader xmlReader = XmlReader.Create(xamlStream);
                    XamlXmlReader xamlReader = new XamlXmlReader(xmlReader); 

                    // Read to the root object 
                    while (xamlReader.Read()) 
                    {
                        if (xamlReader.NodeType == XamlNodeType.StartObject) 
                        {
                            if (xamlReader.Type.IsUnknown)
                            {
                                StringBuilder typeName = new StringBuilder(); 
                                AppendTypeName(xamlReader.Type, typeName);
                                throw FxTrace.Exception.AsError(new TypeLoadException(SR.CouldNotResolveType(typeName))); 
                            } 
                            return xamlReader.Type.UnderlyingType;
                        } 
                    }
                    throw FxTrace.Exception.AsError(new HttpCompileException(SR.UnexpectedEof));
                }
            } 
            catch (XamlParseException ex)
            { 
                throw FxTrace.Exception.AsError(new HttpCompileException(ex.Message, ex)); 
            }
        } 

        public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
        {
            return BuildProviderResultFlags.ShutdownAppDomainOnChange; 
        }
 
        private void AppendTypeName(XamlType xamlType, StringBuilder sb) 
        {
            if (!string.IsNullOrEmpty(xamlType.PreferredXamlNamespace)) 
            {
                sb.Append("{");
                sb.Append(xamlType.PreferredXamlNamespace);
                sb.Append("}"); 
            }
            sb.Append(xamlType.Name); 
            if (xamlType.IsGeneric) 
            {
                sb.Append("("); 
                for (int i = 0; i < xamlType.TypeArguments.Count; i++)
                {
                    AppendTypeName(xamlType.TypeArguments[i], sb);
                    if (i < xamlType.TypeArguments.Count - 1) 
                    {
                        sb.Append(", "); 
                    } 
                }
                sb.Append(")"); 
            }
        }
    }
} 


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK