private ServiceDescription BuildInternal(string name, Type interfaceType) { var allInterfaces = GetAllInterfaces(interfaceType).Distinct().ToArray(); var properties = allInterfaces.SelectMany(x => x.GetProperties()).ToArray(); var subinterfaceDescs = new List <ServiceDescription>(); foreach (var propertyInfo in properties) { if (propertyInfo.SetMethod != null) { throw new ArgumentException(string.Format("{0} is not a valid service interface since it has a setter ({1})", interfaceType.Name, propertyInfo.Name)); } subinterfaceDescs.Add(BuildInternal(propertyInfo.Name, propertyInfo.PropertyType)); } var methods = allInterfaces.SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.Instance)) .Where(m => !properties.Any(p => p.GetMethod == m || p.SetMethod == m)); var methodDescs = methods.Select(methodInfo => methodDescriptionBuilder.Build(methodInfo)).ToArray(); return(new ServiceDescription { Type = interfaceType, Name = name, Subservices = subinterfaceDescs, Methods = methodDescs }); }
public void BuildSimple() { var fooDesc = new MethodDescription(); var barDesc = new MethodDescription(); methodDescriptionBuilder.Build(typeof(IFooBar).GetMethod("Foo")).Returns(fooDesc); methodDescriptionBuilder.Build(typeof(IFooBar).GetMethod("Bar")).Returns(barDesc); var desc = builder.Build(typeof(IFooBar)); Assert.That(desc.Type, Is.EqualTo(typeof(IFooBar))); Assert.That(desc.Name, Is.EqualTo("FooBar")); Assert.That(desc.Subservices, Is.Empty); Assert.That(desc.Methods, Is.EquivalentTo(new[] { fooDesc, barDesc })); }