internal override bool Validate(Type type, Collection <String> warnings)
        {
            System.Diagnostics.Contracts.Contract.Assert(type.Assembly.ReflectionOnly && IContractInReflectionLoaderContext.Assembly.ReflectionOnly,
                                                         "Both the type and IContract should be in the ReflectionOnly loader context");

            if (!type.IsMarshalByRef)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustBeMBRO, type.AssemblyQualifiedName));
                return(false);
            }

            //if (!type.Implements(typeofIContract))
            if (!IContractInReflectionLoaderContext.IsAssignableFrom(type))
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustImplementAnAddInContract, type.AssemblyQualifiedName));
                return(false);
            }

            foreach (Type contractInterface in type.GetInterfaces())
            {
                //if (contractInterface.Implements(typeofIContract))
                if (IContractInReflectionLoaderContext.IsAssignableFrom(contractInterface))
                {
                    _contracts.Add(new TypeInfo(contractInterface));
                }
            }
            if (_contracts.Count == 0)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustImplementAnAddInContract, type.AssemblyQualifiedName));
                return(false);
            }

            foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                ParameterInfo[] pars = ctor.GetParameters();
                if (pars.Length != 1)
                {
                    warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterOneUnusableConstructor, type.AssemblyQualifiedName));
                    continue;
                }
                _constructors.Add(new TypeInfo(pars[0].ParameterType));
            }
            if (_constructors.Count == 0)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterNoUsableConstructors, type.AssemblyQualifiedName));
                return(false);
            }
            return(base.Validate(type, warnings));
        }
예제 #2
0
        internal override bool Validate(Type type, Collection <String> warnings)
        {
            //if (!type.Implements(new TypeInfo(typeof(IContract))))
            if (!IContractInReflectionLoaderContext.IsAssignableFrom(type))
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.ContractMustImplementIContract, Name));
                return(false);
            }

            if (!type.IsInterface)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.ContractMustBeInterface, Name));
                return(false);
            }

            return(base.Validate(type, warnings));
        }