TemplateContentLoader.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / TemplateContentLoader.cs / 1305600 / TemplateContentLoader.cs

                            using System; 
using System.ComponentModel;
using System.Xaml;

namespace System.Windows 
{
    public class TemplateContentLoader : XamlDeferringLoader 
    { 
        public override object Load(XamlReader xamlReader, IServiceProvider serviceProvider)
        { 
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            } 
            else if (xamlReader == null)
            { 
                throw new ArgumentNullException("xamlReader"); 
            }
 
            IXamlObjectWriterFactory factory = RequireService(serviceProvider);
            return new TemplateContent(xamlReader, factory, serviceProvider);
        }
 
        private static T RequireService(IServiceProvider provider) where T : class
        { 
            T result = provider.GetService(typeof(T)) as T; 
            if (result == null)
            { 
                throw new InvalidOperationException(SR.Get(SRID.DeferringLoaderNoContext,typeof(TemplateContentLoader).Name, typeof(T).Name));
            }
            return result;
        } 

        public override XamlReader Save(object value, IServiceProvider serviceProvider) 
        { 
            throw new NotSupportedException(SR.Get(SRID.DeferringLoaderNoSave, typeof(TemplateContentLoader).Name));
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System; 
using System.ComponentModel;
using System.Xaml;

namespace System.Windows 
{
    public class TemplateContentLoader : XamlDeferringLoader 
    { 
        public override object Load(XamlReader xamlReader, IServiceProvider serviceProvider)
        { 
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            } 
            else if (xamlReader == null)
            { 
                throw new ArgumentNullException("xamlReader"); 
            }
 
            IXamlObjectWriterFactory factory = RequireService(serviceProvider);
            return new TemplateContent(xamlReader, factory, serviceProvider);
        }
 
        private static T RequireService(IServiceProvider provider) where T : class
        { 
            T result = provider.GetService(typeof(T)) as T; 
            if (result == null)
            { 
                throw new InvalidOperationException(SR.Get(SRID.DeferringLoaderNoContext,typeof(TemplateContentLoader).Name, typeof(T).Name));
            }
            return result;
        } 

        public override XamlReader Save(object value, IServiceProvider serviceProvider) 
        { 
            throw new NotSupportedException(SR.Get(SRID.DeferringLoaderNoSave, typeof(TemplateContentLoader).Name));
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

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