This question already has answers here:
How do I use the LINQPad Dump() extension method in Visual Studio? [closed]
(4 answers)
Closed 8 years ago.
Given (new [] {"a", "b"}).Dump(), LinqPad provides some very useful print results.
It seems that this extension method is a short hand for Console.WriteLine.
Question> how to implement this dump for myself?
This thread might be of use to you.
Is there a library that provides a formatted Dump( ) function like LinqPad?
With a lot of hard work.
Dump is not a shortcut for Console.WriteLine; it's an extremely complicated recursive method which turns arbitrary object graphs into HTML, with special support for collections, DataTables, Images, and a couple of other types.
It also has special output code to format collections of complex objects into tables, and to prevent recursive expansion.
You can grab the Object Dumper class that is included in the Visual C# 2008 Samples. It won't be in the pretty HTML format used by LINQPad and the other types of output it supports, but the purpose is similar.
Related
This question already has answers here:
Is there a way to implement custom language features in C#?
(6 answers)
Closed 6 years ago.
I'm writing a library for personal use that greatly expands C# features, and I was wondering on something quite interesting... Is it possible to create you own keywords? For example, if, foreach, for etc.
The reason I want to do this can be found at my previous question.
No, you can not do that. Language keywords are defined in the language definition. You could probably use the open sourced parts (compilers, etc) and create your own version of them.
This question already has answers here:
Order of items in classes: Fields, Properties, Constructors, Methods
(16 answers)
Closed 9 years ago.
Is there an official (ie, FX Cop, Guidance on MSDN, etc) way to organize the Properties, Methods and Events in a class file?
I know this can be seen as a "preference" and I have seen it done many different ways, typically:
Constructor
Properties
Events
Methods, in alphabetically order.
My goal is to have a well organized class file which becomes important as the size of the class file gets rather large. (Therein is a different topic, splitting a class which is too large.) It also becomes important when multiple developers are working together so there is an agreed upon standard.
So I am looking for something "official" I can use as a reference for this.
I believe Stylecop used to be Microsoft's baby, might be worth taking a look at it to see what it recommends?
Stylecop
You can refer to:
What's the best way to layout a C# class?
and to:
Order of items in classes: Fields, Properties, Constructors, Methods
For a detailed excellent answers.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Evaluate C# string with math operators
So lets say I have a basic string with the value "1*2+4"
How would I go about parsing the information and then doing the calculation?
I am self teaching c# but my assumption is this is a common issue in programming but without using a library how would one do this?
My results so far have got me splitting the string up and putting them into an array of chars, but this is where I've stopped since I am trying to figure out how to compare chars to operators and chars to ints.
I am not sure if I am going the right way about this but would be great if someone could point me in the right direction.
Thank you for your help in advanced.
What you're looking for is the Shunting-yard algorithm.
You'll need at least two stacks; one for storing operators and one for operands. After you fill the stacks you can make a RPN and calculate the answer.
Well c# (or any other language) might provide you with various tools to help you, but the overall approach to the problem will always remain the same whatever the programming language be.
So yes, you do split up into operators & integers. You do recognize the characters one by one, but try to do it in the most efficient way of the language. Fosco's anser points to the right link. Use Ncalc Library than doing manual labor.
However, to complete what you started :
int.Parse(str)
int.TryParse(str, out num)
...are the functions you may consider to convert character strings into integers (which you got, by using split() function?) in C#. You can read about them here...(Parse, TryParse)
If you want to learn how the various existing libraries do it, you should learn about parsing, lexical and syntactic analysis, expression trees, compiler theory, etc. Also, go through the source-code of any of the multiple open-source libraries that do it.
This question already has answers here:
C# adding implict conversions to existing types
(2 answers)
Closed 9 years ago.
I have two custom classes for which I want to implement casts between each other. I only have the DLLs of the two projects and not the code. Can I use extension methods to implement the cast or would I need to do something else?
I'd suggest that you implement your own mappers between the 2 classes or use mapping tools such as AutoMapper or ValueInjecter
You will have to use either extension methods or some other mapping. You could also use http://automapper.codeplex.com/
I don't think there is a way to do it. Anyway, do you really need the code to look like cast? Sometimes when you implement operators or casts for custom types the code may become harder to understand. I would suggest to create separate utility to convert types which would be more obvious for someone who sees the code for the first time.
This question already has answers here:
How can I extract all classes into separate file?
(3 answers)
Closed 9 years ago.
I've started to refactor/clean up big project. Some of files contains few small classes or few enums (yeah, it is very messy;/ ).
Is there some method or tool to automatically divide files with few enums/classes and create separate files for each of them?
As Fredrik Mörk said - Resharper is very good tool and has possibility to do what I need. But of course as almost all good tools it costs (for one it is cheap, for another not:) ).
Maybe there is some free tool for such simple refactoring? (my boss will not pay for Resharper - he told me that I need 'hammer' not a whole workshop:) )
Resharper has a refactoring that moves a type to a separate file. Might be that it can be applied on a higher level (as project); don't have it installed on this machine to verify though.
Edit: noticed in the online help that there is a refactoring called Move Types Into Matching Files that does exactly what you are asking for.
CodeRush xpress (free) also supports Moving a type into a matching file