A good example of using the dialog in JQuery UI with ajax.
ASP.NET LIVE: jQuery dialog extender for Asp.Net MVC Views
ASP.NET LIVE: jQuery dialog extender for Asp.Net MVC Views
// This method can take a variable number of ints
public int Sum(params int[] values)
{
int sum = 0;
foreach(int value in values)
{
sum += value;
}
return sum;
}
// Method calls
int sum1 = Sum(1, 2, 3, 4);
int sum2 = Sum(1, 2);
// Override with three params
public int Sum(int val1, int val2, int val3) { /* ... */ }
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace TestArgumentParser
{
public class ArgumentParser
{
public string QuoteChars { get; set; }
public string ValueSeparatorChars { get; set; }
public string PrefixChars { get; set; }
public Dictionary Params = new Dictionary();
public string this[string key] { get{ return Params[key]; } }
public ArgumentParser()
{
SetDefaultValues();
string argString = GetComandLineArguments();
Parse(argString);
}
public ArgumentParser(string args)
{
SetDefaultValues();
Parse(args);
}
private static string GetComandLineArguments()
{
string argString = Environment.CommandLine;
argString = argString.Replace("\"" + Process.GetCurrentProcess().MainModule.FileName + "\"", "");
return argString;
}
public void Parse(string arguments)
{
string currentParam = string.Empty;
string currentValue = string.Empty;
bool readingParam = false;
bool readingValue = false;
bool startQuotes = false;
foreach (char c in arguments)
{
if (IsPrefix(c))
{
HandlePrefix(Params, ref currentParam, ref currentValue, ref readingParam);
continue;
}
if (readingParam)
{
HandleParam(ref currentParam, ref readingParam, ref readingValue, c);
continue;
}
if (readingValue)
{
HandleValue(ref currentValue, ref startQuotes, c);
continue;
}
}
if (!string.IsNullOrEmpty(currentParam))
{
Params.Add(currentParam, currentValue);
}
}
private void SetDefaultValues()
{
QuoteChars = "\"\'";
ValueSeparatorChars = ":= ";
PrefixChars = "-/";
}
private void HandlePrefix(Dictionary list, ref string currentParam, ref string currentValue, ref bool readingParam)
{
if (!string.IsNullOrEmpty(currentParam))
{
list.Add(currentParam, currentValue);
}
currentParam = string.Empty;
currentValue = string.Empty;
readingParam = true;
}
private void HandleValue(ref string currentValue, ref bool startQuotes, char c)
{
if (IsQuote(c))
{
startQuotes = !startQuotes;
return;
}
if (!startQuotes && char.IsWhiteSpace(c))
{
return;
}
currentValue += c;
}
private void HandleParam(ref string currentParam, ref bool readingParam, ref bool readingValue, char c)
{
bool isValueSeparator = IsValueSeparator(c);
if (!isValueSeparator)
{
currentParam += c;
}
else
{
readingValue = true;
readingParam = false;
}
}
private bool IsQuote(char c)
{
return QuoteChars.IndexOf(c) > -1;
}
private bool IsValueSeparator(char c)
{
return ValueSeparatorChars.IndexOf(c) > -1;
}
private bool IsPrefix(char c)
{
return PrefixChars.IndexOf(c) > -1;
}
}
}
// This code will return "MyProperty".
ObjectHelper.GetMemberName(() => someEntity.MyProperty);
using System;
using System.Linq.Expressions;
///
/// Extensions to object class
///
public static class ObjectHelper
{
///
/// Gets the name og the property og class using Expression trees
///
///
/// The expression to get name for
///
///
/// Type of the object
///
///
/// A string with the name, or an exception if it isn't a member expression
///
///
///
private static string GetMemberName(Expression> e)
{
var member = e.Body as MemberExpression;
// If the method gets a lambda expression
// that is not a member access,
// for example, () => x + y, an exception is thrown.
if (member == null)
{
throw new ArgumentException(
"'" + e +
"': is not a valid expression for this method");
}
return member.Member.Name;
}
}
Dummy SMTP server that sits in the system tray and does not deliver the received messages. The received messages can be quickly viewed, saved and the source/structure inspected. Useful for testing/debugging software that generates email.
using System;
using System;
using System.ServiceModel;
///
/// Helper class for WCF clients
///
public class WcfClientUtils
{
///
/// Execute actions against the client and aborts the client on a faulted state
///
/// Client type
/// Client instance
/// Actions to perform on instance
///
/// WcfClientUtils.Execute(new ServiceReference1.Service1Client(),
/// client =>
/// {
/// var returnData = client.HelloWorld());
/// });
///
public static void Execute(T client, Action action) where T : ICommunicationObject
{
try
{
//client.Open();
action(client);
client.Close();
}
catch (CommunicationException)
{
client.Abort();
throw;
}
catch (TimeoutException)
{
client.Abort();
throw;
}
catch (Exception)
{
if (client.State == CommunicationState.Faulted)
{
client.Abort();
}
throw;
}
}
}
WcfClientUtils.Execute(new ServiceReference1.Service1Client(),
client =>
{
var returnData = client.HelloWorld());
});