|
In a c# program, I have some code wrapped in a pre-processor directive:code:
|
# ? Mar 24, 2008 21:09 |
|
|
# ? Jun 10, 2024 16:03 |
|
I don't think it can be done in Visual Studio, but really, why would you want preprocessor commands indented in line with "real" code anyway? #if / #endif blocks are supposed to be extremely visible, that's why the non-compiled code is grayed out.
|
# ? Mar 24, 2008 21:51 |
|
notflipmo posted:C# + .NET 3.5 Two other options to work with XML if you're not hell-bent on doing it really manually: * XmlSerializer. Very easy to do. You just put some attributes on a class, give the command to deserialize, and the file gets read and put into an object where you can do whatever. * Linq to XML. Never used it, but it should work.
|
# ? Mar 24, 2008 23:11 |
|
notflipmo posted:Learn me some XML please uXs posted:XmlSerializer. Very easy to do. You just put some attributes on a class, give the command to deserialize, and the file gets read and put into an object where you can do whatever. Because I'm such a fan of Xml serialization in .Net, I'll touch on what uXs mentioned regarding the XmlSerializer. Basically you'd have a class model with properties decorated to indicate how they go to and from an Xml document. All of the basic value types (strings, ints, etc) are serializable, anything like a class or collection needs a bit more decoration but it's not difficult really. You have to have the default constructor available, along with gets/sets for each serializable property, and for collections as far as I know they have to be in a sub-element. So code:
code:
code:
|
# ? Mar 25, 2008 01:07 |
|
ray2k posted:Having said all that, getting to and from xml and the object instances is making a couple calls to XmlSerializer.Deserialize/Serialize and writing/reading from a Stream of your creation.
|
# ? Mar 25, 2008 01:24 |
|
ray2k posted:Because I'm a golden god...
|
# ? Mar 25, 2008 01:58 |
|
ray2k posted:and for collections as far as I know they have to be in a sub-element. So Not true at all. You can have identical tags within a parent tag contribute to a collection property on the parent tag's corresponding class by decorating the collection property with one or more [XmlElement] attributes, and no [XmlArray] or [XmlArrayItem] attributes. In other words, replace your Processes property definition from your example with this instead: code:
(Also note that for collections in an XML serializable class, you don't need to expose a public setter -- in fact it's bad form to. Initialize the collection field to an empty collection in your constructor, and the deserialization process will automatically add to the collection as expected, by calling Add() on the value returned by the getter.) biznatchio fucked around with this message at 04:01 on Mar 25, 2008 |
# ? Mar 25, 2008 03:56 |
|
biznatchio posted:I had a feeling that there was a way to get repeated elements into a collection without nesting into a sub-element (hence the 'as far as I know'), but thanks for showing how, regardless. And the setter on the collection thing is just a force of habit. Good catch, though.
|
# ? Mar 25, 2008 04:14 |
|
Is there any way to get a vertical scrollbar to always show up on a SplitPanel control, whether or not the scrollbar is necessary? Or any control, for that matter?
|
# ? Mar 25, 2008 11:54 |
|
biznatchio posted:In other words, replace your Processes property definition from your example with this instead: Am I entirely mistaken if I assume the above contains a typing error and should be like so: code:
|
# ? Mar 25, 2008 22:29 |
|
notflipmo posted:Am I entirely mistaken if I assume the above contains a typing error and should be like so: Undoubtedly. The post textbox doesn't do compile checks.
|
# ? Mar 26, 2008 00:39 |
|
biznatchio posted:Undoubtedly. The post textbox doesn't do compile checks. Anyway, the serializing used above has improved the code for this project immensely. readConfiguration() and writeConfiguration() have both been transformed to petite, understandable methods and to boot: I now have a Config class (that I really should have had anyway), that I can pass around and reference in a very readable way. That class, in turn, can be scaled and changed to include new configuration options as the project grows. All in all I'm entirely satisfied with what I learned today. notflipmo fucked around with this message at 00:51 on Mar 26, 2008 |
# ? Mar 26, 2008 00:47 |
|
A bit late for this party, but what you probably wanted to use are custom configuration sections rather than any funky XML Serialization. Not to say XML Serialization is not fun, easy nor cool. But for config, use the config stuff.
|
# ? Mar 26, 2008 01:58 |
|
wwb posted:A bit late for this party, but what you probably wanted to use are custom configuration sections rather than any funky XML Serialization. Not to say XML Serialization is not fun, easy nor cool. But for config, use the config stuff. Oh god, you went there.. Seriously, creating custom configuration sections with any marginally complicated schema can be such a complete pain in the rear end. I've done it and I'm not against using them, but it's not exactly a beginner topic. Although I will say that I discovered this that I've played with a bit and it does help when you're going the custom configuration route.
|
# ? Mar 26, 2008 02:11 |
|
Honestly, I have not ran into too many issues creating complex configuration files. And I smokes the configuration crack hard. Furthermore, you can just use the same API to write the configuration values, so you don't even need to hand-write XML. Might not be the perfect tool for every job--such as when you have some legacy configuration that you want to pull in--but it should probably be the first pass. PS: I should note that I am talking about the improved configuration options in 2.0, not the craptastic stuff in 1.1.
|
# ? Mar 26, 2008 02:39 |
|
I'm having some trouble getting the XmlSerializer to do the above situation:code:
Am I doing something wrong that I'm not realizing? Edit: hahaha, of course after I post I realize my problem, I put XmlElement instead of XmlAttribute gibbed fucked around with this message at 07:15 on Mar 26, 2008 |
# ? Mar 26, 2008 07:12 |
|
I've been screwing around with LinqToSql, but I can't seem to get it to behave as I want it to. I have the following classes: code:
The Trigger will be retrieved and sent through web service calls. I want both Trigger and Action to have a Schedule, but they shouldn't have exclusive ownership over it. The user can specify a bunch of schedules, and have multiple triggers or actions adhere to the same schedule. I tried adding an one-to-one association between schedule and trigger, and between schedule and action, but a schedule seems to be tied to one trigger or action, and can't be shared between them. (Note: I don't mind if multiple copies of the same schedule are created, i.e. two actions with the same schedule don't have to references to the same instance of the schedule). If I remove an action from a trigger, I want it to be deleted from the database. I have a one-to-many association between actions and triggers, and when I add an action it gets inserted, but if I remove an action it only gets removed from the trigger's action collection, not from the database, so the next time I retrieve the trigger, it still has the old actions. Is there anyway to automate this, or do I have to write my own code to do so? dwazegek fucked around with this message at 10:37 on Mar 26, 2008 |
# ? Mar 26, 2008 10:33 |
|
Arighty, so an update on my caching post AND a question! So I ended up modifying it so that we were actually using the ASP.NET caching instead of storing everything in a static dictionary. I also modified it so that all of the objects that were getting database selected on are now stored as Lists of that object in the database. So now, I need to gain the same functionality in the list as I had with the database select (which is mostly there with the C# string library) except for one issue. When I do a "StartsWith" on letters, it's fine. When I try to do letters and maybe a number, it shits out and can't find a match. Is there any reason the string searches in C# can't match on numbers?
|
# ? Mar 26, 2008 18:45 |
|
FinkieMcGee posted:Is there any reason the string searches in C# can't match on numbers? No, because that's silly...show us this code and some example content, both working and not working. Something else must be wrong. edit: You're not doing something like this, are you? code:
code:
code:
csammis fucked around with this message at 19:39 on Mar 26, 2008 |
# ? Mar 26, 2008 19:35 |
|
I mean, it's pretty simple, the filter variable is read from a search box:code:
|
# ? Mar 26, 2008 19:41 |
|
FinkieMcGee posted:I mean, it's pretty simple, the filter variable is read from a search box: The OrdinalIgnoreCase might be messing you up. It uses Unicode code point values, not ASCII, which may be leading to unexpected results. Try Invariant/CurrentCultureIgnoreCase.
|
# ? Mar 26, 2008 19:44 |
|
Ugh, I am stupid. I was searching for a something that didnt exist actually. Need more coffee.
|
# ? Mar 26, 2008 20:12 |
|
LINQ CHALLENGE I have 2 tables. One called Classes, and another called Attendance. Classes -------- ClassID ClassName Attendance ----------- AttendanceID ClassID FullName If I wanted to get all the classes that have no attendees what would be the best way of doing this in a LINQ query? All I can think of is some crazy foreach loop iterating over all the classes and running a query to check if it has any attendees. Surely there must be a better way of doing this. Nevermind, figured the best way out: Assume dc is my data context. code:
whiskas fucked around with this message at 21:04 on Mar 26, 2008 |
# ? Mar 26, 2008 20:35 |
|
Follwup question, hopefully not as stupid: Is there anyway to easily ignore case using the Contains method like you can with startswith and endswith? Edit: Other than not using ToUpper() on or both strings.
|
# ? Mar 26, 2008 21:24 |
|
Quick question in visual studio. We do alot of code reviews in my company and its a good thing too. We have a very fast pace environment with high turn around. We usually get a request from a client and have it out the door in 3 weeks. I am not talking simple stuff either. Anyways, after a deploy to production (to meet client deadline) we then have a code review. We try to do it before, by time hardly ever allows it. After we make suggestions, we do another deploy in the next few days after the changes are done and it passes QA again. The biggest thing by far that we find is people, including myself sometimes, forget to close datareaders or dispose certain objects, etc. Is there a way to customize VS to throw a warning if they aren't closed? Is there a custom snippet I can write in that would make it do this? A third party app? I have googled all over but I must not be using the right words. Anyone know of something like this?
|
# ? Mar 26, 2008 21:28 |
|
Fastbreak posted:The biggest thing by far that we find is people, including myself sometimes, forget to close datareaders or dispose certain objects, etc. Is there a way to customize VS to throw a warning if they aren't closed? Is there a custom snippet I can write in that would make it do this? A third party app? I have googled all over but I must not be using the right words. Anyone know of something like this? Why don't you just use Using statements to avoide the whole mess of closing/disposing? The only way I've found to realize that stuff is when stuff on the db end goes to hell.
|
# ? Mar 26, 2008 21:31 |
|
FinkieMcGee posted:Follwup question, hopefully not as stupid: Not generally, because Contains is implemented on collections of all types and not just collections of strings. Options in this case: This wouldn't on sealed primitive types like strings, but for your own classes you could implement IComparable<T> and ignore case in your CompareTo implementation. If your collection supports a Contains or Find method that takes a Predicate<T>, you can write a predicate that ignores case in its comparison.
|
# ? Mar 26, 2008 21:58 |
|
Ah I see, that is unfortunate. I may implement it that way over time, but at the moment that's a bit too much hassle. I'll probably just ToLower() both strings and compare them that way. Thanks a lot for your help.
|
# ? Mar 26, 2008 22:03 |
|
csammis posted:Not generally, because Contains is implemented on collections of all types and not just collections of strings. Anyway, just call ToLowerInvariant (or ToUpperInvariant) on both the container and the containee. edit: I'm an idiot, Contains is part of IEnumerable<T> edit2: Well, string gets Contains(char) from IEnumerable<char>, but Contains(string) isn't part of any of string's interfaces. edit3: My inability to comprehend MSDN continues, Contains(char) isn't even part of IEnumerable, it's an extension method from System.Linq. dwazegek fucked around with this message at 22:14 on Mar 26, 2008 |
# ? Mar 26, 2008 22:06 |
|
FinkieMcGee posted:Why don't you just use Using statements to avoide the whole mess of closing/disposing? The only way I've found to realize that stuff is when stuff on the db end goes to hell. Some stuff doesn't implement idisposable. We also have a company internal framework with a custom class that I would like certain functions required to be called and throw an error if they are not. Not possible?
|
# ? Mar 26, 2008 22:13 |
|
Fastbreak posted:Some stuff doesn't implement idisposable. We also have a company internal framework with a custom class that I would like certain functions required to be called and throw an error if they are not. As far as I know you can't generate warning when a method isn't called. One options might be to write a wrapper class around the classes that don't implement IDisposable and implement it yourself.
|
# ? Mar 26, 2008 22:19 |
|
Fastbreak posted:Some stuff doesn't implement idisposable. We also have a company internal framework with a custom class that I would like certain functions required to be called and throw an error if they are not. You could write a Visual Studio Addin that scans for those common scenarios and prevents a compile from passing if they are found. But it would be far more effort than, you know, remembering to actually dispose of things correctly the first time.
|
# ? Mar 27, 2008 00:43 |
|
ray2k posted:You could write a Visual Studio Addin that scans for those common scenarios and prevents a compile from passing if they are found. But it would be far more effort than, you know, remembering to actually dispose of things correctly the first time. Can't you do this sort of thing in something like FxCop ? I've never used it or seen it closely, but I'm fairly sure it's a tool that can check code for compliance to all sorts of rules. Not closing connections seems like right up its alley. If you have a Team Foundation Server you could even make compliance required before you're allowed to check in code.
|
# ? Mar 27, 2008 09:42 |
|
uXs posted:Can't you do this sort of thing in something like FxCop ? I've never used it or seen it closely, but I'm fairly sure it's a tool that can check code for compliance to all sorts of rules. Not closing connections seems like right up its alley. If you have a Team Foundation Server you could even make compliance required before you're allowed to check in code. FxCop is indeed the poo poo, and I'm fairly sure this is the sort of thing it can detect. Here are some of the things it reports.
|
# ? Mar 27, 2008 13:27 |
|
uXs posted:Can't you do this sort of thing in something like FxCop ? I've never used it or seen it closely, but I'm fairly sure it's a tool that can check code for compliance to all sorts of rules. Not closing connections seems like right up its alley. If you have a Team Foundation Server you could even make compliance required before you're allowed to check in code. Never used FxCop, but after looking at this, it seems like it might be able to do the job, with a little work.
|
# ? Mar 27, 2008 13:37 |
|
ray2k posted:You could write a Visual Studio Addin that scans for those common scenarios and prevents a compile from passing if they are found. But it would be far more effort than, you know, remembering to actually dispose of things correctly the first time. I will be sure to let me team know. Thanks. But now back to stuff thats actually useful. I will recommend FXcop to some people. Everyone has there own little quarks of things they forget and this might help. I was speaking specifically to database objects either. There are certain functions for cleanup that we always want use in our custom framework. I will try to read up more FXcop and see what we can do. Thanks guys.
|
# ? Mar 27, 2008 15:01 |
|
I'm just curious here:Fastbreak posted:There are certain functions for cleanup that we always want use in our custom framework. If that's true, why aren't you implementing the Disposable pattern across your objects and calling those functions in Dispose() ? It'd certainly help consistency, if nothing else.
|
# ? Mar 27, 2008 15:20 |
|
csammis posted:I'm just curious here: Implementing Idisposable for these objects are on the list of things to do. Its right behind all the stuff that makes money so its never going to get done, sadly. I don't make the priorities, I just follow them.
|
# ? Mar 27, 2008 15:54 |
|
Fastbreak posted:Implementing Idisposable for these objects are on the list of things to do. Its right behind all the stuff that makes money so its never going to get done, sadly. I don't make the priorities, I just follow them. Oh, I know how that goes. The product I work on for my job is barreling towards market and I can't do half the refactors I want
|
# ? Mar 27, 2008 16:01 |
|
|
# ? Jun 10, 2024 16:03 |
|
I did something like this once but I don't really remember how: I have a templateField in a gridview that I would like to display one field or the other depending on the particular data in the row. Here's the code code:
Is my memory faulty or can this be done?
|
# ? Mar 28, 2008 03:54 |