Пример #1
0
 public virtual ConstructorSpec GetTypeConstructor(Type type)
 {
     return
         (type.GetConstructors().OrderByDescending(x => x.GetParameters().Length).Select(
              x => ConstructorSpec.FromConstructorInfo(x, defaultFactory: () => null)).FirstOrDefault(
              x => x != null));
 }
Пример #2
0
        public override ConstructorSpec LoadConstructor(TypeSpec typeSpec)
        {
            var ria = typeSpec.DeclaredAttributes.OfType <ResourceInfoAttribute>().FirstOrDefault();

            if (ria == null)
            {
                return(typeSpec.OnLoadConstructor() ??
                       ConstructorSpec.FromConstructorInfo(
                           typeSpec.Type.GetConstructors(BindingFlags.Instance | BindingFlags.Public
                                                         | BindingFlags.NonPublic).First(),
                           defaultFactory: () => null));
            }

            if (ria.PocoType == null)
            {
                throw new NotSupportedException();
            }

            return(ConstructorSpec.FromConstructorInfo(
                       ria.PocoType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic
                                                    | BindingFlags.Public).First(),
                       ria.InterfaceType));
        }
Пример #3
0
        public void FromConstructorInfo_ReturnsCorrectConstructorSpec()
        {
            var cspec = ConstructorSpec.FromConstructorInfo(typeof(Inherited).GetConstructors().First());

            AssertConstructorSpecWithFiveArguments(cspec);
        }