Пример #1
0
        private static ImportDefinition BuildImportDefinition(Type type, Type metadataViewType, string contractName, ImportCardinality cardinality)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (metadataViewType == null)
            {
                throw new ArgumentNullException(nameof(metadataViewType));
            }

            if (contractName == null)
            {
                throw new ArgumentNullException(nameof(contractName));
            }

            IEnumerable <KeyValuePair <string, Type> > requiredMetadata = CompositionServices.GetRequiredMetadata(metadataViewType);
            IDictionary <string, object?> metadata = CompositionServices.GetImportMetadata(type, null);

            string?requiredTypeIdentity = null;

            if (type != typeof(object))
            {
                requiredTypeIdentity = AttributedModelServices.GetTypeIdentity(type);
            }

            return(new ContractBasedImportDefinition(contractName, requiredTypeIdentity, requiredMetadata, cardinality, false, true, CreationPolicy.Any, metadata));
        }
Пример #2
0
        private static ImportDefinition BuildImportDefinition(Type type, Type metadataViewType, string contractName, ImportCardinality cardinality)
        {
            Assumes.NotNull(type, metadataViewType, contractName);

            IEnumerable <KeyValuePair <string, Type> > requiredMetadata = CompositionServices.GetRequiredMetadata(metadataViewType);

            string requiredTypeIdentity = null;

            if (type != typeof(object))
            {
                requiredTypeIdentity = AttributedModelServices.GetTypeIdentity(type);
            }

            return(new ContractBasedImportDefinition(contractName, requiredTypeIdentity, requiredMetadata, cardinality, false, true, CreationPolicy.Any));
        }