Posts by dcastro • 6,808 points
128 posts
-
1
votes1
answer98
viewsA: How to convert a view to string in the controller?
The scripts in the view are only executed on the client side - in the browser - after the HTML has been generated and sent to the client. You will need another view without javascript to generate…
-
2
votes1
answer780
viewsA: How to capture an error occurring on a webapi server?
By default, details of the exception occurring on the server are not placed in the HTTP response. This is to not show details of the server implementation to the client - it is a security measure.…
-
1
votes1
answer86
viewsA: Convert.Todatetime returns the previous day
It seems that the Convert.ToDateTime is converting the original date into UTC for a local date. Checks whether the property Kind is equal to DateTimeKind.Local. If it is, you have to convert the…
-
1
votes1
answer111
viewsA: Doubt about JOIN of LINQ
After performing a Join, two variables are in context: the item selected in the clause from and the group established under join. That is, in the following query: from product in products join…
-
3
votes2
answers40
viewsA: Filedialog doubt c#
Usa Path.GetExtension switch(Path.GetExtension(openFileDialog1.FileName)) { case ".cnf": //... break; case ".csr": //... break; default: throw new InvalidOperationException("Formato nao suportado");…
-
0
votes2
answers314
viewsA: Simultaneous tasks (Best way?)
I’m sorry to inform you, but you’re gonna have to use Invoke. There’s no other way. UI controls can only be modified from the UI thread. If other threads try to modify its state, there is an…
-
2
votes2
answers88
viewsA: Ensure that a set of functions function correctly
To ensure atomicity (1), you must use SQL transactions. The specific syntax depends on the SQL platform. Here’s an example in Mysql: START TRANSACTION; UPDATE Inventory SET quantity = quantity - 1…
-
3
votes1
answer427
viewsA: Associate commit to Bitbucket Issues
Yes, you can use #<issue-number> in the commit message, just like in Githubt. Example taken from the documentation: fixes #6, resolve ticket #5 and see ticket #9 and ticket #5 in the tracker…
-
0
votes4
answers4483
viewsA: Extract decimal part of a decimal
Well, the simplest way to solve the culture problem is to use the CultureInfo.InvariantCulture. So the proper functioning of the code no longer depends on the machine where it runs.…
-
1
votes1
answer258
viewsA: Is it possible to include database versioning in the commit (GIT)?
It is possible, depending on the technologies involved. Databases themselves generally do not provide versioning means. However, some frameworks do create means of applying patches to a database,…
-
4
votes2
answers303
viewsA: Edit local files without committing
The standard/ideal is to tell git not to follow modifications of these files. This is done with Commando: git update-index --assume-unchanged <filename> The file will continue to be part of…
-
2
votes2
answers316
viewsA: What is the strategy to identify a right answer, without exact comparison of String?
The algorithm @Bruno indicated in the comments (Levenshtein Distance) is a good algorithm for determining the similarity of two strings. There is another one a little more robust, called…
-
-1
votes2
answers278
viewsA: Dynamic property in Static class
As you mentioned in browser, I’ll assume you’re developing a web application. In that case, the answer is: nay use mutable static state! Using static status in a web application is a recipe for…
-
4
votes1
answer450
viewsA: Block if you just type a word into a Textbox
To count the number of words (names) in string, use: String.Trim to delete spaces at the beginning and end of the string String.Split to split the string into a word collection Array.Length to count…
-
2
votes1
answer424
viewsA: Class Order to Serialize C Object#
Decorates all class properties with the attribute [XmlElement(Order = 1)]…
-
1
votes2
answers262
viewsA: What is the difference between authorizecore and onauthorization
Succinctly: If you just want to reset the algorithm to determine whether a request is authorized or not, override the AuthorizeCore. Otherwise, use the OnAuthorization. Basically, the…
-
2
votes3
answers133
viewsA: Where are the elements selected by LINQ stored?
Since an interface obviously cannot be instantiated, where then is stored the elements that LINQ selects? It makes polymorphism and instantiation a List? LINQ namespace methods return private…
-
1
votes2
answers54
viewsA: Force the subclass
To force the subclass implementing the method ExibeDados, the method must be abstract (marked with keyword abstract). Consequently, the class Transporte should also be abstract and as such can never…
-
3
votes2
answers288
views -
3
votes1
answer214
viewsA: What is the similar command in git to Intellij’s "git revert"?
To undo changes to a specific file from the last commit (aka discard changes), just do git checkout -- path/to/file To revert all files git checkout -- . See section "Examples" of Git checkout…
-
5
votes4
answers1604
viewsA: Access javascript variable in template loop
That can’t be done. The expression @(Model.ElementAtOrDefault(0).Source) has to be evaluated on the server side, before of the html being sent to the browser and therefore, before of javascript…
-
2
votes2
answers399
viewsA: Doubt about HTTP POST
Since the launch of C# 4.0, it is standard to use HttpClient (part of the nuget Microsoft.Net.Http) for web requests. This class creates a unified API for sending/receiving HttpRequestMessages and…
-
8
votes2
answers23279
viewsA: How to remove an old commit
NOTE: If the commit has been posted, and the repository is used by others, it is highly recommended NOT to delete the commit. Instead, you can "reverse" the commit with the "git revert" command"…
-
2
votes1
answer633
viewsA: How to search for files recursively inside a folder?
To resurrect all files within a directory (and subdirectories), use Directory.GetFiles with the option SearchOptions.AllDirectories. var files = Directory.GetFiles(@"c:/folder", "*",…
-
9
votes2
answers2783
viewsA: Add new file to commit
If you do --force, and other authors have created new commits however, these commits will be permanently erased. --force is recipe for disaster and should be avoided at all costs. --amend is…
-
3
votes2
answers1064
viewsA: What does << in PHP mean?
When the right-hand operator is 31, the shift-left operator is used with a very specific purpose: to find out if the left-hand operator is even or odd. If even, the result of par << 31 will be…
-
4
votes7
answers1682
viewsA: Make the class builder private?
This is a concrete case, implemented by the ASP.NET Web Api team on Github: https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/System.Web.Http/Results/OkResult.cs I myself have applied…
-
0
votes2
answers378
viewsA: Error in reference in C#
Right click on the project "Forklifts.DTO" Properties Choose the tab "Application" Under "Target framework", choose ". NET Framework 4.0" Alternatively, you can perform the same steps to change the…
-
2
votes3
answers162
viewsA: Relationship Have-one in C#?
You have to initialize the property endereco before you can use it. The best place to do it is in the constructor. class Cliente { public string Name { get; set; } public string Idade { get; set; }…
-
2
votes1
answer1711
viewsA: How to open a . Net dll
If the library is internal (written by the company), then the company should keep the source code somewhere, probably in a different DVCS/VCS repository. In that case just ask a colleague where the…
-
17
votes5
answers38995
viewsA: How to disable (stop, remove, delete) git versioning from a repository
Delete the hidden folder .git within the repository and execute git init to start a new history.
-
0
votes4
answers164
viewsA: Father class with the same responsibility of the daughter class
The way the class Item is structured, even applying the @ramaral solution, it will be very difficult for the customer to use the item tree. Customer will always have to check if an item is a node in…
-
1
votes1
answer133
viewsA: Add parameters to Idbcommand
The estate IDbCommand.Parameters is the type IDataParameterCollection. This guy has no method called AddWithValue, only Add (defined by the interface IList). When using the interface IDbCommand,…
-
1
votes2
answers98
viewsA: How to avoid code redundancy in these two methods, one having a Ienumerable<> parameter and the other not?
The parameter joinMember and the generic parameters TProperty are only used in the first two lines of both methods. Then we can extract all other lines for a common method. public…
-
13
votes3
answers24523
views -
4
votes1
answer418
viewsA: Is it possible to keep a branch with pending changes in Git?
It is only possible to have pending changes to the branch that is currently being used. When you have pending changes, and you want to change branch, it is customary to store changes in a stash. For…
-
3
votes4
answers642
viewsA: Prevent user from saving information in the bank
The logic is wrong. Currently, to show "Saving", just fill in the student’s name - all other fields are optional. if(nomeAluno == ""){ //... if(campo2 == "") //.. if(campo3 == "") //... } else {…
-
5
votes2
answers101
viewsA: Many Relationships for Many in Restful Service
I see no problem with the suggested proposal. The fact that there are two Uris /clientes/id/fornecedores and /fornecedores it doesn’t seem strange to me. In fact, it’s a common way of managing this…
-
1
votes4
answers313
viewsA: Changing a random string of characters using Stringbuilder
A very concise and readable way: int numeroIndex = 0; var array = mascara.Select( ch => ch == '*' ? numero[numeroIndex++] : ch) .ToArray(); var result = new string(array); For each Cluster ch in…
-
8
votes4
answers661
viewsA: How do I execute a method at the end of each method in my class C#
That’s called Aspect Oriented Programming (aspect-oriented programming), an orthogonal concept to OOP. At AOP, methods are decorated with aspects. Generally, there are 3 types of aspects: aspects…
-
7
votes1
answer139
viewsA: How to restrict inherited types from a hierarchy level?
The most common way to solve this type of problems is to 'make the Generic base class, and let the derived class choose its engine type. public abstract class Veiculo<TMotor> where TMotor :…
-
2
votes3
answers2713
viewsA: ASP.NET MVC5 - Asynchronous Methods in Controller
To understand why new threads should not be created or use Threadpool (with Task.Run for example), see this question: Async operations on ASP.NET. (I found this explanation too complex, so I created…
-
9
votes2
answers1921
viewsQ: Async operations on ASP.NET
When it is advantageous to use asynchronous operations in an application ASP.NET (classic, MVC, MVC Web API)? When do I use the ThreadPool to perform some operations may be useful?…
-
18
votes2
answers1921
viewsA: Async operations on ASP.NET
Async on the Web HTTP is a protocol fundamentally synchronous. The client sends a request -> the server processes the request -> the server sends a reply -> the client receives the reply.…
-
1
votes5
answers1056
viewsA: How do I connect Windows Phone to an SQL Server?
An observation on the other comments: Windows Phone does not allow connecting to a database remote! However, it is perfectly possible to connect to a local database (e.g., Sqlite). In fact, this is…
-
5
votes1
answer512
viewsA: Close a Mysql connection without committing or rollback to c# Asp.net
If the connection is disconnected before reaching the COMMIT, happens a ROLLBACK automatic. Documentation: With START TRANSACTION, autocommit remains disabled until you end the transaction with…
-
1
votes3
answers403
viewsA: Log reading to infer counter
You have to update the comic schematics, and change the field number table Requests for primary key auto increment - this depends on BD. In SQL Server, keyword is used Identity Add attribute…
-
6
votes1
answer268
viewsA: How to hide images from 'Resources' folder?
You want to hide resources from the project? You can embed/embed them in Assembly. Just go the file properties inside Visual Studio, and where it says Build Action, select Embedded Resource. Then…
-
1
votes1
answer170
viewsA: Make Sonarqube with Opencover ignore some C#classes
Adds the flag -filter the Opencover execution command to delete types belonging to a namespace MyNamespace: -filter:"+[*]* -[NomeDaAssembly]MyNamespace.*" I’m not sure, but I think you can also…
-
5
votes3
answers17410
viewsA: How to create a Javascript function that accepts an arbitrary number of arguments?
A more advisable approach is to pass an argument map: function DoSomething(config) { config = config || {}; var idioma = config.Idioma || "en-GB"; } The first line initializes an empty map if the…