public class SingleResult<T> where T : class {
private readonly T result;
public readonly bool IsSuccess;
private SingleResult(T result, bool isSuccess) {
this.result = result;
IsSuccess = isSuccess;
}
public T Result {
get {
Contract.Requires<InvalidOperationException>(IsSuccess);
return result;
}
}
public static SingleResult<T> Success(T result) {
Contract.Requires<ArgumentNullException>(result != null, "result");
return new SingleResult<T>(result, true);
}
public static SingleResult<T> Nothing = new SingleResult<T>(null, false);
}
public SingleResult<SomeRecord> FindMe(string prop) {
var l = <linqquery >;
var result = l.SingleOrDefault();
if (result == null)
return SingleResult<SomeRecord>.Nothing;
return SingleResult<SomeRecord>.Success(result);
}
public bool TryFindSingle(string prop, out SomeRecord result) {...}
sealed class CompoundPlugin<T> : Plugin<T> {
private readonly IReadOnlyList<Plugin<T>> plugins;
public CompoundPlugin(IReadOnlyList<Plugin<T>> plugins) {
Contract.Requires<ArgumentNullException>(plugins != null, "arg");
Contract.Requires<ArgumentException>(plugins.Count > 0);
this.plugins = plugins;
}
public override T Modify(T param) {
return plugins.Aggregate(param, (arg1, plugin) => plugin.Modify(arg1));
}
}
int tmp = j;
j = j + 1;
j = temp;
IL_0006: ldloc.0 // В стек кладем значение j (оно у нас == 0)
IL_0007: dup // Дублируем в стеке значение j
IL_0008: ldc.i4.1 // Кладем второй аргумент инкремента (он == 1)
IL_0009: add // Складываем два верних значения, результат кладем в стек
IL_000a: stloc.0 // Сохраняем в j результат сложения
IL_000b: stloc.0 // Сохраняем в j 0, который получился при dup
class CustomDependencyManager {
class CustomDependency : CacheDependency {
public void Invalidate() {
NotifyDependencyChanged(this, EventArgs.Empty);
}
}
public static CustomDependencyManager Instance = new CustomDependencyManager();
private readonly ConcurrentDictionary<string, CustomDependency> dependencies = new ConcurrentDictionary<string, CustomDependency>();
private CustomDependency GetCacheDependencyInternal(string xxx) {
return dependencies.GetOrAdd(xxx, s => new CustomDependency());
}
public void Invalidate(string xxx) {
GetCacheDependencyInternal(xxx).Invalidate();
}
public CacheDependency For(string xxx) {
GetCacheDependencyInternal(xxx);
}
}
Cache.Insert("prefix_"+xxx+"_"+yyyy, data, CustomDependencyManager.Instance.For(xxx), DateTime.Now.AddSeconds(1), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
...
...
// Пора сбросить кеш
CustomDependencyManager.Instance.Invalidate(xxx);
public class DateToEnabledConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
if(value is Plavka)
return ((DateTime.Now - ((Plavkas) value).dataPrig).Days != 1);
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
return null;
}
<Window.Resources>
<wpfApplication1:DateToEnabledConverter x:Key="dateToEnabledConverter" />
</Window.Resources>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding plavka1}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox IsEnabled="{Binding Converter= {StaticResource dateToEnabledConverter}}" Text="{Binding plavka1}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
const string input = "\"key\"=\"value\";\"key1\"=\"value1\";\"key2\"=\"value2\"";
var result = Regex.Matches(input, @"\""(?<key>\w*)\""=\""(?<value>\w*)\""")
.OfType<Match>()
.ToDictionary(match => match.Groups["key"], match => match.Groups["value"]);
foreach (var pair in result) {
Console.Write(pair.Key);
Console.Write("=");
Console.WriteLine(pair.Value);
}
foreach(var substring in Regex.Split("'2+'+'3=5'", @"'\+'").Select(s => s.Trim('\'')))
Console.WriteLine(substring);
2+
3=5
class Program {
static void Main(string[] args) {
SyntaxTree tree = SyntaxTree.ParseText(
@"using System;
namespace HelloWorld {
class Program {
static void Main(string[] args) {
var i = 10 * 20;
String s = t.ToString();
}
}
}");
var comp = Compilation.Create("HelloWorld")
.AddReferences(MetadataReference.CreateAssemblyReference("mscorlib"))
.AddSyntaxTrees(tree);
var model = comp.GetSemanticModel(tree);
new Walker(model).Visit(tree.GetRoot());
Console.ReadKey();
}
class Walker : SyntaxWalker {
private readonly SemanticModel model;
public Walker(SemanticModel model) : base() {
this.model = model;
}
public override void VisitVariableDeclarator(VariableDeclaratorSyntax node) {
var declaredSymbol = (LocalSymbol) model.GetDeclaredSymbol(node);
Console.WriteLine("{0} {1} {2}", declaredSymbol.Type, declaredSymbol.Name, node.Initializer.GetText());
}
}
#include <stdio.h>
extern "C" __declspec(dllexport)
void __stdcall TestString(char str[]) {
char source[] = "Привет!";
sprintf_s(str, sizeof(source), source);
}
class Program {
[DllImport(@"Project1.dll", CharSet=CharSet.Ansi)]
public static extern void TestString(StringBuilder str);
static void Main(string[] args) {
var sb = new StringBuilder(4096);
TestString(sb);
Console.Write(sb.ToString());
Console.ReadLine();
}
}
private void Form1_Paint(object sender, PaintEventArgs e) {
DrawRegularPolygon(new PointF(100, 100), 10, 100, e.Graphics);
}
private static void DrawRegularPolygon(PointF center, // Координаты центра окружности
int vertexes, // Количество вершин
float radius, // Радиус
Graphics graphics) {
var angle = Math.PI*2/vertexes;
var points = Enumerable.Range(0, vertexes)
.Select(i => PointF.Add(center, new SizeF((float) Math.Sin(i*angle)*radius, (float) Math.Cos(i*angle)*radius)));
graphics.DrawPolygon(Pens.Black, points.ToArray());
graphics.DrawEllipse(Pens.Aqua, new RectangleF(PointF.Subtract(center, new SizeF(radius, radius)), new SizeF(radius * 2, radius * 2)));
}
WebRequest request = HttpWebRequest.Create("http://rain.kassir.ru:8080/kassirgate/");
WebRequest request = HttpWebRequest.Create("http://rain.kassir.ru:8080/kassirgate/VenueService/");
using (var txtReader = new StreamReader(@"statuses.xml")) {
var xmlAttributeOverrides = new XmlAttributeOverrides();
var xmlAttributes = new XmlAttributes {
XmlRoot = new XmlRootAttribute("issue_statuses")
};
xmlAttributeOverrides.Add(typeof(IssueStatus[]), xmlAttributes);
var attributes = new XmlAttributes {
XmlRoot = new XmlRootAttribute("issue_status"),
XmlType = new XmlTypeAttribute("issue_status")
};
xmlAttributeOverrides.Add(typeof(IssueStatus), attributes);
var xmlSerializer = new XmlSerializer(typeof (IssueStatus[]), xmlAttributeOverrides);
var statuses = (IssueStatus[])xmlSerializer.Deserialize(txtReader);
}