本文整理汇总了C#中CompositionContract.TryUnwrapMetadataConstraint方法的典型用法代码示例。如果您正苦于以下问题:C# CompositionContract.TryUnwrapMetadataConstraint方法的具体用法?C# CompositionContract.TryUnwrapMetadataConstraint怎么用?C# CompositionContract.TryUnwrapMetadataConstraint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompositionContract
的用法示例。
在下文中一共展示了CompositionContract.TryUnwrapMetadataConstraint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetExportDescriptors
/// <summary>
/// <see cref="ILogger"/>生成処理
///
/// https://mef.codeplex.com/wikipage?title=ProgrammingModelExtensions&referringTitle=Documentation
/// </summary>
/// <param name="contract"></param>
/// <param name="descriptorAccessor"></param>
/// <returns></returns>
public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
{
if (contract.ContractType == typeof(ILogger))
{
string value = string.Empty;
CompositionContract unwrap;
contract.TryUnwrapMetadataConstraint("LogType", out value, out unwrap);
string header = string.Format("[{0}] LogExportDescriptorProvider - ", value);
return new ExportDescriptorPromise[]
{
new ExportDescriptorPromise(
contract,
"ConsoleMef2 ILogger",
true,
NoDependencies,
_ => ExportDescriptor.Create((c, o) => new Logger() { Header = header }, NoMetadata)
)
};
}
else
return NoExportDescriptors;
}
示例2: GetExportDescriptors
public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(
CompositionContract contract,
DependencyAccessor dependencyAccessor)
{
if (contract == null) throw new ArgumentNullException("contract");
if (dependencyAccessor == null) throw new ArgumentNullException("dependencyAccessor");
string key;
CompositionContract unwrapped;
if (!contract.TryUnwrapMetadataConstraint(SettingKey, out key, out unwrapped) ||
!unwrapped.Equals(new CompositionContract(unwrapped.ContractType)) ||
!SupportedSettingTypes.Contains(unwrapped.ContractType) ||
!ConfigurationManager.AppSettings.AllKeys.Contains(key))
yield break;
var value = ConfigurationManager.AppSettings.Get(key);
var converted = Convert.ChangeType(value, contract.ContractType);
yield return new ExportDescriptorPromise(
contract,
"System.Configuration.ConfigurationManager.AppSettings",
true,
NoDependencies,
_ => ExportDescriptor.Create((c, o) => converted, NoMetadata));
}
示例3: GetExportDescriptors
public override IEnumerable<ExportDescriptorPromise> GetExportDescriptors(CompositionContract contract, DependencyAccessor descriptorAccessor)
{
if (contract == null) throw new ArgumentNullException("contract");
if (descriptorAccessor == null) throw new ArgumentNullException("descriptorAccessor");
string name;
CompositionContract unwrapped;
var connectionStringSettings = ConfigurationManager.ConnectionStrings.OfType<ConnectionStringSettings>().ToArray();
if (!contract.TryUnwrapMetadataConstraint(NameKey, out name, out unwrapped) ||
!unwrapped.Equals(new CompositionContract(unwrapped.ContractType)) ||
!(unwrapped.ContractType == typeof(string) || typeof(DbConnectionStringBuilder).IsAssignableFrom(unwrapped.ContractType)) ||
!connectionStringSettings.Any(cs => cs.Name == name))
yield break;
var stringValue = connectionStringSettings.Single(cs => cs.Name == name).ConnectionString;
object value = stringValue;
if (contract.ContractType != typeof(string))
{
var stringBuilder = Activator.CreateInstance(contract.ContractType) as DbConnectionStringBuilder;
if (stringBuilder == null) yield break;
stringBuilder.ConnectionString = stringValue;
value = stringBuilder;
}
yield return new ExportDescriptorPromise(
contract,
"System.Configuration.ConfigurationManager.ConnectionStrings",
true,
NoDependencies,
_ => ExportDescriptor.Create((c, o) => value, NoMetadata));
}