Exemplo n.º 1
0
        public ChoCustomKeyValuePropertyReplacer(string name, IChoKeyValuePropertyReplacer keyValuePropertyReplacer)
        {
            ChoGuard.ArgumentNotNull(name, "name");
            ChoGuard.ArgumentNotNull(keyValuePropertyReplacer, "CustomKeyValuePropertyReplacer");

            _name = name;
            _keyValuePropertyReplacer = keyValuePropertyReplacer;
        }
Exemplo n.º 2
0
        private static bool ReplaceToken(IChoPropertyReplacer[] propertyReplacers, StringBuilder message,
                                         string propertyName, string format, object context)
        {
            if (!String.IsNullOrEmpty(propertyName))
            {
                if (propertyName == "@this")
                {
                    if (context != null)
                    {
                        message.Append(ChoObject.Format(context, format));
                    }
                    return(true);
                }
                foreach (IChoPropertyReplacer propertyReplacer in propertyReplacers)
                {
                    if (!(propertyReplacer is IChoKeyValuePropertyReplacer))
                    {
                        continue;
                    }

                    IChoKeyValuePropertyReplacer dictionaryPropertyReplacer = propertyReplacer as IChoKeyValuePropertyReplacer;
                    if (dictionaryPropertyReplacer == null || !dictionaryPropertyReplacer.ContainsProperty(propertyName, context))
                    {
                        continue;
                    }
                    //if (propertyName.Contains("@this"))
                    //{
                    //    if (context == null)
                    //        context = message.ToString();

                    //    message.Clear();
                    //}

                    message.Append(dictionaryPropertyReplacer.ReplaceProperty(propertyName, format, context));
                    return(true);
                }
            }

            string propertyValue;
            bool   retValue = ChoApplication.OnPropertyResolve(propertyName, format, context, out propertyValue);

            if (retValue)
            {
                if (propertyValue != null)
                {
                    message.Append(propertyValue);
                }
                return(true);
            }

            //if (!format.IsNullOrWhiteSpace())
            //{
            //    message.Append(ChoObject.Format(propertyName, format));
            //    return true;
            //}
            return(false);
        }
Exemplo n.º 3
0
        private static bool ReplaceToken(IChoPropertyReplacer[] propertyReplacers, StringBuilder message,
                                         string propertyName, string format)
        {
            if (!String.IsNullOrEmpty(propertyName))
            {
                foreach (IChoPropertyReplacer propertyReplacer in propertyReplacers)
                {
                    if (!(propertyReplacer is IChoKeyValuePropertyReplacer))
                    {
                        continue;
                    }

                    IChoKeyValuePropertyReplacer dictionaryPropertyReplacer = propertyReplacer as IChoKeyValuePropertyReplacer;
                    if (dictionaryPropertyReplacer == null || !dictionaryPropertyReplacer.ContainsProperty(propertyName))
                    {
                        continue;
                    }
                    message.Append(dictionaryPropertyReplacer.ReplaceProperty(propertyName, format));
                    return(true);
                }
            }

            string propertyValue;
            bool   retValue = ChoApplication.OnPropertyResolve(propertyName, format, out propertyValue);

            if (retValue)
            {
                if (propertyValue != null)
                {
                    message.Append(propertyValue);
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
 public static string ExpandProperties(object target, string inString, IChoKeyValuePropertyReplacer keyValuePropertyReplacer)
 {
     return(ExpandProperties(target, inString, StartSeperator, EndSeperator, FormatSeperator, new ChoCustomKeyValuePropertyReplacer(keyValuePropertyReplacer)));
 }
Exemplo n.º 5
0
 public static string ExpandProperties(string inString, IChoKeyValuePropertyReplacer keyValuePropertyReplacer)
 {
     return(ExpandProperties(null, inString, keyValuePropertyReplacer));
 }
Exemplo n.º 6
0
 public ChoCustomKeyValuePropertyReplacer(IChoKeyValuePropertyReplacer keyValuePropertyReplacer)
     : this(String.Format("CustomKeyValuePropertyReplacer_{0}", ChoRandom.NextRandom().ToString()), keyValuePropertyReplacer)
 {
 }