static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var injectAttributes = paramInfo.AllAttributes<InjectAttribute>().ToList();
            var injectOptionalAttributes = paramInfo.AllAttributes<InjectOptionalAttribute>().ToList();

            string identifier = null;

            Assert.That(injectAttributes.IsEmpty() || injectOptionalAttributes.IsEmpty(),
                "Found both 'InjectOptional' and 'Inject' attributes on type parameter '{0}' of type '{1}'.  Parameter should only have one or the other.", paramInfo.Name, parentType.Name());

            if (injectAttributes.Any())
            {
                identifier = injectAttributes.Single().Identifier;
            }
            else if (injectOptionalAttributes.Any())
            {
                identifier = injectOptionalAttributes.Single().Identifier;
            }

            return new InjectableInfo(
                injectOptionalAttributes.Any(),
                identifier,
                paramInfo.Name,
                paramInfo.ParameterType,
                parentType,
                null);
        }
예제 #2
0
        static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var identifier = paramInfo.AllAttributes<InjectAttribute>().Select(x => x.Identifier)
                .Concat(paramInfo.AllAttributes<InjectOptionalAttribute>().Select(x => x.Identifier)).FirstOrDefault();

            return new InjectableInfo(
                paramInfo.HasAttribute(typeof(InjectOptionalAttribute)),
                identifier,
                paramInfo.Name,
                paramInfo.ParameterType,
                parentType,
                null);
        }
예제 #3
0
        static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var injectAttributes = paramInfo.AllAttributes<InjectAttributeBase>().ToList();

            Assert.That(injectAttributes.Count <= 1,
                "Found multiple 'Inject' attributes on type parameter '{0}' of type '{1}'.  Parameter should only have one", paramInfo.Name, parentType.Name());

            var injectAttr = injectAttributes.SingleOrDefault();

            string identifier = null;
            bool isOptional = false;
            InjectSources sourceType = InjectSources.Any;

            if (injectAttr != null)
            {
                identifier = injectAttr.Identifier;
                isOptional = injectAttr.IsOptional;
                sourceType = injectAttr.SourceType;
            }

            bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault;

            return new InjectableInfo(
                isOptionalWithADefaultValue || isOptional,
                identifier,
                paramInfo.Name,
                paramInfo.ParameterType,
                parentType,
                null,
                isOptionalWithADefaultValue ? paramInfo.DefaultValue : null,
                sourceType);
        }
        public MetadataPropertyType ToProperty(ParameterInfo pi)
        {
            var propertyAttrs = pi.AllAttributes();
            var property = new MetadataPropertyType
            {
                Name = pi.Name,
                Attributes = ToAttributes(propertyAttrs),
                Type = pi.ParameterType.GetOperationName(),
                IsValueType = pi.ParameterType.IsValueType() ? true : (bool?)null,
                IsSystemType = pi.ParameterType.IsSystemType() ? true : (bool?)null,
                IsEnum = pi.ParameterType.IsEnum() ? true : (bool?)null,
                TypeNamespace = pi.ParameterType.Namespace,
                Description = pi.GetDescription(),
            };

            return property;
        }
예제 #5
0
        public MetadataPropertyType ToProperty(ParameterInfo pi)
        {
            var propertyAttrs = pi.AllAttributes();
            var property = new MetadataPropertyType
            {
                Name = pi.Name,
                Attributes = ToAttributes(propertyAttrs),
                Type = pi.ParameterType.GetOperationName(),
                Description = pi.GetDescription(),
            };

            return property;
        }