本文整理汇总了C#中IServiceProvider.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.Get方法的具体用法?C# IServiceProvider.Get怎么用?C# IServiceProvider.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.Get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProvideValue
public override object ProvideValue( IServiceProvider serviceProvider )
{
var designMode = DesignerProperties.GetIsInDesignMode( DependencyObject.Value );
try
{
// Retrieve target information
var service = serviceProvider.Get<IProvideValueTarget>();
if ( service?.TargetObject != null )
{
// In a template the TargetObject is a SharedDp (internal WPF class)
// In that case, the markup extension itself is returned to be re-evaluated later
switch ( service.TargetObject.GetType().FullName )
{
case "System.Windows.SharedDp":
return this;
default:
var property = factory( serviceProvider );
if ( property != null )
{
var value = designMode ? designTimeFactory( property.Reference.PropertyType ) : GetValue( new MarkupServiceProvider( serviceProvider, service.TargetObject, property ) );
var result = service.TargetProperty == null ? property.SetValue( value ) : value;
return result;
}
break;
}
}
return null;
}
catch ( Exception e )
{
var exception = designMode ? new Exception( e.ToString() ) : e;
throw exception;
}
}
示例2: DetermineContext
protected virtual object DetermineContext( IServiceProvider serviceProvider )
{
var types = Types.Select( serviceProvider.Get<IXamlSchemaContextProvider>().SchemaContext.GetXamlType ).ToArray();
var context = serviceProvider.Get<IAmbientProvider>().GetFirstAmbientValue( types );
return context;
}
示例3: ProvideValue
public override object ProvideValue( IServiceProvider serviceProvider )
{
var result = serviceProvider.Get<IRootObjectProvider>().With( x => x.RootObject.GetType().Assembly.GetName().Version );
return result;
}
示例4: CreateAssembly
public void CreateAssembly( [Service]IParameterizedSource<Assembly, AssemblyInformation> factory, IServiceProvider container, [Service]Assembly sut )
{
var fromFactory = ApplicationAssembly.Default.Get();
var fromContainer = container.Get<Assembly>();
Assert.Same( fromFactory, fromContainer );
Assert.Same( fromContainer, sut );
var fromProvider = factory.Get( fromFactory );
Assert.NotNull( fromProvider );
var assembly = GetType().Assembly;
Assert.Equal( assembly.From<AssemblyTitleAttribute, string>( attribute => attribute.Title ), fromProvider.Title );
Assert.Equal( assembly.From<AssemblyCompanyAttribute, string>( attribute => attribute.Company ), fromProvider.Company );
Assert.Equal( assembly.From<AssemblyCopyrightAttribute, string>( attribute => attribute.Copyright ), fromProvider.Copyright );
Assert.Equal( assembly.From<DebuggableAttribute, string>( attribute => "DEBUG" ), fromProvider.Configuration );
Assert.Equal( assembly.From<AssemblyDescriptionAttribute, string>( attribute => attribute.Description ), fromProvider.Description );
Assert.Equal( assembly.From<AssemblyProductAttribute, string>( attribute => attribute.Product ), fromProvider.Product );
Assert.Equal( assembly.GetName().Version, fromProvider.Version );
}
示例5: Get
public override IMarkupProperty Get( IServiceProvider parameter )
{
var reference = propertyFactory( parameter );
var result = reference.IsAssigned() ? new CollectionMarkupProperty( (IList)parameter.Get<IProvideValueTarget>().TargetObject, reference ) : null;
return result;
}