ResourceExpressionEditor.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / ResourceExpressionEditor.cs / 1 / ResourceExpressionEditor.cs

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

namespace System.Web.UI.Design { 
    using System; 
    using System.Collections;
    using System.ComponentModel; 
    using System.ComponentModel.Design;
    using System.Web.Compilation;

    ///  
    public class ResourceExpressionEditor : ExpressionEditor {
 
        ///  
        public override object EvaluateExpression(string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider) {
            ResourceExpressionFields fields; 
            if (parseTimeData is ResourceExpressionFields) {
                fields = (ResourceExpressionFields)parseTimeData;
            }
            else { 
                fields = ResourceExpressionBuilder.ParseExpression(expression);
            } 
 
            if (String.IsNullOrEmpty(fields.ResourceKey)) {
                return null; 
            }

            object resource = null;
            DesignTimeResourceProviderFactory resourceProviderFactory = ControlDesigner.GetDesignTimeResourceProviderFactory(serviceProvider); 
            IResourceProvider resProvider;
            if (String.IsNullOrEmpty(fields.ClassKey)) { 
                resProvider = resourceProviderFactory.CreateDesignTimeLocalResourceProvider(serviceProvider); 
            }
            else { 
                resProvider = resourceProviderFactory.CreateDesignTimeGlobalResourceProvider(serviceProvider, fields.ClassKey);
            }
            if (resProvider != null) {
                resource = resProvider.GetObject(fields.ResourceKey, System.Globalization.CultureInfo.InvariantCulture); 
            }
 
            if (resource != null) { 
                Type resourceType = resource.GetType();
                if (!propertyType.IsAssignableFrom(resourceType)) { 
                    TypeConverter converter = TypeDescriptor.GetConverter(propertyType);
                    if ((converter != null) && converter.CanConvertFrom(resourceType)) {
                        return converter.ConvertFrom(resource);
                    } 
                }
            } 
            return resource; 
        }
 
        public override ExpressionEditorSheet GetExpressionEditorSheet(string expression, IServiceProvider serviceProvider) {
            return new ResourceExpressionEditorSheet(expression, serviceProvider);
        }
    } 
}

// 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