Parameter Info Tooltip using Roslyn [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I would like to develop my own tooltip for Parameter Info (which pops up as soon as you start entering parameters in a function call).
I would like to implement it using Roslyn, but I don't know where to start. Can anyone provide me a small example to get me started?

I should preface this by pointing out that extending Visual Studio is not a particularly easy, fun or straightforward endeavor.
I believe the MSDN article Walkthrough: Displaying Signature Help should get you off to a good start.
The Signature Help source is based on signatures that implement ISignature, each of which contains parameters that implement IParameter.
So first we have to create a parameter that inherits from IParameter.
Next we have to create a signature that inherits from ISignature. The key here is to implement a CurrentParameterChanged event that is fired as the user types commas, changing with parameter's definition should be shown.
This is accomplished by creating the event and firing it as follows:
public event EventHandler<CurrentParameterChangedEventArgs> CurrentParameterChanged;
public IParameter CurrentParameter
{
get { return m_currentParameter; }
internal set
{
if (m_currentParameter != value)
{
IParameter prevCurrentParameter = m_currentParameter;
m_currentParameter = value;
this.RaiseCurrentParameterChanged(prevCurrentParameter, m_currentParameter);
}
}
}
private void RaiseCurrentParameterChanged(IParameter prevCurrentParameter, IParameter newCurrentParameter)
{
EventHandler<CurrentParameterChangedEventArgs> tempHandler = this.CurrentParameterChanged;
if (tempHandler != null)
{
tempHandler(this, new CurrentParameterChangedEventArgs(prevCurrentParameter, newCurrentParameter));
}
}
They computer the current parameter based on the number of commas in the string. The ComputeCurrentParameter() method is a little too long to post here, however.
Next you have to implement ISignatureHelpSource. This interface provides signature help information for Intellisense.
The method ISignatureHelpSource.AugmentSignatureHelpSession() is where the list of parameter information is created and where you'll be adding your custom parameter information. The MSDN provided example uses pre-written strings here. In reality, you'd probably want to calculate these things on the fly, perhaps with Roslyn, depending on your goals.
Finally, you must export an ISignatureHelpSourceProvider via MEF. This allows Visual Studio to consume your ISignatureHelpSource.

Related

C# checking if a word is in an English dictionary? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to go through a list of words and for each one determine if it is a valid English word (for Scrabble). I'm not sure how to approach this, do I have to go find a text file of all English words and then use file reading and parsing methods to manually build a data structure like a trie or hashmap - or can I find those premade somewhere? What is the simplest way to go about this?
You can use NetSpell library for checking this. It can be installed through Nuget Console easily with the following command
PM> Install-Package NetSpell
Then, loop through the words and check them using the library
NetSpell.SpellChecker.Dictionary.WordDictionary oDict = new NetSpell.SpellChecker.Dictionary.WordDictionary();
oDict.DictionaryFile = "en-US.dic";
oDict.Initialize();
string wordToCheck = "door";
NetSpell.SpellChecker.Spelling oSpell = new NetSpell.SpellChecker.Spelling();
oSpell.Dictionary = oDict;
if(!oSpell.TestWord(wordToCheck))
{
//Word does not exist in dictionary
...
}
Since you're looking specifically for valid Scrabble words, there are a few APIs that validate words for Scrabble. If you use anything that's not for that intended purpose then it's likely going to leave out some words that are valid.
Here's one, here's another, and here's a separate question that lists available APIs.
So that I can add some value beyond just pasting links, I'd recommend wrapping this in your own interface so that you can swap these out in case one or another is unavailable (since they're all free services.)
public interface IScrabbleWordValidator
{
bool IsValidScrabbleWord(string word);
}
Make sure your code only depends on that interface, and then write implementations of it that call whatever APIs you use.

Class Names in C# (English vs Intellisense) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm using Visual Studio 2013 to write C# code.
How should I name my classes? In a "English-friendly" way, or in a way thats more IntelliSense- friendly.
For instance, I have a interface called
IColorComparer. And a few classes that implement that interface:
QuadraticColorComparer vs ColorComparerQuadratic DefaultColorComparer vs ColorComparerDefault TrauerColorComparer vs ColorComparerTrauer
Question: Is there a official naming convention for Classes in C# / VS? Does it take tools like IntelliSense into account?
Here are some links provided by Microsoft regarding the naming conventions in C#
General Naming Conventions
https://msdn.microsoft.com/en-ca/library/ms229045(v=vs.110).aspx
Capitalization Conventions
https://msdn.microsoft.com/en-ca/library/ms229043(v=vs.110).aspx
Overall Guidelines for naming
https://msdn.microsoft.com/en-ca/library/ms229002(v=vs.110).aspx
Here is another link provided by "dofactory" for C# coding standards
http://www.dofactory.com/reference/csharp-coding-standards
It usually makes sense to put the differentiator at the start. For example:
TextReader / StreamReader / StringReader
Stream / FileStream / MemoryStream / NetworkStream
It's like having an adjective to provide more detail: "the red book, the blue book".
One alternative option is to avoid exposing the classes themselves, and instead have:
public static class ColorComparers
{
public static IColorComparer Quadratic { get { ... } }
public static IColorComparer Default { get { ... } }
public static IColorComparer Trauer { get { ... } }
}
Then you'd just use it as:
IColorComparer comparer = ColorComparers.Quadratic;
Does anything else really need the implementation details? The implementations could even be private nested classes within ColorComparers.
There is no rule for such naming convention. But of course there are coding standards in c#. Please refer below link which indicates naming conventions standards by Microsoft:
Microsoft naming conventions
For your questions answer I would suggest you to use friendly names and more convenient names for classes. For example use
public class ColorComparer
Or
public class CompareColor
Use names that is more friendly to read and understand which will reduce your ans other developers time as well and also help in reducing maintenance cost.
You can ask me your doubts further.
Happy coding 😊

