|
Heath Stewart wrote:
Why not just use the BinaryFormatter and save yourself the trouble?
Because we want to allow most of the types to be able to edited by hand in the XML file, but also allow embedded binary serialization of types that can't be serialized to XML directly.
Note that we are *not* re-implementing serialization from scratch - only unifying and extending what's already there. Our system basically orchestrates the identification of what serializer to use, and allows the serialization to be handled the same from the outside regardless of what means is used for serialization. So if it can be serialized through our interface, that is used, if it can be serialized using the XmlSerializer directly, the XmlSerializer is used, if it can be serialized using the TypeConverter, that is used, or if it is marked as serializable, binary serialization is used and it is encoded using Base64 encoding.
The first and foremost reason we re-implemented the IXmlSerializable interface ourselves is that it is unsupported and therefore may change without notice or backwards compatibility.
As I said, it's not anything really special, but it serves a need.
|
|
|
|
|
if (foo == null)
System.Data.Foo _Foo = new System.Data.Foo;
∙ ^ Error ^
if (foo == null) {
System.Data.Foo _Foo = new System.Data.Foo;
}
∙ ^ No Error ^
Becouse?
|
|
|
|
|
You can't define a variable in an inline if statement. The correct way would be:
System.Data.Foo _Foo=null;
if(foo==null)
_Foo = new System.Data.Foo;
System.Data.Foo _Foo=(foo==null ? new System.Data.Foo : null);
|
|
|
|
|
If you use:
if (foo == null)
{
System.Data.Foo _Foo = new System.Data.Foo;
}
Now _Foo is only available within the { and } .
Now, if you could use the short version:
if (foo == null)
System.Data.Foo _Foo = new System.Data.Foo;
...then where would _Foo be available? In the { and } , which you left out, or in the parent's context (e.g. between the methods { and } )?
Because of this confusion, it is not possible.
|
|
|
|
|
If you use:
if (foo == null)
{
System.Data.Foo _Foo = new System.Data.Foo;
}
Now _Foo is only available within the { and } .
Now, if you could use the short version:
if (foo == null)
System.Data.Foo _Foo = new System.Data.Foo;
...then where would _Foo be available? In the { and } , which you left out, or in the parent's context (e.g. between the methods { and } )?
Because of this confusion, it is not possible.
|
|
|
|
|
yes correct
but i see the c# schema ambiguous ;)
|
|
|
|
|
I cant seem to get my text to align in a list box, heres my code, i just cant remember what im doing wrong, im trying to left align the first string, then have both of the following strings in left aligned columns. But depending on the size of the first string, the second and third strings end up offset.
String.Format("{0, -20}", m_sTimerName) + String.Format("{0, 10}", m_iInitialTime.ToString()) + String.Format("{0, 10}", m_bRepeat.ToString());
Thanks,
Ryan
|
|
|
|
|
Ryan@SalamanderTechnologies wrote:
im trying to left align the first string, then have both of the following strings in left aligned columns. But depending on the size of the first string, the second and third strings end up offset.
2. Those last 2 should be -10.
1. if the timername is too long it will screw up.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Whoa! Talk about string concatenation inefficiencies! String concatenation is one slow piece of code. For each concat, the CLR needs to measure the length of each string, then create a string large enough to hold the total length, then copy the characters from each string. This is a 2*O(n+m) operation. Instead, just use String.Format one:
string.Format("{0,-20}{1,-10}{2,-10}",
m_sTimerName, miInitialTime, m_bRepeat); Notice also that you don't need to call ToString on non-string variables. String.Format will do this automatically, or it will use "G" for the format if the object implements IFormattable , or it will call Format if the object implements ICusotmFormatter (see the String.Format documentation for details). Leaving the formatting details to String.Format makes it easier to take into account globalization (i.e., using the regional settings when necessary/available).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the coding suggestion Heath. I did indeed implement it as you have shown, and the second and third columns do not line up. The larger or smaller for that matter the first column is, depends on where the second and third columns end up. I was hoping to have them all aligned, and the values I was testing the first column with did not exceed the length in the format. Any suggestions? I am also using a true type font.
Ryan
|
|
|
|
|
The font doesn't matter with String.Format - it's about the number of characters. The code fragment I gave you also uses your original code plus the suggestion before mine (using the negative operator, which was a correct solution) to yield better coding. As I stated - never concatenate strings so hap-hazardly! The code I gave merely was a solution to your concatenation snaffu.
The problem you're having is two-fold: String.Format - and the format specifiers that the previous guy mentions - align text up to the amount specified. Any more than that and the rest of the string is pushed over to make room for larger strings. If you don't mind this string being cut off, you'll have to trim it before using String.Format .
The second problem does have to do with the font and your word alignment (the first statement I made above about the font was in relation to character alignment). If you're not using a fixed-width font, you won't be able to get the text to line up because the sum of the widths of each character will most likely be different for each line. If you really need to line up your text, consider using a ListView .
If you're doing this for a console app, you'd be a fool to use a nothing but a fixed-width font for your console window (specifying a font in the app - at least for now - won't do anything). Most utilities rely on using a fixed-width font to format their output.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
My class contains an unmanaged system object member (a user profile handle) that is initialized in the static constructor. Conversely, I need to free the object when the class (not object instances) is destroyed, but I've never heard of a static destructor.
Perhaps I could use Environment.HasShutdownStarted in the finalizer, but all instances could have already been gc'd when the AppDomain unloads and the code wouldn't run.
Perhaps I could use the AppDomain.Unload event to run my code.
Any thoughts?
|
|
|
|
|
CBoland wrote:
but I've never heard of a static destructor.
They are allowable by the CLR, but I suggest using a Singleton pattern instead of static if it involves any resources.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Good call. Thanks for the reply.
|
|
|
|
|
I need to split a string in C# into tokens, separated by whitespace characters. What would be the best way for me to do this? I just found out about the Split method in the string class, are there other options available?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
If you know RegEx you can try that, else I would stick to the split method, simply and easy
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Something like this worked for me:
foreach( string sToken in sOriginal.Split( " \t\r\n".ToCharArray() ) )
{
}
|
|
|
|
|
Is anybody aware of anything (API) out there that will generate a PDF file using an XSL:FO file that can be integrated into a C# application?
Here be more info :
I am currently working on an application that pulls data from a MSSQL database and put this into a PDF document. For various reasons I am tied to using a fully C# based open source solution. Although these rules can be "bent" if I find a fast non C#/Closed Source implementation.
I have come across a J# port (http://sourceforge.net/projects/nfop) of Apache FOP (http://xml.apache.org/fop) but unfortunatly I have been unable to locate a C# port (with the exception of http://sourceforge.net/projects/fop-dotnet which isnt even 30% completed). Both FOP and nFOP work fine, but they are too slow (FOP - 6 secs average, nFOP - 20 secs average)
In my search for a decent solution, I have played around with iTextSharp (http://sourceforge.net/projects/itextsharp) which requires me to create the entire document in code and doesnt support templates. I have also found Report.NET (http://sourceforge.net/projects/report/) and iSEDquickpdf(http://www.sedtech.com/isedquickpdf/). Both of which suffer from the same problem as iTextSharp. Creating the entire document within code isnt feasible as any change to the document layout would require a recompile and re-release, whereas with XSLT/FO templates any changes can be done in a matter of seconds. There is one solution I have found at http://www.antennahouse.com/ the problem here is that it is far to costly ($5000+).
Having searched through the forums here, it seems that this question has only been asked once before, and it unfortunatly turned into a flame war, so no answers to be found there.
So back to the original question : Is anybody aware of anything (API) out there that will generate a PDF file using an XSL:FO file that can be integrated into a C# application?
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
http://www.xmlpdf.com/ibex.html[^] works well for me.
be aware that XSL-FO is always going to be slower than other rendering techniques due to the XML overhead.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
In my travels through this problem, I havent come across this one.
So I downloaded their evaluation version, and unfortunatly it doesnt work correctly. The PDF I am using has a fairly complex table layout, and also has various embedded images. This renders fine in nFOP and Apache FOP but XMLPDF doesnt seem to able to render these correctly.
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
I came from a VB background. How do I declare a global variable (collection in c#).
I have a combo box in multiple winform that get populate by a table in the DB,I want to read the table into a collection then populate the form each time it loads instead of read from the DB.
|
|
|
|
|
You can't.
What you can do is declaring a public property on the main form which contains the collection, and then accessing this property from whereever you need the collection. Or you use this property as a parameter when calling the other forms.
But a global variable can't be created (and they are evil, I'm told...;)).
|
|
|
|
|
In .NET (true for any language that targets the CLR) there is no such thing as global variables. Instead, though, you can create a class with static fields or properties (properties are usually recommended because you can validate inputs and use logic in your get or set accessors that access a private field. This has the same result, though, at least per AppDomain (if you need a "global" to span multiple AppDomain s, you should consider a ContextBoundObject ).
public class Globals
{
private static object someProperty;
private Globals()
{
}
public static object SomeProperty
{
get { return someProperty; }
set { someProperty = value; }
}
} If you need the power of a singleton, search the comments of this forum for a recent thread discussing various options. Just use the keyword "singleton", of course.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How can I write to my application configuration file from my application?
Mazy
No sig. available now.
|
|
|
|
|
There is not built-in support for writing app configs, but you can use the System.Xml classes to manipulate the XML DOM. Note that your application will not see these settings until restarted, though. I did post several replies to similar questions in the recent past, so search the comments of this forum, using the AppDomainSetup keyword.
As far as writing to the config, you have to remember one very important thing: leave other settings untouched! Users may have customized how the CLR runs your app or even customized settings for your program (like, in <appSettings> ) that you don't want to overwrite. Nick wrote one article about this: http://www.codeproject.com/csharp/config_settings.asp[^]. There are others, too.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|