- StringResources_SourceCode.zip
- docu
- Pub
- Desktop.Release
- de
- Itenso.Community.StringResources.ResStrings.resources.dll
- Itenso.Community.StringResources.SampleLibrary.resources.dll
- Itenso.Community.StringResources.ResStrings.dll
- Itenso.Community.StringResources.SampleLibrary.dll
- Release
- de
- Itenso.Community.StringResources.ResStrings.resources.dll
- Itenso.Community.StringResources.SampleLibrary.resources.dll
- Itenso.Community.StringResources.ResStrings.dll
- Itenso.Community.StringResources.SampleLibrary.dll
- Silverlight.Release
- de
- Itenso.Community.StringResources.ResStrings.resources.dll
- Itenso.Community.StringResources.SampleLibrary.resources.dll
- Itenso.Community.StringResources.ResStrings.dll
- Itenso.Community.StringResources.SampleLibrary.dll
- Web.Release
- de
- Itenso.Community.StringResources.ResStrings.resources.dll
- Itenso.Community.StringResources.SampleLibrary.resources.dll
- Itenso.Community.StringResources.ResStrings.dll
- Itenso.Community.StringResources.SampleLibrary.dll
- WindowsPhone.Release
- de
- Itenso.Community.StringResources.ResStrings.resources.dll
- Itenso.Community.StringResources.SampleLibrary.resources.dll
- Itenso.Community.StringResources.ResStrings.dll
- Itenso.Community.StringResources.SampleLibrary.dll
- ResStrings
- SampleApplication.Web
- SampleApplication.WinForms
- SampleApplication.Xaml
- SampleLibrary
- StringResources.Desktop.sln
- StringResources.Desktop.suo
- StringResources.Silverlight.sln
- StringResources.Silverlight.suo
- StringResources.sln
- StringResources.suo
- StringResources.Web.sln
- StringResources.Web.suo
- StringResources.WindowsPhone.sln
- StringResources.WindowsPhone.suo
- StringResources.WinForms.sln
- StringResources.WinForms.suo
|
// -- FILE ------------------------------------------------------------------
// name : Localization.Web.cs
// project : Itenso String Resources
// created : Jani Giannoudis - 2012.03.21
// language : c#
// environment: .NET 4.0
// copyright : (c) 2004-2012 by Itenso GmbH, Switzerland
// --------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Reflection;
using System.Web.UI;
namespace Itenso.Community.StringResources.ResStrings
{
// ------------------------------------------------------------------------
[Designer( typeof( LocalizationDesigner ) )]
public class Localization : Control
{
// ----------------------------------------------------------------------
public enum LocalizationSetup
{
Init,
Load,
PreRender,
} // enum LocalizationSetup
// ----------------------------------------------------------------------
private class ObjectProperty
{
// --------------------------------------------------------------------
public object Object { get; set; }
// --------------------------------------------------------------------
public PropertyInfo Property { get; set; }
} // ObjectProperty
// ----------------------------------------------------------------------
public Localization()
{
ApplyOn = LocalizationSetup.Load;
} // Localization
// ----------------------------------------------------------------------
[Themeable( false )]
[Description( "Set the target control" )]
public string TargetControl { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
[Description( "Set the target value" )]
public string TargetValue { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
[Description( "Set the localization source type" )]
public string SourceType { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
[Description( "Set the localization source value" )]
public string SourceValue { get; set; }
// ----------------------------------------------------------------------
[Themeable( false )]
[Description( "Set the localization setup phase" )]
[DefaultValue( LocalizationSetup.Load )]
public LocalizationSetup ApplyOn { get; set; }
// ----------------------------------------------------------------------
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
if ( ApplyOn == LocalizationSetup.Init )
{
Localize();
}
} // OnInit
// ----------------------------------------------------------------------
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
if ( ApplyOn == LocalizationSetup.Load )
{
Localize();
}
} // OnLoad
// ----------------------------------------------------------------------
protected override void OnPreRender( EventArgs e )
{
base.OnPreRender( e );
if ( ApplyOn == LocalizationSetup.PreRender )
{
Localize();
}
} // OnPreRender
// ----------------------------------------------------------------------
private void Localize()
{
if ( !DesignMode && !string.IsNullOrEmpty( TargetControl ) && !string.IsNullOrEmpty( TargetValue ) &&
!string.IsNullOrEmpty( SourceType ) && !string.IsNullOrEmpty( SourceValue ) )
{
Control control = Parent.FindControl( TargetControl );
if ( control != null )
{
ObjectProperty objectProperty = FindObjectProperty( control, TargetValue );
if ( objectProperty != null )
{
object localizedValue = StringsExpressionParser.Parse( SourceType, SourceValue );
if ( localizedValue != null && objectProperty.Property.PropertyType.IsAssignableFrom( localizedValue.GetType() ) )
{
objectProperty.Property.SetValue( objectProperty.Object, localizedValue, null );
}
}
}
}
} // Localize
// ----------------------------------------------------------------------
private static ObjectProperty FindObjectProperty( object source, string propertyName )
{
if ( source == null || string.IsNullOrEmpty( propertyName ) )
{
return null;
}
int childIndex = propertyName.IndexOf( '.' );
if ( childIndex > 0 )
{
PropertyInfo childProperty = source.GetType().GetProperty( propertyName.Substring( 0, childIndex ), BindingFlags.Public | BindingFlags.Instance );
if ( childProperty == null )
{
return null;
}
object childObject = childProperty.GetValue( source, null );
return childObject == null ? null : FindObjectProperty( childObject, propertyName.Substring( childIndex + 1 ) );
}
PropertyInfo property = source.GetType().GetProperty( propertyName, BindingFlags.Public | BindingFlags.Instance );
return property == null ? null : new ObjectProperty { Object = source, Property = property };
} // FindObjectProperty
} // class Localization
} // namespace Itenso.Community.StringResources.ResStrings
// -- EOF -------------------------------------------------------------------
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
👨 Senior .NET Software Engineer
🚀 My Open Source Projects
-
Time Period Library 👉
GitHub
-
Payroll Engine 👉
GitHub
Feedback and contributions are welcome.