internal static ILocalizationValue FromConvention(string value, ILocalizationFormattedValueDefinition definition)
        {
            switch (definition.FormatTypes.Length)
            {
            case 0:
                return(GetInstance(definition, typeof(LocalizationValue)));

            case 1:
                return(GetInstance(definition, typeof(LocalizationValue <>).MakeGenericType(definition.FormatTypes)));

            case 2:
                return(GetInstance(definition, typeof(LocalizationValue <,>).MakeGenericType(definition.FormatTypes)));

            case 3:
                return(GetInstance(definition, typeof(LocalizationValue <, ,>).MakeGenericType(definition.FormatTypes)));

            case 4:
                return(GetInstance(definition, typeof(LocalizationValue <, , ,>).MakeGenericType(definition.FormatTypes)));

            case 5:
                return(GetInstance(definition, typeof(LocalizationValue <, , , ,>).MakeGenericType(definition.FormatTypes)));

            case 6:
                return(GetInstance(definition, typeof(LocalizationValue <, , , , ,>).MakeGenericType(definition.FormatTypes)));

            case 7:
                return(GetInstance(definition, typeof(LocalizationValue <, , , , , ,>).MakeGenericType(definition.FormatTypes)));

            case 8:
                return(GetInstance(definition, typeof(LocalizationValue <, , , , , , ,>).MakeGenericType(definition.FormatTypes)));
            }

            return(null);

            ILocalizationValue GetInstance(ILocalizationFormattedValueDefinition definition, Type type)
            {
                var constructor = type.GetConstructor(new[] { definition.GetType(), typeof(string) });

                var newInstance = constructor.Invoke(new object[] { definition, value });

                return((ILocalizationValue)newInstance);
            }
        }
Exemplo n.º 2
0
 public LocalizationValueBase(string value, ILocalizationFormattedValueDefinition definition)
 {
     Value      = value;
     Definition = definition;
 }
Exemplo n.º 3
0
 public LocalizationInstanceDefinition(PropertyInfo propertyInfo, ILocalizationFormattedValueDefinition definition)
 {
     PropertyInfo = propertyInfo;
     Definition   = definition;
     Type         = propertyInfo.PropertyType;
 }