473,626 Members | 3,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help! Problems with custom TypeConverter and Persistence...

(PS: Cross post from microsoft.pulic .dotnet.framewo rk.aspnet.webco ntrols)

I've been looking lately for a way to keep the Properties panel for Controls
'clean'...

My goal is to keep similar public properties of a custom Control neatly tied
together -- rather than all over the IDE.

One such set of values that will rarely be changed, so should have little
priority in the IDE Properties panel, and therefore a good candidate for
keeping
in an expandableobjec t like way, is maybe Captions that are used
through the control.

So assuming that I made the following class

class MyControl : WebControl {
....

public class cCaptions {
public string _Btn_Submit = "Login";
public string _Btn_NewUser = "Register";
public string Btn_Submit {get{return _Btn_Submit;}se t{_Btn_Submit=v alue;}}
public string Btn_NewUser {get{return
_Btn_NewUser;}s et{_Btn_NewUser =value;}}
}//Subclass:End
....

private cCaptions _Captions = new cCaptions;
....
[TypeConverter(t ypeof(TestConve rter)),
PersistenceMode (PersistenceMod e.Attribute )]
public cCaptions {get {return _Captions;}set {_Captions = value;}
....
}//Control:End
As you can see the public property now requires a custom TypeConverter so
that it can be seen in the IDE -- and deal with persistence as an attribute.

I originally thought/tried using the standard ExpandableObjec t one -- but I
needed a way to persist it in one string -- just like how style="" attribute
is done, with : and ; as sep chars between key and value...
Well.
The TypeConverter I wrote works atleast for converting between object and
string, and now in the IDE's Property panel I get the expandableObjec t look
(+/- tree) as well as a means of reading it as one string which looks like

<MyControl CAPTIONS="Btn_S ubmit:Login;Btn _NewUser:Regist er"></MyControl>
My problem with this is that it all LOOKS right -- but its not acting
right...
Problems/Observations:
a) When I edit the string directly in the Properties panel -- eg change it
to "Btn_Submit:HEL LO;Btn_NewUser: Come on in!" it ---well...doesn't do it.
The moment I hit Save -- it reverts back to to the default values. :-(
b) When I click + to expand the Expandable options, and edit the Btn_Submit
value directly -- it updates the summary string line/title to the new
values -- AND updates the interface's actual label (I have to hit save to
get this to trigger)-- but when I check the Html of the control -- its not
been notified of the changes and still shows default values...
c) If I edit the Html of the Control to another value. Nothing happens.
In other words -- total disconnection between the values of the property --
and what is persisted.

Anybody have an idea?
I attach the TypeConverter that I wrote in case it is the cause -- or if
not, that it may be the starting point for someone else...

using System;
using System.Web.UI.D esign;
using System.Web;
using System.Componen tModel;
using System.Globaliz ation;
using System.Reflecti on;
using System.Collecti ons;

namespace XAct.Web.Contro ls {

public class TestConverter : ExpandableObjec tConverter {
System.Type _Type = typeof(XAct.Web .Controls.Login Panel.cCaptions );

public override bool CanConvertFrom( ITypeDescriptor Context context, Type t)
{
if (t == typeof(string)) {return true;}
return base.CanConvert From(context, t);
}

public override object ConvertFrom(ITy peDescriptorCon text context,
CultureInfo info,object value) {
if (value is string) {
string[] tParts;
tParts = SplitPlus((stri ng) value, ";");
object o = _Type.Assembly. CreateInstance( _Type.ToString( ));
string tKey = string.Empty;
string tValue = string.Empty;
int tPos = 0;
foreach (string tPart in tParts){
if (tPart == string.Empty){c ontinue;}
tPos = tPart.IndexOf(' :');
if (tPos == -1){
tPos = tPart.Length;
tKey = tPart;
tValue = string.Empty;
}else{
tKey = tPart.Substring (0,tPos);
tValue = tPart.Substring (tPos+1);
System.Reflecti on.PropertyInfo oPI =
_Type.GetProper ty(tKey,System. Reflection.Bind ingFlags.SetPro perty |
System.Reflecti on.BindingFlags .Public
|System.Reflect ion.BindingFlag s.IgnoreCase);
if (oPI != null){
oPI.SetValue(o, tValue,null);
}
}
}
return o;
}
return base.ConvertFro m(context, info, value);
}
public override object ConvertTo(IType DescriptorConte xt context, CultureInfo
culture, object value, Type destType) {
object o=null;
try {
o = System.Convert. ChangeType(valu e,_Type);
}catch{}
if ((o !=null) && (destType == typeof(string)) ) {
string tResult = string.Empty;
string tDivChar = string.Empty;
PropertyInfo[] oPIs = _Type.GetProper ties();
foreach(Propert yInfo oPI in oPIs){
string tKey = oPI.Name;
object oVal = oPI.GetValue(o, null);
string tValue = string.Empty;
if (oVal != null){
tValue = oVal.ToString() ;
if (tValue != string.Empty){t Result += tDivChar + tKey + ":" + tValue;}
if (tDivChar == string.Empty){t DivChar = ";";}
}
}
return tResult;
}
return base.ConvertTo( context, culture, value, destType);
}

/// <summary>
/// Split function that only splits if not within brackets or quotes.
/// </summary>
/// <param name="qString"> </param>
/// <param name="qDivChar" ></param>
/// <returns></returns>
public static string[] SplitPlus(strin g qString, string qDivChar) {
if (qDivChar== String.Empty){q DivChar = ",";}
ArrayList tResults = new ArrayList();
string tChar="";
string tWord = "";
bool tEscaped=false;
string tLastChar = "";
System.Collecti ons.Stack tQuotes=new System.Collecti ons.Stack();
for (int i=0;i<qString.L ength;i++) {
tChar = qString[i].ToString();
if (tQuotes.Count == 0) {
//We are outside of quotes, so look for quote beginnings...
if ((tChar == "(") ||
(tChar == "{") ||
(tChar == "[") ||
(tChar == "'") ||
(tChar == "\"")) {
tQuotes.Push(tC har);
tLastChar=tChar ;
}
if ((tChar == qDivChar)) {
tResults.Add(tW ord);
tWord="";
tChar = "";
}
}
else {
//We are within quotes...need to look for close chars:
if (tEscaped ==false) {
if (tChar == "\\") {tEscaped=true; }
else {
tLastChar =(string)tQuote s.Peek();
if ((tChar == "\"") && (tChar == tLastChar)) {
tQuotes.Pop();
}
else if ((tChar == "\'") && (tChar == tLastChar)) {
tQuotes.Pop();
}
else if ((tChar == "]") && (tLastChar == "[")) {
tQuotes.Pop();
}
else if ((tChar == "}") && (tLastChar == "{")) {
tQuotes.Pop();
}
if ((tChar == ")") && (tLastChar == "(")) {
tQuotes.Pop();
}
}
}
else {
tEscaped = false;
}
}
tWord = tWord+tChar;
}
if (tWord!= String.Empty) {tResults.Add(t Word);}
return (string[])tResults.ToArr ay(typeof(strin g));
}
}//Class:End
}
Nov 18 '05 #1
1 1693
Correction to class posted before:

There was a bug in ConvertFrom -- when fixed it solved problem a) mentioned
before.

Secondly, I modified this:
[PersistenceMode (PersistenceMod e.Attribute )]

//[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible )
]

public cCaptions Captions {get {return _Captions;}set{ _Captions = value;}}

and tried every variation I can think of -- the only one that works is when
DesignerSeriali zationVisiblity is set to Content -- which negates the whole
use of the TypeConverter to string format I was going for....

And the wierd thing is that before, when I had just

[PersistenceMode (PersistenceMod e.Attribute )]

it was saved as an attribute -- which is what I wanted. Now...nothing. Can't
get it back . gone. Nada.

If anybody can see what I bolloxed up -- thank you very very much!

Sky





using System;

using System.Web.UI.D esign;

using System.Web;

using System.Componen tModel;

using System.Globaliz ation;

using System.Reflecti on;

using System.Collecti ons;

//http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dndotnet/
html/vsnetpropbrow.a sp

