当前位置: 首页>>代码示例>>C#>>正文


C# CompositionContract.TryUnwrapMetadataConstraint方法代码示例

本文整理汇总了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;
        }
开发者ID:yasu-s,项目名称:MEF-Sample,代码行数:33,代码来源:LogExportDescriptorProvider.cs

示例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));
        }
开发者ID:blinds52,项目名称:alt-composition,代码行数:26,代码来源:SettingsExportDescriptorProvider.cs

示例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));
        }
开发者ID:blinds52,项目名称:alt-composition,代码行数:34,代码来源:ConnectionStringsExportDescriptorProvider.cs


注:本文中的CompositionContract.TryUnwrapMetadataConstraint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。