I use IntelliJ (java) IDE and it can easily generate a really nice toString() for any class that includes all the properties etc.
So in my log4net I want to output the deserialized version of a class.
Can resharper do this or do I have to manually do it myself?
Yes it can. Look at help topic Generating Formatting Members.
Related
Is there a way to pull up common methods, properties etc. just by name (maybe even signature too) into a common class from 2 or more classes?
You can extract some members from a single class to a base class as in this documentation link from Resharper 2016.2, but detect the common properties and methods seems to be a very tricky thing to do without any input from the developer.
There is a feature request in Jetbrains' backlog asking for something like that since 2014, but the linked SO question states the same I'm telling you. Maybe you want to take a look at it too.
As an Eclipse using client-side dev, my colleague just showed me the coolest features in Visual Studio where he copied a JSON string representing a single object and paste special into Visual Studio, then it automagically create a C# class complete with setters and getters. He then took a JSON string representing an array of objects and then did the same workflow. Visual Source save then derived the common fields in the collection and automagically created a C# class.
How do I do this in Eclipse? There is no such thing as Paste Special -> Parse JSON to Class in Eclipse that I know of.
protostuff could probably fit with your requirements, see http://code.google.com/p/protostuff/
it takes a special language describing the base data structure an produces tidy java classes with annotations.
Automagically deriving structured java classes from schema-less JSON sample data is IMHO a bad idea as you may miss optional fields that are not in your sample.
I want to build a visual studio plugin that automatically annotates classes for serialization. For example for the built in binary serializer I could just add [Serializable] to the class declaration, for WCF it could add [DataContract] to the class and [DataMember] to the members and properties (I could get [KnownType] information through reflection and annotate where appropriate). If using protocol buffers it could add [ProtoContract], [ProtoMember] and [ProtoInclude] attributes and so on.
I am assuming that the classes we are going to use this on are safe to serialize (so no sockets or nonserializable stuff in there). What I want to know is what is the easier way to take an existent piece of code (or a binary if that's easier) and add those attributes while preserving the rest of the code intact. I am fine with the output being source code or binary.
It comes to mind the idea of a using a C# parser, parse everything find the interesting code elements, annotate them and write back the code. However that seems to be very complex given the relatively small amount of modifications I want to make to the code. Is there an easier way to do so?
Visual Studio already has an API for discovering and emitting code which you might take a look at. It's not exactly a joy to use but could work for this purpose.
While such a plugin would certainly be a useful thing, I would consider rather making an add-in for a tool like ReSharper instead of VS directly. The advantage is somebody already solved the huge pile of problems you haven't even dreamed of yet and so it will be a lot easier to build such a specific functionality.
it looks to me like you need to have a MSBuild task similar to this one http://kindofmagic.codeplex.com/. is that about right?
i'm adding comments to some csharp code, and i'm using the xml language provided by .net (or something). i have an interface, and some implementing classes. i have one method in the interface, and it has a comment. in the implementing classes there is no comment on the implementing method.
when one does it like this in java, javadoc automagically uses the interface comment when generating documentation. however, now that i build my project, i get the warning (transalted from swedish, sorry) "the xml comment for the visible type or member bla.blabla.blablabla() is missing (cs1591)". this is only a warning, so not so bad. but!!! it means no xml file was output, so i can't use sandcastle to generate a chm document file, which is my real goal here.... googling the error coded gave nothing :(
do i really have to copy the method comment to all implementing classes? that's like.... code duplication D: is there no way to get the behavior java offers?
I don't know of any way of getting it to happen at XML file generation time, but GhostDoc may well save you from performing the copying manually. I can't say I've used it myself though.
I agree that it would be a valuable feature... particularly if the base class (or interface) documentation changes after the derived classes have been implemented and documented.
You do have to copy the interfaces comments to the implementing class. Generally this is a good thing as the two comments should ideally be different - my opinion (and practise) on this can be summarised as the following:
Interface Comments - Explains what the method/property/etc is supposed/expected to do but should generally not proscribe how any specific implementation should behave
Implementing Class Comments - Explains what the method/property/etc actually does and may include some details of how this is done (typically in <remarks>)
VSdocman can resolve missing XML comments from implemented interfaces automatically when it generates documentation. Moreover, like GhostDoc, it can also explicitly copy inherited comments to the implementing method. Unlike Sandcastle, it's not free.
Well i dont know about Java but Sorry you will have to copy the interface's comments in the implemented class. here is no inbuilt way of doing it...
And yeah consider the suggestion given by JonSkeet
Basically what I would like to know is if there is any way to add new 'statements' to the .net based languages?
An example of what I'm looking for would be something like introducing a public class MyClass decoratorOf ClassWithLotsOfMethods and in pre-compile time changing that to be a normal class that overrides everything by default but the methods I define.
Another example would be the .net 3.5 auto properties, or extension methods, etc
This is just for fun, not that I really want to do this, just curious if is possible
Thanks!
Seba
C# doesn't allow this. You can of course tweak the generated IL with a post-compiler (like CciSharp).
Some alternative .NET languages that allow extensions are Nemerle and Boo.
There is nothing built-in.
You could of course use a PreProcessor but that won't make you popular.
Not that I know about, but take a look at PostSharp and T4 Templates and see if that can solve your problem :)
Related: Extending the Mono C# compiler: is there any documentation or precedent?