namespace XAct.Web.Contro ls {

public class TestConverter : ExpandableObjec tConverter {

System.Type _Type = typeof(XAct.Web .Controls.Login Panel.cCaptions );

public override bool CanConvertFrom( ITypeDescriptor Context context, Type t)
{

if (t == typeof(string)) {return true;}

return base.CanConvert From(context, t);

}

public override object ConvertFrom(ITy peDescriptorCon text context,
CultureInfo info,object value) {

if (value is string) {

try {

string[] tParts;

tParts = SplitPlus((stri ng) value, ";");

XAct.Web.Contro ls.LoginPanel.c Captions o = new
XAct.Web.Contro ls.LoginPanel.c Captions();//_Type.Assembly. CreateInstance( _Ty
pe.ToString());

string tKey = string.Empty;

string tValue = string.Empty;

int tPos = 0;

foreach (string tPart in tParts){

if (tPart == string.Empty){c ontinue;}

tPos = tPart.IndexOf(' :');

if (tPos == -1){

tPos = tPart.Length;

tKey = tPart;

tValue = string.Empty;

}else{

tKey = tPart.Substring (0,tPos);

tValue = tPart.Substring (tPos+1);

System.Reflecti on.PropertyInfo oPI =
_Type.GetProper ty(tKey,Binding Flags.Instance | BindingFlags.Pu blic |
System.Reflecti on.BindingFlags .IgnoreCase);

if (oPI != null){

oPI.SetValue(o, tValue,null);

}

}

}

o._NewUser_Emai l="MERDE EMAIL";

return o;

}

catch {throw new Exception("MERD E!");}

}

return base.ConvertFro m(context, info, value);

}

public override object ConvertTo(IType DescriptorConte xt context, CultureInfo
culture, object value, Type destType) {

object o=null;

try {

o = System.Convert. ChangeType(valu e,_Type);

}catch{}

if ((o !=null) && (destType == typeof(string)) ) {

try {

string tResult = string.Empty;

string tDivChar = string.Empty;

PropertyInfo[] oPIs = _Type.GetProper ties();
foreach(Propert yInfo oPI in oPIs){

string tKey = oPI.Name;

object oVal = oPI.GetValue(o, null);

string tValue = string.Empty;

if (oVal != null){

tValue = oVal.ToString() ;

if (tValue != string.Empty){t Result += tDivChar + tKey + ":" + tValue;}

if (tDivChar == string.Empty){t DivChar = ";";}

}

}

return tResult;

}

catch {}

}

return base.ConvertTo( context, culture, value, destType);

}

// public override bool
GetStandardValu esSupported(Sys tem.ComponentMo del.ITypeDescri ptorContext
context){

// return false;

// }


/// <summary>

/// Split function that only splits if not within brackets or quotes.

/// </summary>

/// <param name="qString"> </param>

/// <param name="qDivChar" ></param>

/// <returns></returns>

public static string[] SplitPlus(strin g qString, string qDivChar) {

if (qDivChar== String.Empty){q DivChar = ",";}

ArrayList tResults = new ArrayList();

string tChar="";

string tWord = "";

bool tEscaped=false;

string tLastChar = "";

System.Collecti ons.Stack tQuotes=new System.Collecti ons.Stack();

for (int i=0;i<qString.L ength;i++) {

tChar = qString[i].ToString();

if (tQuotes.Count == 0) {

//We are outside of quotes, so look for quote beginnings...

if ((tChar == "(") ||

(tChar == "{") ||

(tChar == "[") ||

(tChar == "'") ||

(tChar == "\"")) {

tQuotes.Push(tC har);

tLastChar=tChar ;

}

if ((tChar == qDivChar)) {

tResults.Add(tW ord);

tWord="";

tChar = "";

}

}

else {

//We are within quotes...need to look for close chars:

if (tEscaped ==false) {

if (tChar == "\\") {tEscaped=true; }

else {

tLastChar =(string)tQuote s.Peek();

if ((tChar == "\"") && (tChar == tLastChar)) {

tQuotes.Pop();

}

else if ((tChar == "\'") && (tChar == tLastChar)) {

tQuotes.Pop();

}

else if ((tChar == "]") && (tLastChar == "[")) {

tQuotes.Pop();

}

else if ((tChar == "}") && (tLastChar == "{")) {

tQuotes.Pop();

}

if ((tChar == ")") && (tLastChar == "(")) {

tQuotes.Pop();

}

}

}

else {

tEscaped = false;

}

}

tWord = tWord+tChar;

}

if (tWord!= String.Empty) {tResults.Add(t Word);}

return (string[])tResults.ToArr ay(typeof(strin g));

}

}//Class:End

}
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6527
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
9
4396
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
4
3345
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
6
4327
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
3347
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
7
5364
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
5
3259
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
10
3350
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
1
6120
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
2873
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
8265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.