Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

I would do it like this:

dictionaryFrom.ToList().ForEach(x => dictionaryTo.Add(x.Key, x.Value));
Simple and easy. According to this blog post it's even faster than most loops as its underlying implementation accesses elements by index rather than enumerator (see this answer).

It will of course throw an exception if there are duplicates, so you'll have to check before merging.
3 years ago
We do this on our Intranet

You have to use System.DirectoryServices;

Here are the guts of the code
***
using (DirectoryEntry adsEntry = new DirectoryEntry(path, strAccountId, strPassword))
{
using (DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry))
{
//adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))";
adsSearcher.Filter = "(sAMAccountName=" + strAccountId + ")";

try
{
SearchResult adsSearchResult = adsSearcher.FindOne();
bSucceeded = true;

strAuthenticatedBy = "Active Directory";
strError = "User has been authenticated by Active Directory.";
}
catch (Exception ex)
{
// Failed to authenticate. Most likely it is caused by unknown user
// id or bad strPassword.
strError = ex.Message;
}
finally
{
adsEntry.Close();
}
}
}
***
3 years ago
I found another way you can do it was to have the source and property strongly typed and explicitly infer the input for the lambda. Not sure if that is correct terminology but here is the result.

public static RouteValueDictionary GetInfo(this HtmlHelper html, Expression> action) where T : class
{
var expression = (MemberExpression)action.Body;
string name = expression.Member.Name;

return GetInfo(html, name);
}
And then call it like so.

GetInfo((User u) => u.UserId);
3 years ago
The biggest use of partial classes is to make life easier for code generators / designers. Partial classes allow the generator to simply emit the code they need to emit and they do not have to deal with user edits to the file. Users are likewise free to annotate the class with new members by having a second partial class. This provides a very clean framework for separation of concerns.

A better way to look at it is to see how designers functioned before partial classes. The WinForms designer would spit out all of the code inside of a region with strongly worded comments about not modifying the code. It had to insert all sorts of heuristics to find the generated code for later processing. Now it can simply open the designer.cs file and have a high degree of confidence that it contains only code relevant to the designer.
3 years ago
The simplest way to do this is to install Json.NET from nuget and add the [JsonIgnore] attribute to the virtual property in the class, for example:
***
public string Name { get; set; }
public string Description { get; set; }
public Nullable Project_ID { get; set; }

[JsonIgnore]
public virtual Project Project { get; set; }
***
Although these days, I create a model with only the properties I want passed through so it's lighter, doesn't include unwanted collections, and I don't lose my changes when I rebuild the generated files...
3 years ago
If you're using .Net 3+, you can use Linq.
***
List withDupes = LoadSomeData();
List noDupes = withDupes.Distinct().ToList();
***
3 years ago
***
public void SomeMethod(int a, int b = 0)
{
//some code
}
***
3 years ago
***
Guid id = Guid.NewGuid();
***
3 years ago
Theres lots of ways of doing this, but the two I've found to be most useful are these:

Detexify Allows you to draw the symbol, and then guesses based on similar symbols. This is great for me because I don't always remember the name of the symbol, and even if I know the name, I may not have the correct name.

AMS LaTeX Short Math Guide This short pdf gives an overview of AMS LaTeX functionality, and includes a pretty thorough list of most of the math symbols (un)commonly used in proofs and formulas.
3 years ago
if the content should be placed in the exact place it was defined in the source document, then the H float modifier from the float package can be used to accomplish this. This differs from the floatless solution discussed in the second paragraph in that it does use a float (even though it doesn't actually float anywhere). This can be useful for instance if a certain floatstyle is used throughout the document (e.g. the ruled and boxed styles from the float package) and we wish to have a consistent look.
3 years ago
***
function msieversion() {

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
{
alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
}
else // If another browser, return 0
{
alert('otherbrowser');
}

return false;
}
***
3 years ago
should be done like that and not with delete operator:
***
localStorage.removeItem(key);
***
3 years ago