Explicit interface on properties

Jan 30, 2009 at 4:39 PM
Edited Jan 30, 2009 at 4:40 PM

It seems that the ReflectionUtils is not taking into account interfaces on public classes where the members are referenced as implicit interfaces.


public
class TempClass : TempInterface
{

   
int TempInterface.TempProperty
   
{
       
get;
       
set;
   
}
   
int TempInterface.TempProperty2
   
{
       
get;
       
set;
   
}

   
public int TempProperty
   
{
       
get;
       
set;
   
}
}

public interface TempInterface
{
   
int TempProperty
   
{
       
get;
       
set;
   
}
   
int TempProperty2     {
       
get;
       
set;
   
}
}


I think we should check if a class implements interfaces, get it's properties, and check if those properties are set to .isFinal to avoid duplicates.

Disclaimer. I just started to try this component out. So I might be doing something completely wrong. But I  did notice if I remove my implicit implementation it seems to work.

 

Jan 30, 2009 at 5:17 PM

I was trying to extend  GetFieldsAndProperties

 

 

 

 

//Add explicit interface members

 

 

 

foreach (var anInterface in type.FindInterfaces((type1, criteria) => true, ""))

 

{

 

var interfaceMapping = type.GetInterfaceMap(anInterface);

 

 

foreach (var targetMethod in interfaceMapping.TargetMethods)

 

{

 

if (targetMethod.IsPrivate)

 

{

targetMembers.Add(targetMethod);

 

//Console.WriteLine("Explicit interface implementation: {0}", info.Name);

 

 

 

 

}

}

}

in combination of


 

 

public static Type GetMemberUnderlyingType(MemberInfo member)

 

{

 

ValidationUtils.ArgumentNotNull(member, "member");

 

 

switch (member.MemberType)

 

{

 

case MemberTypes.Field:

 

 

return ((FieldInfo)member).FieldType;

 

 

case MemberTypes.Property:

 

 

return ((PropertyInfo)member).PropertyType;

 

 

case MemberTypes.Event:

 

 

return ((EventInfo)member).EventHandlerType;

 

 

case MemberTypes.Method:

 

 

//For explicit interface implementations

 

 

return ((MethodInfo) member).ReturnType;

 

 

default:

 

 

throw new ArgumentException("MemberInfo must be if type FieldInfo, PropertyInfo or EventInfo", "member");

 

}

}

 

Although it does not throw an excpetion, I don't get any results. Hope somebody familiar with .NET JSON knows all the integration points.