public static SPField EnsureField(this SPList list, SPFieldType type, string displayName, string internalName, bool isRequired)
        {
            SPField field = null;

            try
            {
                list.ParentWeb.AllowUnsafeUpdates = true;
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    field = list.TryGetField(displayName);
                    if (field == null)
                    {
                        list.Fields.Add(internalName, type, isRequired);
                        list.Update();
                        var datefield = list.TryGetField(internalName);
                        if (datefield.Type == SPFieldType.DateTime)
                        {
                            (datefield as SPFieldDateTime).DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                            datefield.Update();
                            list.Update();
                        }
                        field = list.TryGetField(internalName);
                        field.RenameField(displayName);
                        //field.Update();
                        if (field.Type == SPFieldType.Note)
                        {
                            var notefield  = list.TryGetField(internalName);
                            var f          = (SPFieldMultiLineText)list.TryGetField(internalName);
                            f.RichText     = true;
                            f.RichTextMode = SPRichTextMode.FullHtml;
                            f.Update();
                            f.ParentList.Update();
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            return(field);
        }