找出Framework 4.0 新增的方法和新增的类(下) (2)

!v3Type.MemberNames.Contains(mi.Name)).ToArray();

result.Add(new TypeMembers() { FullName = v4Type.FullName, MemberNames = v4NewMis.Select(mi => mi.Name).ToList() }); } } } #endregion #region 所有新增的Type List<string> v3TypeFullName = lstOldTypes.Select(tm => tm.FullName).ToList();

Type[] v4NewTypes = v4Types.Where(t => !v3TypeFullName.Contains(t.FullName) &&

!t.IsEnum).ToArray();

foreach (Type v4NewType in v4NewTypes) { result.Add(new TypeMembers() { FullName = v4NewType.FullName, MemberNames = v4NewType.GetMembers().Select(mi => mi.Name).ToList() }); } #endregion return result.OrderBy(tm=>tm.FullName).ToList(); } } }

服务的实现和第一个反射的版本差不多。

Web.config文件绑定代码如下:

<system.serviceModel> <bindings> <wsHttpBinding> <binding name="NewBinding0" maxReceivedMessageSize="65536000" /> </wsHttpBinding> <mexHttpBinding> <binding name="NewBinding1" /> </mexHttpBinding> </bindings> <services> <service behaviorConfiguration="V4WcfService.Service1Behavior" name="V4WcfService.Service1"> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="V4WcfService.IService1"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="NewBinding1" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="V4WcfService.Service1Behavior"> <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false 并删除上面的元数据终结点 --> <serviceMetadata httpGetEnabled="true"/> <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 --> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>

因为默认的maxReceivedMessageSize 65536,所以在后面增加了两个0, 否则会抛出经典的超出范围的异常。

WinForm程序界面如下:

image

后台代码如下:

namespace V4NewLooker { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private List<TypeMembers> NewTypeMembers { get; set; } private void btnSearch_Click(object sender, EventArgs e) { Assembly mscorlibAssembly = typeof(object).Assembly; List<TypeMembers> v3TypeMembers = new List<TypeMembers>(); foreach (Type v4NewType in mscorlibAssembly.GetTypes()) { List<string> memberNames = new List<string>(); MemberInfo[] mis = v4NewType.GetMembers(); foreach (MemberInfo mi in mis) { memberNames.Add(mi.Name); } v3TypeMembers.Add(new TypeMembers() { FullName = v4NewType.FullName, MemberNames = memberNames }); } using (Service1Client client = new Service1Client()) { NewTypeMembers = client.GetNewTypeMember(v3TypeMembers); } List<string> typeNames=new List<string>(); foreach (TypeMembers tm in NewTypeMembers) { typeNames.Add(tm.FullName); } lstBox_Types.DataSource = typeNames; } private void lstBox_Types_SelectedIndexChanged(object sender, EventArgs e) { string fullName = lstBox_Types.SelectedItem.ToString(); foreach (TypeMembers tm in NewTypeMembers) { if (tm.FullName == fullName) { lstBox_Members.DataSource = tm.MemberNames; break; } } } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgwygj.html