Get DataMembers from DLL assembly using System.Reflection

I'm trying to use Assembly class to get [DataMember]'s from my [ServiceContract]. The problem is, my method returns an empty collection...

Here's my code:

Assembly assembly = Assembly.LoadFrom(dllPath);
Type c = assembly.GetType(fullName);
var dataMembers = c.GetFields().Where(f => f.GetCustomAttributes<DataContractFormatAttribute>().Any());

And here's my service class:

public class MyService
    public string Test;

    public Int64 ComeAndGetMe;

    public bool AmIUseless;

    public void DoSomething()

I want to get Test and ComeAndGetMe.


No fields are marked [DataContractFormat], so looking for <DataContractFormatAttribute> will not find anything. Try looking for fields where DataMemberAttribute is specified.

Minor point, but personally I think you should make those properties, not fields (and use GetProperties(), obviously):

public string Test {get;set;}
public long ComeAndGetMe {get;set;}
// etc

Need Your Help

XSLT - How to ignore a sub tag in XML if supertag contains a particular term


I am trying to change my XSLT so that when a super tag in my XML contains a particular word the sub tag is not selected.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.