Пример #1
0
        public static void AreSame(ReflectionItem expected, ReflectionItem actual)
        {
            switch (expected.ItemType)
            {
                case ReflectionItemType.Property:
                {
                    ReflectionProperty expectedProperty = (ReflectionProperty)expected;
                    ReflectionProperty actualProperty = (ReflectionProperty)actual;

                    ReflectionAssert.AreSame(expectedProperty.UnderlyingGetMethod, actualProperty.UnderlyingGetMethod);
                    ReflectionAssert.AreSame(expectedProperty.UnderlyingSetMethod, actualProperty.UnderlyingSetMethod);
                    return;
                }

                case ReflectionItemType.Parameter:
                {
                    ReflectionParameter expectedParameter = (ReflectionParameter)expected;
                    ReflectionParameter actualParameter = (ReflectionParameter)actual;

                    ReflectionAssert.AreSame(expectedParameter.UnderlyingParameter, actualParameter.UnderlyingParameter);
                    return;
                }

                default:
                {
                    ReflectionMember expectedMember = (ReflectionMember)expected;
                    ReflectionMember actualMember = (ReflectionMember)actual;

                    ReflectionAssert.AreSame(expectedMember.UnderlyingMember, actualMember.UnderlyingMember);
                    return;
                }
            }
        }
Пример #2
0
        private static IAttributedImport GetAttributedImport(ReflectionItem item, ICustomAttributeProvider attributeProvider)
        {
            IAttributedImport[] imports = attributeProvider.GetAttributes<IAttributedImport>(false);

            // For constructor parameters they may not have an ImportAttribute
            if (imports.Length == 0)
            {
                return new ImportAttribute();
            }

            if (imports.Length > 1)
            {
                CompositionTrace.MemberMarkedWithMultipleImportAndImportMany(item);
            }

            // Regardless of how many imports, always return the first one
            return imports[0];
        }
Пример #3
0
        //
        // Import definition creation helpers
        //
        private static AttributedImportDefinitionCreationInfo GetImportDefinitionCreationInfo(ReflectionItem item, ICustomAttributeProvider attributeProvider)
        {
            Assumes.NotNull(item, attributeProvider);

            AttributedImportDefinitionCreationInfo importCreationInfo = new AttributedImportDefinitionCreationInfo();

            IAttributedImport attributedImport = AttributedModelDiscovery.GetAttributedImport(item, attributeProvider);
            ImportType importType = new ImportType(item.ReturnType, attributedImport.Cardinality);

            DisplayDebugWarnings(attributedImport.Cardinality, item, importType);

            importCreationInfo.RequiredMetadata = importType.IsLazy ?
                    CompositionServices.GetRequiredMetadata(importType.LazyType.MetadataViewType) :
                    Enumerable.Empty<string>();
            importCreationInfo.Cardinality = attributedImport.Cardinality;
            importCreationInfo.ContractName = attributedImport.GetContractNameFromImport(importType);
            importCreationInfo.RequiredTypeIdentity = attributedImport.GetTypeIdentityFromImport(importType);
            importCreationInfo.IsRecomposable = (item.ItemType == ReflectionItemType.Parameter) ? false : attributedImport.AllowRecomposition;
            importCreationInfo.RequiredCreationPolicy = attributedImport.RequiredCreationPolicy;

            return importCreationInfo;
        }
Пример #4
0
        private static IAttributedImport GetAttributedImport(ReflectionItem item, ICustomAttributeProvider attributeProvider)
        {
            IAttributedImport[] imports = attributeProvider.GetAttributes<IAttributedImport>(false);

            // For constructor parameters they may not have an ImportAttribute
            if (imports.Length == 0)
            {
                return new ImportAttribute();
            }

            if (imports.Length == 1)
            {
                return imports[0];
            }

            // DiscoveryError (Dev10:602872): This should go through the discovery error reporting when
            // we add a way to report discovery errors properly.
            throw ExceptionBuilder.CreateDiscoveryException(Strings.Discovery_MultipleImportAttributes, item.GetDisplayName());
        }
Пример #5
0
        private static void DisplayDebugWarnings(ImportCardinality cardinality, ReflectionItem item, ImportType importType)
        {
            if ((importType.ElementType == ExportType) || (importType.Type == ExportType))
            {
                System.Diagnostics.Debug.WriteLine(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} : Imports of type Export are no longer supported", item.GetDisplayName()));
            }

            // Output a debug warning if someone is using ImportAttribute where it looks like they might want to use ImportMany
            if (cardinality != ImportCardinality.ZeroOrMore && CollectionServices.GetEnumerableElementType(importType.Type) != null)
            {
                System.Diagnostics.Debug.WriteLine("May want to use ImportMany on " + item.GetDisplayName());
            }
        }
        internal static void MemberMarkedWithMultipleImportAndImportMany(ReflectionItem item)
        {
            Assumes.NotNull(item);

            if (CompositionTraceSource.CanWriteError)
            {
                CompositionTraceSource.WriteError(CompositionTraceId.Discovery_MemberMarkedWithMultipleImportAndImportMany,
                                                  Strings.CompositionTrace_Discovery_MemberMarkedWithMultipleImportAndImportMany,
                                                  item.GetDisplayName());
            }
        }