本文整理汇总了C#中Lazy类的典型用法代码示例。如果您正苦于以下问题:C# Lazy类的具体用法?C# Lazy怎么用?C# Lazy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Lazy类属于命名空间,在下文中一共展示了Lazy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReflectedAsyncActionDescriptor
internal ReflectedAsyncActionDescriptor(MethodInfo asyncMethodInfo, MethodInfo completedMethodInfo, string actionName, ControllerDescriptor controllerDescriptor, bool validateMethods) {
if (asyncMethodInfo == null) {
throw new ArgumentNullException("asyncMethodInfo");
}
if (completedMethodInfo == null) {
throw new ArgumentNullException("completedMethodInfo");
}
if (String.IsNullOrEmpty(actionName)) {
throw Error.ParameterCannotBeNullOrEmpty("actionName");
}
if (controllerDescriptor == null) {
throw new ArgumentNullException("controllerDescriptor");
}
if (validateMethods) {
string asyncFailedMessage = VerifyActionMethodIsCallable(asyncMethodInfo);
if (asyncFailedMessage != null) {
throw new ArgumentException(asyncFailedMessage, "asyncMethodInfo");
}
string completedFailedMessage = VerifyActionMethodIsCallable(completedMethodInfo);
if (completedFailedMessage != null) {
throw new ArgumentException(completedFailedMessage, "completedMethodInfo");
}
}
AsyncMethodInfo = asyncMethodInfo;
CompletedMethodInfo = completedMethodInfo;
_actionName = actionName;
_controllerDescriptor = controllerDescriptor;
_uniqueId = new Lazy<string>(CreateUniqueId);
}
示例2: TestingContext
static TestingContext()
{
_library = new Lazy<FixtureLibrary>(() =>
{
try
{
var fixture = new SentenceFixture();
var library = FixtureLibrary.CreateForAppDomain(new GrammarSystem().Start());
// Need to force it to use this one instead of the FactFixture in the samples project
var factFixture = new StoryTeller.Testing.EndToEndExecution.FactFixture();
library.Models["Fact"] = factFixture.Compile(CellHandling.Basic());
library.Fixtures["Fact"] = factFixture;
return library;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
throw;
}
});
}
示例3: PartPresenter
public PartPresenter(PartPresenterView view, IUnityContainer container)
{
_container = container;
View = view;
View.DataContext = this;
_regionManager = new RegionManager();
RegionManager.SetRegionManager(View, _regionManager);
_addPartCommand = new Lazy<DelegateCommand<object>>(() => new DelegateCommand<object>(AddPartExecuted));
Action<int> add = (i) =>
{
var region = _regionManager.Regions["Page1Content" + i];
if (region.Views.Count() == 0)
{
var partView = _container.Resolve<PartView>();
region.Add(partView);
region.Activate(partView);
}
};
add(1);
add(2);
add(3);
}
示例4: ConstructorMap
public ConstructorMap(ConstructorInfo ctor, IEnumerable<ConstructorParameterMap> ctorParams)
{
Ctor = ctor;
CtorParams = ctorParams;
_runtimeCtor = new Lazy<LateBoundParamsCtor>(() => DelegateFactory.CreateCtor(ctor, CtorParams));
}
示例5: CrawledPage
public CrawledPage(Uri uri)
: base(uri)
{
_htmlDocument = new Lazy<HtmlDocument>(() => InitializeHtmlAgilityPackDocument() );
_csQueryDocument = new Lazy<CQ>(() => InitializeCsQueryDocument());
Content = new PageContent();
}
示例6: RegisterHubExtensions
private void RegisterHubExtensions()
{
var methodDescriptorProvider = new Lazy<ReflectedMethodDescriptorProvider>();
Register(typeof(IMethodDescriptorProvider), () => methodDescriptorProvider.Value);
var hubDescriptorProvider = new Lazy<ReflectedHubDescriptorProvider>(() => new ReflectedHubDescriptorProvider(this));
Register(typeof(IHubDescriptorProvider), () => hubDescriptorProvider.Value);
var parameterBinder = new Lazy<DefaultParameterResolver>();
Register(typeof(IParameterResolver), () => parameterBinder.Value);
var activator = new Lazy<DefaultHubActivator>(() => new DefaultHubActivator(this));
Register(typeof(IHubActivator), () => activator.Value);
var hubManager = new Lazy<DefaultHubManager>(() => new DefaultHubManager(this));
Register(typeof(IHubManager), () => hubManager.Value);
var proxyGenerator = new Lazy<DefaultJavaScriptProxyGenerator>(() => new DefaultJavaScriptProxyGenerator(this));
Register(typeof(IJavaScriptProxyGenerator), () => proxyGenerator.Value);
var requestParser = new Lazy<HubRequestParser>();
Register(typeof(IHubRequestParser), () => requestParser.Value);
var assemblyLocator = new Lazy<DefaultAssemblyLocator>(() => new DefaultAssemblyLocator());
Register(typeof(IAssemblyLocator), () => assemblyLocator.Value);
// Setup the default hub pipeline
var dispatcher = new Lazy<IHubPipeline>(() => new HubPipeline().AddModule(new AuthorizeModule()));
Register(typeof(IHubPipeline), () => dispatcher.Value);
Register(typeof(IHubPipelineInvoker), () => dispatcher.Value);
}
示例7: ProductionQueueFromSelection
public ProductionQueueFromSelection(World world, ProductionQueueFromSelectionInfo info)
{
this.world = world;
tabsWidget = new Lazy<ProductionTabsWidget>(() =>
Widget.RootWidget.GetWidget<ProductionTabsWidget>(info.ProductionTabsWidget));
}
示例8: ApplicationVersionContextInitializer
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationVersionContextInitializer" /> class.
/// </summary>
/// <param name="applicationVersion">The application version. If null, calculated from <see cref="Assembly.GetEntryAssembly"/>.</param>
public ApplicationVersionContextInitializer(string applicationVersion = null)
{
_applicationVersion = new Lazy<string>(() =>
String.IsNullOrWhiteSpace(applicationVersion)
? (Assembly.GetEntryAssembly()?.ToString() ?? Assembly.GetExecutingAssembly().ToString())
: applicationVersion);
}
示例9: Chapter
public Chapter()
{
pagesUrl = new Lazy<IEnumerable<Page>>(() =>
{
var content = Utility.GetContent(Uri);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(content);
List<Page> pages = new List<Page>();
doc.DocumentNode
.SelectNodes("//select[@id=\"pageMenu\"]//option")
.ToList()
.ForEach(p =>
{
Page page = new Page
{
ChapterName = Title,
ChapterNumber = Number,
PageNumber = Convert.ToInt32(p.NextSibling.InnerText),
Uri = MangaPanda.BaseUrl + p.Attributes["value"].Value
};
pages.Add(page);
});
return pages;
});
}
示例10: AbpNHibernateInterceptor
public AbpNHibernateInterceptor(IIocManager iocManager)
{
_iocManager = iocManager;
_abpSession =
new Lazy<IAbpSession>(
() => _iocManager.IsRegistered(typeof(IAbpSession))
? _iocManager.Resolve<IAbpSession>()
: NullAbpSession.Instance,
isThreadSafe: true
);
_guidGenerator =
new Lazy<IGuidGenerator>(
() => _iocManager.IsRegistered(typeof(IGuidGenerator))
? _iocManager.Resolve<IGuidGenerator>()
: SequentialGuidGenerator.Instance,
isThreadSafe: true
);
_eventBus =
new Lazy<IEventBus>(
() => _iocManager.IsRegistered(typeof(IEventBus))
? _iocManager.Resolve<IEventBus>()
: NullEventBus.Instance,
isThreadSafe: true
);
}
示例11: UseRedis
/// <summary>
/// Use Redis as the messaging backplane for scaling out of ASP.NET SignalR applications in a web farm.
/// </summary>
/// <param name="resolver">The dependency resolver</param>
/// <param name="configuration">The Redis scale-out configuration options.</param>
/// <returns>The dependency resolver.</returns>
public static IDependencyResolver UseRedis(this IDependencyResolver resolver, RedisScaleoutConfiguration configuration)
{
var bus = new Lazy<RedisMessageBus>(() => new RedisMessageBus(resolver, configuration, new RedisConnection()));
resolver.Register(typeof(IMessageBus), () => bus.Value);
return resolver;
}
示例12: WebWorkContext
public WebWorkContext(Func<string, ICacheManager> cacheManager,
HttpContextBase httpContext,
ICustomerService customerService,
IStoreContext storeContext,
IAuthenticationService authenticationService,
ILanguageService languageService,
ICurrencyService currencyService,
IGenericAttributeService attrService,
TaxSettings taxSettings, CurrencySettings currencySettings,
LocalizationSettings localizationSettings, Lazy<ITaxService> taxService,
IStoreService storeService, ISettingService settingService,
IUserAgent userAgent)
{
this._cacheManager = cacheManager("static");
this._httpContext = httpContext;
this._customerService = customerService;
this._storeContext = storeContext;
this._authenticationService = authenticationService;
this._languageService = languageService;
this._attrService = attrService;
this._currencyService = currencyService;
this._taxSettings = taxSettings;
this._taxService = taxService;
this._currencySettings = currencySettings;
this._localizationSettings = localizationSettings;
this._storeService = storeService;
this._settingService = settingService;
this._userAgent = userAgent;
}
示例13: ExecuteCommand
private static void ExecuteCommand(CommandType command, DirectoryInfo baseDirectory, Lazy<Uri> url, string userName, string password)
{
var engine = Engine.CreateStandard(baseDirectory);
switch (command)
{
case CommandType.Help:
break;
case CommandType.Generate:
var generatedDocuments = engine.Generate();
foreach (var generatedDocument in generatedDocuments)
{
System.Console.WriteLine(generatedDocument);
System.Console.WriteLine();
}
break;
case CommandType.Check:
var haveChanged =
engine.CheckIfChanged(url.Value, userName, password);
System.Console.WriteLine(haveChanged? "Changed": "Have not changed");
break;
case CommandType.Push:
engine.PushIfChanged(url.Value, userName, password);
break;
case CommandType.Purge:
engine.PurgeDatabase(url.Value, userName, password);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
示例14: ProductionPaletteWidget
public ProductionPaletteWidget([ObjectCreator.Param] World world,
[ObjectCreator.Param] WorldRenderer worldRenderer)
{
this.world = world;
this.worldRenderer = worldRenderer;
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
cantBuild = new Animation("clock");
cantBuild.PlayFetchIndex("idle", () => 0);
clock = new Animation("clock");
iconSprites = Rules.Info.Values
.Where(u => u.Traits.Contains<BuildableInfo>() && u.Name[0] != '^')
.ToDictionary(
u => u.Name,
u => Game.modData.SpriteLoader.LoadAllSprites(
u.Traits.Get<TooltipInfo>().Icon ?? (u.Name + "icon"))[0]);
overlayFont = Game.Renderer.Fonts["TinyBold"];
holdOffset = new float2(32,24) - overlayFont.Measure("On Hold") / 2;
readyOffset = new float2(32,24) - overlayFont.Measure("Ready") / 2;
timeOffset = new float2(32,24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
queuedOffset = new float2(4,2);
}
示例15: ConfigSource
public ConfigSource(FubuRegistry provenance, IConfigurationAction action)
{
_provenance = provenance;
_action = action;
Id = Guid.NewGuid();
_description = new Lazy<Description>(() => Description.For(action));
}