Need a great explanation of using MOQ syntax [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I seem to have problems getting MOQ syntax by example. I would like to have suggestions where to look, besides MOQ website, to comprehend usage of mocking various interfaces.
For example, I would like to understand how exactly I proceed mocking this or that interface method and be able, for example, to undestand why a developer writes things like this:
daoMock.Setup(d => d.Get(It.Is<Expression<Func<ConfigurationEntity, bool>>>(e => ExpressionMatchesEntityWithKey(e, TestKey))))
.Returns(new List<ConfigurationEntity> {configEntity});
thanks in advance!
The github page, as suggested by #Jakub, is actually a great place to start.
Either way, I'll explain the example you posted.
Say you have this interface and this setup:
public interface IDao
{
IEnumerable<ConfigurationEntity> Get(Expression<Func<ConfigurationEntity, bool>> expression) {...}
}
var daoMock = new Mock<IDao>();
daoMock.Setup(d => d.Get(It.Is<Expression<Func<ConfigurationEntity, bool>>>(e => ExpressionMatchesEntityWithKey(e, TestKey))))
.Returns(new List<ConfigurationEntity> {configEntity});
This setup tells the mock to return a list containing configEntity when:
the Get method is called
with an argument of type Expression<Func<ConfigurationEntity, bool>>
and ExpressionMatchesEntityWithKey(e, TestKey) (where e is the expression passed in as an argument) returns true.
So, basically, when you call the Get method on the mocked object, Moq will check if the argument is of the correct type, check if ExpressionMatchesEntityWithKey(e, TestKey) returns true, and then return a list with configEntity.
By default, if any of these requirements are not met, the mocked object will return the default value for IEnumerable<ConfigurationEntity>, which is null.
Now, you can retrieve the mocked object and do whatever you want with it.
IDao dao = daoMock.Object;

How do I create a method, and make a constructer that calls the method [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
All in the Title.
Also please give an answer in less than a week.
I need someone to really help me with this, I'm using an online course and it says I have to Write the NumberBoard method, then write a NumberBoard constructer and call the method.
Here's the link to the .zip file that has the PDF telling me what to do, and the project that they give you:
https://d396qusza40orc.cloudfront.net/gameprogramming%2Frequired_assessment_materials%2FRequiredProjectMaterials.zip
(Copy and paste if link not clickable)
To get to the project, open the code folder and click the "GameProject" thing
Something like this will work
public class SomeClass
{
public SomeClass() //constructor
{
SomeMethod(); //Calling the method in constructor
}
public void SomeMethod() // Method
{
//Method implementation
}
}

General method placement [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Is it best practice to place method bodies before or after they are called ? I generally place them after; interested in what others are doing ?
I prefer after. The reason for this is because it makes the flow of your code more logical. Code flows from top to bottom anyway, so it's logical that methods called appear after the current method.
This has the added advantage of the entry point of your program/class being at the top, which is where you start looking anyway.
When developing Java, I place the method bodies after they are called. This will typically result in classes that have a small number of public methods at the top, followed by quite a few private methods at the bottom. I think this makes the class easier to read and understand: you just need to read those few public methods at the top to understand what the class does — in many cases you can stop reading once you get to the private methods.
I also note that Java IDEs typically place the method body after the current method when you refactor code. For example in Eclipse, if you select a block of code and click Refactor | Extract Method... it will place that selected code in a new method below the current one.
It is entirely a matter of personal preference. For most people, the code navigation facilities of a modern IDE mean that it hardly makes any difference how the methods are ordered.
The method placement is largely irrelevant to me (of course in case of some static methods that need to be defined before invoked):
The code formatters are usually in place (and running automatically - if not for you, turn them on) which results in the source being ordered nicely by type of the method and then alphabetically, rather without the regard to the method call sequence
I use the modern IDE, where finding the proper method is done in a different way than sequentially going through the whole source

Categories