I am trying to convert the lot of 'if else' to switch stements
Need pointer for a optimal switch cases, some code structure as below.
Code:
Public void ImageTest(String format, string path)
{
//Other Code
//if-Else part
try
{
if (strImageFormat.Equals("BMP"))
{
if (Convert.ToString(dataRow["IsEmployee"]).ToUpper() == "TRUE")
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".BMP");
}
else
{
ImagePath = string.Format("{0}{1}", fileNamelabel, ".BMP");
}
}
else if (strImageFormat.Equals("GIF"))
{
if (Convert.ToString(dataRow["IsEmployee"]).ToUpper() == "TRUE")
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".GIF");
}
else
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".GIF");
}
}
else if (strImageFormat.Equals("JPEG"))
{
if (Convert.ToString(dataRow["IsEmployee"]).ToUpper() == "TRUE")
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".JPEG");
}
else
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".JPEG");
}
}
else if (strImageFormat.Equals("PDF"))
{
if (Convert.ToString(dataRow["IsEmployee"]).ToUpper() == "TRUE")
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".PDF");
}
else
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".PDF");
}
}
}
catch(Exception ex)
{
}
}
I would rather not use too many switch statements and store the value in a bool then use conditional operator inside a case:
bool _condition = Convert.ToString(dataRow["IsEmployee"]);
switch(strImageFormat)
{
case "JPG":
ImagePath = _condition ? string.Format("{0}{1}", fileNameUpper, ".JPEG") : ImagePath = string.Format("{0}{1}", fileNamelabel, ".JPEG") ;
break;
case "GIF":
ImagePath = _condition ? string.Format("{0}{1}", fileNameUpper, ".GIF") : ImagePath = string.Format("{0}{1}", fileNamelabel, ".GIF") ;
break;
.
.
.
.
.
.
default:
// DO SOMETHING
}
It looks that the code
if (Convert.ToString(dataRow["IsEmployee"]).ToUpper() == "TRUE")
{
ImagePath = string.Format("{0}{1}", fileNameUpper, ".GIF");
}
else
{
// fileNamelabel expected, not fileNameUpper
ImagePath = string.Format("{0}{1}", fileNameUpper, ".GIF");
}
is either redundant or just copy-pasted. Providing that it's copy-pasted:
if (Convert.ToString(dataRow["IsEmployee"]).Equals("TRUE", StringComparison.OrdinalIgnoreCase))
ImagePath = string.Format("{0}.{1}", fileNameUpper, strImageFormat);
else
ImagePath = string.Format("{0}.{1}", fileNamelabel, strImageFormat);
Note dot in the changed format: {0}.{1}.
I'd use a factory pattern for that in C#. That makes your code much more flexible, and since switches of strings are converted to a dictionary in C# anyways, it doesn't matter much in terms of performance.
For details on implementation, I've posted an implementation not so long ago on Naming convention for GoF Factory? .
Just another idea without need of switch statement.
bool isEmployee = Convert.ToString(dataRow["IsEmployee"]).ToUpper() == "TRUE";
ImagePath = string.Format("{0}.{1}", isEmployee ? fileNameUpper : fileNamelabel, strImageFormat);
I think that you shouldn't use a switch case instead of ifs.
you should solve it the right way which means to use polymorphism.
have a look at the design pattern http://www.dofactory.com/net/factory-method-design-pattern
have a look on the following initial skeleton:
public static class TestEliminateSwitch
{
public static string GetImagePath()
{
var formatFactory = new FormatFactory();
var instance = formatFactory.GetFomatClass("PDF");
return instance.GetImagePath("TRUE");
}
}
public class FormatFactory
{
public FormatBase GetFomatClass(string formatName)
{
string className = typeof (FormatBase).FullName.Replace("Base", formatName);
return Assembly.GetExecutingAssembly()
.CreateInstance(className) as FormatBase;
}
}
public abstract class FormatBase
{
public string fileNameUpper = string.Empty;
public string fileNamelabel = string.Empty;
public virtual string GetImagePath(string IsEmployee)
{
return string.Format("{0}{1}", IsEmployee.ToUpper() == "TRUE" ? fileNameUpper : fileNamelabel, GetFileExtention());
}
public abstract string GetFileExtention();
}
class FormatPDF : FormatBase
{
public override string GetFileExtention()
{
return ".PDF";
}
}
class FormatGIF : FormatBase
{
public override string GetFileExtention()
{
return ".GIF";
}
}
Related
At the min I am replacing _content in the source elements of my cshtml razor to inject the theme name my users are selecting in the admin this works.
But It requires me to place a tag helper on every element this happens.
At Present I am doing
[HtmlTargetElement(Attributes = AppendVersionAttributeName)]
public class AppendVersionTagHelper : TagHelper
{
private const string AppendVersionAttributeName = "cella-append-version";
private readonly IConfiguration _config;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.Attributes.RemoveAll(AppendVersionAttributeName);
if (!AppendVersion)
{
if (output.Attributes.ContainsName("href"))
{
var href = output.Attributes["href"].Value.ToString();
output.Attributes.SetAttribute("href", AppendVersionToUrl(href));
}
}
if (!AppendVersion)
{
if (output.Attributes.ContainsName("src"))
{
var src = output.Attributes["src"].Value.ToString();
output.Attributes.SetAttribute("src", AppendVersionToUrl(src));
}
}
if (output.Attributes.ContainsName("href"))
{
var href = output.Attributes["href"].Value.ToString();
output.Attributes.SetAttribute("href", AppendThemeNameToUrl(href));
}
if (output.Attributes.ContainsName("src"))
{
var src = output.Attributes["src"].Value.ToString();
var replace = AppendThemeNameToUrl(src);
output.Attributes.SetAttribute("src", replace);
}
if (output.Attributes.ContainsName("xlink:href"))
{
var src = output.Attributes["xlink:href"].Value.ToString();
var replace = AppDomainNameToImage(src);
output.Attributes.SetAttribute("xlink:href", replace);
}
private string AppDomainNameToImage(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return string.Empty;
}
var theme = Constants.DomainName + #"/" + _config[Constants.ThemFolderNameConfigKey] + #"/" + _config["Theme"];
url = url.Replace("_DomainName", theme);
return url;
}
private string AppendThemeNameToUrl(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return string.Empty;
}
var theme = _config[Constants.ThemFolderNameConfigKey] + #"/"+ _config["Theme"];
url = url.Replace("_content", theme);
return url;
}
private string AppendVersionToUrl(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return string.Empty;
}
var version = _config["Global.AssetVersion"];
return url.Contains("?") ? $"{url}&v={version}" : $"{url}?v={version}";
}
}
The function above called
private string AppendThemeNameToUrl(string url)
{
if (string.IsNullOrWhiteSpace(url))
{
return string.Empty;
}
var theme = _config[Constants.ThemFolderNameConfigKey] + #"/"+ _config["Theme"];
url = url.Replace("_content", theme);
return url;
}
}
Then I call the tag helper like so
<link rel="stylesheet" cella-append-version="false" href="~/_content/vendor/bootstrap/css/bootstrap.min.css">
My only concern is this is making an impact on how fast the razor engine returns from the tag helper to present to the user is there a neater way to inject the theme name dynamically to the front end
I have a settings class like this:
public class Settings
{
string resourcePath;
public string ResourcePath {
get {
return resourcePath + "/";
}
set {
resourcePath = value;
}
}
string texturePath;
public string TexturePath {
get {
string a = resourcePath + "/"; // This is just some debug stuff I did trying to find out wtf is going on
string b = texturePath + "/";
return a + b; // Breakpointing here shows that it is "Content/Textures/"
}
set {
texturePath = value;
}
}
public Settings ()
{
resourcePath = "Content";
texturePath = "Textures";
}
public static Settings CurrentSettings = new Settings();
}
Then I try to get the TexturePath from it, like this:
string path = Settings.CurrentSettings.TexturePath + file;
The string returned by the property is "Content//Content/Textures//"
What am I missing here? Why does it do that? With my knowledge it should return Content/Textures/
Use Path.Combine to work with path.
string path = Path.Combine(Settings.CurrentSettings.TexturePath,file);
and no need to add "/" to your properties.
public string ResourcePath {
get {
return resourcePath;
}
set {
resourcePath = value;
}
}
You might not be balancing the / between the getter and the setter. And you probably are getting some property and then setting another with it - resulting in too many /'s.
You haven't shown the code that produces the results you reported but the following code is highly suspect:
string resourcePath;
public string ResourcePath {
get {
return resourcePath + "/";
}
set {
resourcePath = value;
}
}
It always appends a forward slash on the getter but never removes it in the setter. So the following code:
x.ResourcePath = "abc";
x.ResourcePath = x.ResourcePath + "/def";
x.ResourcePath = x.ResourcePath + "/ghi";
Would set ResourcePath to "abc//def//ghi".
I suspect you are running into something like that.
I am currently trying to declare a public string within a while loop, as I would like to use it (the string) in other methods
The string in question is "s"
private void CheckLog()
{
bool _found;
while (true)
{
_found = false;
Thread.Sleep(5000);
if (!System.IO.File.Exists("Command.bat")) continue;
using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
if (s.Contains("mp4:production/CATCHUP/"))
{
_found = true;
break;
}
}
}
}
}
you can't declare public string inside the method.
Try this:
string s = "";
private void CheckLog()
{
bool _found;
while (true)
{
_found = false;
Thread.Sleep(5000);
if (!System.IO.File.Exists("Command.bat")) continue;
using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
{
//s = "VALUE";
while ((s = sr.ReadLine()) != null)
{
if (s.Contains("mp4:production/CATCHUP/"))
{
_found = true;
break;
}
}
}
}
}
You should create a global variable and assign that instead for example
public class MyClass
{
public string s;
private void CheckLog() { ... }
}
In any method you might use it remember to check if s.IsNullOrEmpty() to avoid getting a NullPointerException (also I'm assuming that the string should contain something).
Better pass the string as by-ref argument to function, or return it from the function. Declaring it as member doesn't seem to be a good idea.
public string CheckLog(){}
within windows live messenger, it is possible to share the song you are currently listening to. what would i need to do to get this working within c# like libarys etc cannot find the correct documentation on google.
You'll need to use the iTunes SDK to interact with iTunes from .NET. So there's your Google search term. :)
Here's a start:
http://blogs.msdn.com/b/noahc/archive/2006/07/06/automating-itunes-with-c-in-net.aspx
http://blogs.msdn.com/b/dancre/archive/2004/05/08/128645.aspx
Here is a script for LinqPad in C# which does as requested. (see LinqPad.com)
Bonus! Artwork view.
It looks like this:
<Query Kind="Program">
<Namespace>iTunesLib</Namespace>
<Namespace>System.Security.Cryptography</Namespace>
</Query>
void Main()
{
var track = new iTunesApp().CurrentTrack;
if (track == null)
"nothing playing".Dump();
else
new Viewer(track,true).Dump();
}
public class Viewer
{
const string PREFIX = "itlps-";
private IITFileOrCDTrack store;
private bool materialize;
public string album { get { return store.Album; } }
public string band { get { return store.Artist; } }
public string song { get { return store.Name; } }
public string desc { get { return store.Description; } }
public int? artCnt { get {
if (store.Artwork == null) return null;
else return store.Artwork.Count; }
}
public IEnumerable<ImageViewer> art { get {
if (materialize)
{
foreach(var artT in store.Artwork)
{
var art = artT as IITArtwork;
string ext = ".tmp";
switch(art.Format)
{
case ITArtworkFormat.ITArtworkFormatBMP:
ext = ".BMP";
break;
case ITArtworkFormat.ITArtworkFormatJPEG:
ext = ".JPG";
break;
case ITArtworkFormat.ITArtworkFormatPNG:
ext = ".PNG";
break;
}
string path = Path.Combine(Path.GetTempPath(),PREFIX+Path.GetRandomFileName()+ext);
art.SaveArtworkToFile(path);
yield return new ImageViewer(path);
}
}
yield break; }
}
public Viewer(IITFileOrCDTrack t,bool materializeArt = false)
{
store = t;
materialize = materializeArt;
}
public Viewer(IITTrack t,bool materializeArt = false)
{
store = t as IITFileOrCDTrack;
materialize = materializeArt;
}
}
public class ImageViewer
{
public string hash { get { return _hash.Value; } }
static private string _path { get; set; }
public object image { get { return _image.Value; } }
static private SHA1Managed sha = new SHA1Managed();
private Lazy<object> _image = new Lazy<object>(() => {return Util.Image(_path);});
private Lazy<string> _hash = new Lazy<string>(() =>
{
string hash = string.Empty;
using (FileStream stream = File.OpenRead(_path))
{
byte [] checksum = sha.ComputeHash(stream);
hash = BitConverter.ToString(checksum).Replace("-", string.Empty);
}
return hash;
});
public ImageViewer(string path)
{
_path = path;
}
}
last i checked this functionality is included out of the box all you need is to have itunes and windows live messenger installed and activate "what im listening to" and it shows this in your messenger status. if you are looking to create a bot that messages this out to a contact that is a different story tho that you will need to write a script for
I need a webpart that has a plaintext field for a title, an image for a thumbnail and a HTML content-editable block, so I thought the best way to do this would be to try and extend the existing Content Editor Web Part. Unfortunately, the CEWP is marked as sealed so I can't subclass it. I've reflected and tried to recreate the functionality in my own custom webpart (see the end of the question for code), but the content of my custom version of the CEWP is not persisted.
Does anyone know how I can:
safely subclass the ContentEditableWebPart, or
include a rich text block (including the RTE Ribbon) in a custom web part, or
host multiple web parts in one "wrapper" web part?
Thanks in advance!
code follows below (stuff that was stopping it compiling that was copied from reflector has been commented out/altered/removed)
using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace Public.Webparts
{
[ToolboxItemAttribute(false)]
[XmlRoot(Namespace="Webparts/ProductItem")]
public class ProductItemWebPart :System.Web.UI.WebControls.WebParts.WebPart
{
// Fields
private string _content;
private bool _contentHasToken;
private string _contentLink;
private string _partContent;
private string _partStorage;
private HtmlGenericControl editableRegion = new HtmlGenericControl();
private HtmlGenericControl emptyPanel = new HtmlGenericControl();
private const string EmptyPanelHtmlV4 = "<A href=\"#\" title=\"{0}\" style=\"padding:8px 0px\" class=\"ms-toolbar ms-selectorlink\" >{0}</A>";
internal const string InputContentClientId = "content";
// Methods
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public ProductItemWebPart()
{
//base.PreRender += new EventHandler(this.OnPreRender);
if (this.Title.Length == 0)
{
this.Title = "Product Item Webpart";
}
if (this.Description.Length == 0)
{
this.Description = "This web part contains a title, content and image for a product item.";
}
}
private string GetContent()
{
if (this._partContent != null)
{
return SPHttpUtility.NoEncode(ReplaceTokens(this._partContent));
}
return "";
}
protected internal string ReplaceTokens(string input)
{
string str = string.Empty;
if (this.WebPartManager != null)
{
return SPWebPartManager.ReplaceTokens(HttpContext.Current, SPContext.Current.Web, this, input);
}
if (input != null)
{
str = input;
}
return str;
}
private string getEmptyPanelHtml()
{
return "<A href=\"#\" title=\"Click to enter content.\" style=\"padding:8px 0px\" class=\"ms-toolbar ms-selectorlink\" >Click to enter content.</A>";
}
//private void HttpAsyncCallback(object state)
//{
// ULS.SendTraceTag(0x38393969, ULSCat.msoulscat_WSS_WebParts, ULSTraceLevel.Medium, "ASYNC: Http Callback: UniqueID={0}", new object[] { this.UniqueID.ToString() });
// if ((HttpStatusCode.OK != base.GetHttpWebResponse(this._contentLink, out this._partContent)) && (this._content == null))
// {
// this._partContent = "<p class=\"UserGeneric\">" + SPHttpUtility.HtmlEncode(WebPartPageResource.GetString("CannotRetrieveContent", new object[] { WebPartPageResource.GetString("ContentLinkLiteral") })) + "</p>";
// }
//}
private bool inEditMode()
{
SPWebPartManager currentWebPartManager = (SPWebPartManager) WebPartManager.GetCurrentWebPartManager(this.Page);
return (((currentWebPartManager != null) && !base.IsStandalone) && currentWebPartManager.GetDisplayMode().AllowPageDesign);
}
//[SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
//public override string LoadResource(string id)
//{
// string str = WebPartPageResource.GetString(id);
// if (str != null)
// {
// return str;
// }
// return id;
//}
[SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (this.ShowContentEditable())
{
SPRibbon current = SPRibbon.GetCurrent(this.Page);
if (current != null)
{
current.MakeTabAvailable("Ribbon.EditingTools.CPEditTab");
current.MakeTabAvailable("Ribbon.Image.Image");
current.MakeTabAvailable("Ribbon.EditingTools.CPInsert");
current.MakeTabAvailable("Ribbon.Link.Link");
current.MakeTabAvailable("Ribbon.Table.Layout");
current.MakeTabAvailable("Ribbon.Table.Design");
//if (!(this.Page is WikiEditPage))
//{
// current.TrimRTEWikiControls();
//}
}
}
}
[SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
protected override void OnLoad(EventArgs e)
{
this.Controls.Add(this.editableRegion);
this.Controls.Add(this.emptyPanel);
this.editableRegion.Visible = false;
this.emptyPanel.Visible = false;
base.OnLoad(e);
string str = this.Page.Request.Form[this.ClientID + "content"];
if ((str != null) && (this._content != str))
{
this._content = str;
try
{
SPWebPartManager currentWebPartManager = (SPWebPartManager) WebPartManager.GetCurrentWebPartManager(this.Page);
Guid storageKey = currentWebPartManager.GetStorageKey(this);
currentWebPartManager.SaveChanges(storageKey);
}
catch (Exception exception)
{
Label child = new Label();
child.Text = exception.Message;
this.Controls.Add(child);
}
}
if (this.ShowContentEditable())
{
string str2;
//if (this.ContentHasToken)
//{
// str2 = ReplaceTokens(this._content);
//}
//else
//{
// str2 = this._content;
//}
str2 = this._content;
this.Page.ClientScript.RegisterHiddenField(this.ClientID + "content", str2);
this.editableRegion.Visible = true;
this.emptyPanel.Visible = true;
this.emptyPanel.TagName = "DIV";
this.emptyPanel.Style.Add(HtmlTextWriterStyle.Cursor, "hand");
this.emptyPanel.Controls.Add(new LiteralControl(this.getEmptyPanelHtml()));
this.emptyPanel.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
base.Attributes["RteRedirect"] = this.editableRegion.ClientID;
ScriptLink.RegisterScriptAfterUI(this.Page, "SP.UI.Rte.js", false);
ScriptLink.RegisterScriptAfterUI(this.Page, "SP.js", false);
ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Runtime.js", false);
this.editableRegion.TagName = "DIV";
this.editableRegion.InnerHtml = str2;
this.editableRegion.Attributes["class"] = "ms-rtestate-write ms-rtestate-field";
this.editableRegion.Attributes["contentEditable"] = "true";
this.editableRegion.Attributes["InputFieldId"] = this.ClientID + "content";
this.editableRegion.Attributes["EmptyPanelId"] = this.emptyPanel.ClientID;
this.editableRegion.Attributes["ContentEditor"] = "True";
this.editableRegion.Attributes["AllowScripts"] = "True";
this.editableRegion.Attributes["AllowWebParts"] = "False";
string script = "RTE.RichTextEditor.transferContentsToInputField('" + SPHttpUtility.EcmaScriptStringLiteralEncode(this.editableRegion.ClientID) + "');";
this.Page.ClientScript.RegisterOnSubmitStatement(base.GetType(), "transfer" + this.editableRegion.ClientID, script);
if (string.IsNullOrEmpty(this._content))
{
this.emptyPanel.Style["display"] = "";
this.editableRegion.Style["display"] = "none";
}
else
{
this.emptyPanel.Style["display"] = "none";
this.editableRegion.Style["display"] = "";
}
}
}
//private void OnPreRender(object sender, EventArgs e)
//{
// Uri fullURLPath = base.GetFullURLPath(this._contentLink);
// if ((fullURLPath != null) && !base.TryToGetFileFromDatabase(fullURLPath, out this._partContent))
// {
// ULS.SendTraceTag(0x38393968, ULSCat.msoulscat_WSS_WebParts, ULSTraceLevel.Medium, "ASYNC: Begin Fetch: UniqueID={0}", new object[] { this.UniqueID.ToString() });
// base.RegisterWorkItemCallback(new WaitCallback(this.HttpAsyncCallback), null);
// }
//}
[SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
//protected override void RenderWebPart(HtmlTextWriter writer)
protected override void Render(HtmlTextWriter writer)
{
//if (this.ShowContentEditable() && base.WebPartManager.IsAllowedToScript(this))
if (this.ShowContentEditable())
{
base.Render(writer);
}
else
{
writer.Write(this.GetContent());
}
}
//[SharePointPermission(SecurityAction.Demand, ObjectModel=true)]
//protected internal override bool RequiresWebPartClientScript()
//{
// return true;
//}
//public bool ShouldSerializeContent()
//{
// if (!base.SerializeAll)
// {
// return (this.WebPartDefault._content != this._content);
// }
// return true;
//}
//public bool ShouldSerializeContentHasToken()
//{
// return ((this.WebPartDefault._contentHasToken != this._contentHasToken) && !base.SerializeAll);
//}
//public bool ShouldSerializeContentLink()
//{
// if (!base.SerializeAll)
// {
// return (this.WebPartDefault._contentLink != this._contentLink);
// }
// return true;
//}
public bool ShouldSerializePartStorage()
{
//if (!base.SerializeAll)
//{
//return (this.WebPartDefault._partStorage != this._partStorage);
//}
return true;
}
internal bool ShowContentEditable()
{
return (((SPContext.Current.Web.UIVersion > 3) && (this._partContent == null)) && this.inEditMode());
}
//[XmlElement("ContentHasToken", IsNullable=false), Browsable(false), WebPartStorage(Storage.Shared)]
//public bool ContentHasToken
//{
// get
// {
// return this._contentHasToken;
// }
// set
// {
// this._contentHasToken = value;
// }
//}
//private string EncodedInvalidContentError
//{
// get
// {
// string str2;
// string str = "<a id=\"" + this.ID + "HelpLink\" href=\"javascript:HelpWindowUrl('" + SPHttpUtility.NoEncode("sts/html/dpvwpabt.htm") + "');\">" + SPHttpUtility.HtmlEncode(WebPartPageResource.GetString("InvalidContentErrorHelpLink")) + "</a>";
// if ((this.Context != null) && Utility.BrowserIsIE(this.Context.Request.Browser))
// {
// str2 = "InvalidContentError";
// }
// else
// {
// str2 = "InvalidContentErrorDL";
// }
// return ("<p><div class=\"UserGeneric\">" + string.Format(CultureInfo.InvariantCulture, SPHttpUtility.HtmlEncodeAllowSimpleTextFormatting(WebPartPageResource.GetString(str2)), new object[] { str }) + "</div></p>");
// }
//}
[Resources("PartStorageLiteral", "Advanced", "PartStorage"), WebPartStorage(Storage.Personal), XmlElement("PartStorage", IsNullable=false)]
public string PartStorage
{
get
{
//return Utility.GetMemberString(this._partStorage);
return this._partStorage ?? String.Empty;
}
set
{
//Utility.SetMemberString(ref this._partStorage, value);
if (value != null && value.Length > 0)
{
this._partStorage = value;
}
else
{
this._partStorage = null;
}
}
}
//internal ContentEditorWebPart WebPartDefault
//{
// get
// {
// return (ContentEditorWebPart) base.WebPartDefault;
// }
//}
}
}
Think this may solve your problem - you were on the right track when you got Reflector out :)
http://zootfroot.blogspot.com/2010/09/develop-custom-editable-visual-web-part.html
You can use ControlAdapter, as described in this article: http://blog.mastykarz.nl/inconvenient-content-editor-web-part/
Why not create a "Visual Web Part" and use a rich text editor (like Telerik or others)? I think trying to reverse engineer the code for CEWP is probably overkill and probably against SharePoint's license.