SenseNet.Portal.Portlets.ContentHandlers.FormItem.ReplaceField C# (CSharp) Метод

ReplaceField() защищенный Метод

protected ReplaceField ( string body, bool isHtml, Content itemContent ) : string
body string
isHtml bool
itemContent Content
Результат string
        protected string ReplaceField(string body, bool isHtml, Content itemContent)
        {
            try
            {
                body = body.Replace("{0}", CreateEmailBody(isHtml));

                int startIdx = body.IndexOf('{');
                while (startIdx >= 0)
                {
                    int cIdx = startIdx;
                    int endIdx = body.IndexOf('}', startIdx);
                    if (startIdx < endIdx)
                    {
                        cIdx = endIdx;

                        string fieldName = body.Substring(startIdx, endIdx - startIdx + 1);
                        fieldName = fieldName.Trim('{', '}');
                        if (itemContent.Fields.ContainsKey(fieldName))
                        {
                            body = body.Remove(startIdx, endIdx - startIdx + 1);
                            var objValue = itemContent.Fields[fieldName].GetData();
                            string fieldValue = string.Empty;
                            if (objValue is List<String>)
                            {
                                fieldValue =((List<string>)objValue)[0];
                            }
                            else
                            {
                                fieldValue = itemContent.Fields[fieldName].GetData().ToString();
                            }
                            body = body.Insert(startIdx, fieldValue);
                            cIdx = startIdx + fieldValue.Length;
                        }
                    }
                    startIdx = body.IndexOf('{', cIdx);
                }
                return body;
            }
            catch (Exception ex) //logged
            {
                Logger.WriteException(ex);
                return body + " " + ex.Message + ex.StackTrace;
            }
        }