Start a new topic
Solved

Type passed in attribute is turned into Delegate with DuoCode

Getting type via typeof(ITestB) and via typeof(ITestB) as a parameter to attribute results in different results.

The second one results in some weird type, which looks like Delegete type. Anyway, it does not contain any of the properties of Type.


You assistance please. 


Snippet

public class MyAttribute : Attribute
 {
 public Type MyType { get; set; }
 
 public MyAttribute(Type myType)
 {
 Console.WriteLine("MyAttribute - " + myType + " | " + myType.GetType());
 MyType = myType;
 }  }
[MyAttribute(typeof(ITestB))]
 public class TestB : ITestB
 {
 }
Output:
MyAttribute - My.ITestB | System.Type: System.Delegate

Just to clarify:

myType != typeof(ITestB)

when the actual value in myType is ITestB


Also, when executing 

typeof(Sharable.ITestB).GetType())

the result is

System.Type, which is as expected.

Thanks we reproduced this bug and already fixed it in the coming DuoCode 2.2.


Just to let you know in resulted JS instead of

[new MyAttribute.ctor(ITestB)]

should be

[new MyAttribute.ctor($d.typeOf(ITestB))]

I've been able to overcome this with:


public MyAttribute(Type serviceInterface)
 {
#if DUOCODE
 var isValidType = serviceInterface.GetType() == typeof(Type);
 if (isValidType)
 {
 ServiceInterfaceType = (Type)serviceInterface;
 }
 else
 {
 string serviceInterfaceFullName = ((dynamic)serviceInterface).toString(); // In order to overcome DuoCode's bug (the type transformed into Delegate). So just comapre FullName of types instead...
  ServiceInterfaceType = System.Type.GetType(serviceInterfaceFullName);
 }
#else
 ServiceInterfaceType = serviceInterface;
#endif
 }
Login or Signup to post a comment