public static ContractInfo ParseContractInterface(Type contractInterfaceType) { var memberInfos = new ContractInfo(contractInterfaceType); foreach (var methodInfo in contractInterfaceType.GetMethods()) { if (methodInfo.IsSpecialName) { continue; } var attribute = methodInfo.GetCustomAttribute <TntMessage>(); if (attribute == null) { throw new ContractMemberAttributeMissingException(contractInterfaceType, methodInfo.Name); } memberInfos.ThrowIfAlreadyContainsId(attribute.Id, methodInfo); memberInfos.AddInfo(attribute.Id, methodInfo); } foreach (var propertyInfo in contractInterfaceType.GetProperties()) { var attribute = propertyInfo.GetCustomAttribute <TntMessage>(); if (attribute == null) { throw new ContractMemberAttributeMissingException(contractInterfaceType, propertyInfo.Name); } memberInfos.ThrowIfAlreadyContainsId(attribute.Id, propertyInfo); memberInfos.AddInfo(attribute.Id, propertyInfo); } return(memberInfos); }
public static ContractInfo GetContractMemebers(Type contractType, Type interfaceType) { var contractMemebers = new ContractInfo(interfaceType); foreach (var meth in interfaceType.GetMethods()) { if (meth.IsSpecialName) { continue; } var overrided = ReflectionHelper.GetOverridedMethodOrNull(contractType, meth); if (overrided == null) { continue; } var attribute = Attribute.GetCustomAttribute(meth, typeof(TntMessage)) as TntMessage; if (attribute == null) { throw new ContractMemberAttributeMissingException(interfaceType, meth.Name); } contractMemebers.ThrowIfAlreadyContainsId(attribute.Id, overrided); contractMemebers.AddInfo(attribute.Id, overrided); } foreach (var propertyInfo in interfaceType.GetProperties()) { var attribute = Attribute.GetCustomAttribute( propertyInfo, typeof(TntMessage)) as TntMessage; if (attribute == null) { throw new ContractMemberAttributeMissingException(interfaceType, propertyInfo.Name); } var overrided = ReflectionHelper.GetOverridedPropertyOrNull(contractType, propertyInfo); if (overrided == null) { continue; } contractMemebers.ThrowIfAlreadyContainsId(attribute.Id, overrided); contractMemebers.AddInfo(attribute.Id, overrided); } return(contractMemebers); }