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));
}
}
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);
#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();
}
}
class Class1Wrapper {
public readonly Class1 Wrapped;
public Class1Wrapper(Class1 toWrap) {
Wrapperd = toWrap;
}
public override string ToString() {
return string.Format("X: {0}, Y : {1}", Wrapped.X, Wrapped.Y);
}
public static Class1Wrapper Wrap(Class1 toWrap) {
return new Class1Wrapper(toWrap) ;
}
}
Дальше в тесте
Assert.That(templateSeries.getElements().Select(Class1Wrapper.Wrap).ToArray(),
Is.EqualTo(resultSeries.getElements().Select(Class1Wrapper.Wrap).ToArray())
.Using(new Class1WrapperComparer()));