Skip to content

Instantly share code, notes, and snippets.

@urasandesu
Last active August 29, 2015 14:05
Show Gist options
  • Save urasandesu/10eb367afb2a5fe310d6 to your computer and use it in GitHub Desktop.
Save urasandesu/10eb367afb2a5fe310d6 to your computer and use it in GitHub Desktop.
DateTime_Now_Indirect_v2.cs
namespace System
{
public struct DateTime
{
public static DateTime Now
{
get
{
try
{
// スタブでやっていたことの逆が挿入される。
var holder = default(IndirectionHolder<IndirectionFunc<DateTime>>);
if (LooseCrossDomainAccessor.TryGet(out holder))
{
var info = new IndirectionInfo();
info.AssemblyName = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
info.Token = 0x060002D2;
var get_Now = default(IndirectionFunc<DateTime>);
if (holder.TryGet(info, out get_Now))
{
return get_Now();
}
}
}
catch (Exception e)
{
var exists = false;
for (var type = e.GetType(); type != null; type = type.BaseType)
{
if (type.FullName == "Urasandesu.Prig.Framework.FlowControlException")
{
exists = true;
break;
}
}
if (!exists)
throw;
// 条件によって、全く違う処理(例えば、特定のインスタンスの時だけ元の処理を呼び出す)を
// 行いたい場合は、FlowControlException 派生例外をスロー。
}
// 元の処理がそのままコピーされる。
return DateTime.UtcNow.ToLocalTime();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment