/// <summary>
        /// Figures the content of the string place holders in.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns>ICollection{StringPlaceHolder}.</returns>
        public static ICollection <StringPlaceHolder> FigureStringPlaceHoldersInContent(string content)
        {
            ICollection <StringPlaceHolder> result = new List <StringPlaceHolder>();

            if (!string.IsNullOrWhiteSpace(content))
            {
                MatchCollection matches = placeHolderStatementRegex.Matches(content);
                if (matches != null && matches.Count > 0)
                {
                    foreach (Match one in matches)
                    {
                        var key = one.Result(holderKeyResult).ObjectToString();

                        if (!string.IsNullOrWhiteSpace(key))
                        {
                            StringPlaceHolder holder = TranslatePlaceHolderSign(key);
                            if (holder != null && !result.Contains(holder))
                            {
                                result.Add(holder);
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
        /// </summary>
        /// <param name="obj">The object to compare with the current object.</param>
        /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            StringPlaceHolder holder = obj as StringPlaceHolder;
            var result = holder != null && holder.PlaceKey == PlaceKey;

            if (result)
            {
                if (holder.AdditionalParameters == null || AdditionalParameters == null)
                {
                    return true;
                }
            }
            else if (holder.AdditionalParameters != null && AdditionalParameters != null && holder.AdditionalParameters.Count == AdditionalParameters.Count)
            {
                for (int i = 0; i < AdditionalParameters.Count; i++)
                {
                    if (holder.AdditionalParameters[i] != AdditionalParameters[i])
                    {
                        result = false;
                        break;
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Translates the place holder sign.
        /// </summary>
        /// <param name="statement">The statement.</param>
        /// <returns>The <see cref="StringPlaceHolder" /> instance if the input statement is valid for translating.</returns>
        public static StringPlaceHolder TranslatePlaceHolderSign(string statement)
        {
            StringPlaceHolder holder = null;

            if (!string.IsNullOrWhiteSpace(statement))
            {
                Match match = placeHolderSyntaxRegex.Match(statement);
                if (match.Success)
                {
                    holder = new StringPlaceHolder {
                        PlaceKey = match.Result(holderKeyResult).ObjectToString()
                    };
                    holder.AdditionalParameters.AddRange(match.Result(additionalParameterResult).ObjectToString().TrimStart('(').TrimEnd(')').Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                }
            }

            return(holder);
        }
        /// <summary>
        /// Standards the replace delegate.
        /// </summary>
        /// <param name="stringPlaceHolder">The string place holder.</param>
        /// <param name="objects">The objects.</param>
        /// <returns>System.String.</returns>
        private static string StandardTranslateValueDelegate(StringPlaceHolder stringPlaceHolder, params object[] objects)
        {
            string result = string.Empty;

            if (stringPlaceHolder != null && !string.IsNullOrWhiteSpace(stringPlaceHolder.PlaceKey) &&
                objects != null && objects.Length > 0)
            {
                foreach (IPlaceHolderMember one in objects)
                {
                    if (one != null && one.SupportedPlaceKeys != null &&
                        one.SupportedPlaceKeys.Contains(stringPlaceHolder.PlaceKey))
                    {
                        result = one.GetPlaceValueByKey(stringPlaceHolder);
                        break;
                    }
                }
            }

            return(result);
        }
 /// <summary>
 /// Replaces the content.
 /// </summary>
 /// <param name="originalContent">Content of the original.</param>
 /// <param name="placeHolder">The place holder.</param>
 /// <param name="translateValueDelegate">The translate value delegate.</param>
 /// <param name="objects">The objects.</param>
 /// <returns>System.String.</returns>
 public static string ReplaceContent(string originalContent, StringPlaceHolder placeHolder, TranslateValueDelegate translateValueDelegate, params object[] objects)
 {
     return((string.IsNullOrWhiteSpace(originalContent) || placeHolder == null) ? originalContent : originalContent.Replace(placeHolder.ToStatement(), translateValueDelegate(placeHolder, objects)));
 }
        /// <summary>
        /// Standards the replace delegate.
        /// </summary>
        /// <param name="stringPlaceHolder">The string place holder.</param>
        /// <param name="objects">The objects.</param>
        /// <returns>System.String.</returns>
        private static string StandardTranslateValueDelegate(StringPlaceHolder stringPlaceHolder, params object[] objects)
        {
            string result = string.Empty;

            if (stringPlaceHolder != null && !string.IsNullOrWhiteSpace(stringPlaceHolder.PlaceKey)
                && objects != null && objects.Length > 0)
            {
                foreach (IPlaceHolderMember one in objects)
                {
                    if (one != null && one.SupportedPlaceKeys != null
                        && one.SupportedPlaceKeys.Contains(stringPlaceHolder.PlaceKey))
                    {
                        result = one.GetPlaceValueByKey(stringPlaceHolder);
                        break;
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Translates the place holder sign.
        /// </summary>
        /// <param name="statement">The statement.</param>
        /// <returns>The <see cref="StringPlaceHolder" /> instance if the input statement is valid for translating.</returns>
        public static StringPlaceHolder TranslatePlaceHolderSign(string statement)
        {
            StringPlaceHolder holder = null;

            if (!string.IsNullOrWhiteSpace(statement))
            {
                Match match = placeHolderSyntaxRegex.Match(statement);
                if (match.Success)
                {
                    holder = new StringPlaceHolder { PlaceKey = match.Result(holderKeyResult).ObjectToString() };
                    holder.AdditionalParameters.AddRange(match.Result(additionalParameterResult).ObjectToString().TrimStart('(').TrimEnd(')').Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                }
            }

            return holder;
        }
 /// <summary>
 /// Replaces the content.
 /// </summary>
 /// <param name="originalContent">Content of the original.</param>
 /// <param name="placeHolder">The place holder.</param>
 /// <param name="translateValueDelegate">The translate value delegate.</param>
 /// <param name="objects">The objects.</param>
 /// <returns>System.String.</returns>
 public static string ReplaceContent(string originalContent, StringPlaceHolder placeHolder, TranslateValueDelegate translateValueDelegate, params object[] objects)
 {
     return (string.IsNullOrWhiteSpace(originalContent) || placeHolder == null) ? originalContent : originalContent.Replace(placeHolder.ToStatement(), translateValueDelegate(placeHolder, objects));
 }