@@ -15,7 +15,6 @@ limitations under the License.
15
15
16
16
using Newtonsoft . Json . Linq ;
17
17
using System ;
18
- using System . Reflection ;
19
18
20
19
namespace RosSharp . RosBridgeClient
21
20
{
@@ -25,13 +24,11 @@ namespace RosSharp.RosBridgeClient
25
24
26
25
internal abstract class Communicator
27
26
{
28
- public static string GetRosName < T > ( ) where T : Message
27
+ public static string GetRosName < T > ( ) where T : Message , new ( )
29
28
{
30
- #if ! WINDOWS_UWP
31
- return ( string ) typeof ( T ) . GetField ( "RosMessageName" ) . GetRawConstantValue ( ) ;
32
- #else
33
- return ( string ) typeof ( T ) . GetTypeInfo ( ) . GetDeclaredField ( "RosMessageName" ) . GetValue ( null ) ;
34
- #endif
29
+ string name = new T ( ) . RosMessageName ;
30
+ Output . Log ( name ) ;
31
+ return name ;
35
32
}
36
33
}
37
34
internal abstract class Publisher : Communicator
@@ -47,7 +44,7 @@ internal Unadvertisement Unadvertise()
47
44
}
48
45
}
49
46
50
- internal class Publisher < T > : Publisher where T : Message
47
+ internal class Publisher < T > : Publisher where T : Message , new ( )
51
48
{
52
49
internal override string Id { get ; }
53
50
internal override string Topic { get ; }
@@ -79,7 +76,7 @@ internal Unsubscription Unsubscribe()
79
76
}
80
77
}
81
78
82
- internal class Subscriber < T > : Subscriber where T : Message
79
+ internal class Subscriber < T > : Subscriber where T : Message , new ( )
83
80
{
84
81
internal override string Id { get ; }
85
82
internal override string Topic { get ; }
@@ -113,7 +110,7 @@ internal ServiceUnadvertisement UnadvertiseService()
113
110
}
114
111
}
115
112
116
- internal class ServiceProvider < Tin , Tout > : ServiceProvider where Tin : Message where Tout : Message
113
+ internal class ServiceProvider < Tin , Tout > : ServiceProvider where Tin : Message , new ( ) where Tout : Message
117
114
{
118
115
internal override string Service { get ; }
119
116
internal ServiceCallHandler < Tin , Tout > ServiceCallHandler ;
@@ -125,7 +122,7 @@ internal ServiceProvider(string service, ServiceCallHandler<Tin, Tout> serviceCa
125
122
}
126
123
127
124
internal override Communication Respond ( string id , JToken args = null )
128
- {
125
+ {
129
126
bool isSuccess = ServiceCallHandler . Invoke ( args . ToObject < Tin > ( ) , out Tout result ) ;
130
127
return new ServiceResponse < Tout > ( id , Service , result , isSuccess ) ;
131
128
}
0 commit comments