/// <summary> /// /// </summary> /// <param name="callback"></param> /// <param name="eventInfo"></param> private static void GenerateDecription(AddInterfaceMemberCallback callback, EventInfo eventInfo) { Type tDelegate = eventInfo.EventHandlerType; MethodInfo invoke = tDelegate.GetMethod("Invoke"); if (invoke == null) { throw new ApplicationException("Not a delegate."); } if (invoke.ReturnType != typeof(void)) { throw new ApplicationException("Object Event delegate " + eventInfo.Name + " cannot have a return type other than void. Alljoyn doesn't support return type of signals."); } string[] args = new string[3]; args[0] = eventInfo.Name; args[1] = ""; args[2] = ""; ParameterInfo[] parameters = invoke.GetParameters(); for (int i = 0; i < parameters.Length; i++) { args[1] += GetAllJoynCode(parameters[i].ParameterType); args[2] += (i == 0 ? "" : ",") + parameters[i].Name; } Console.WriteLine("ifaceDesc.AddSignal(\"" + args[0] + "\",\"" + args[1] + "\",\"" + args[2] + "\")"); callback(args[0], args[1], null, args[2], 0 /* Signal*/); }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="callback"></param> public static void RegisterMembers(Type type, AddInterfaceMemberCallback callback) { // Parse methods and generate iface descriptions // MethodInfo[] mInfos = type.GetMethods(); foreach (MethodInfo method in mInfos) { object[] attributes = method.GetCustomAttributes(false); foreach (object attribute in attributes) { if (attribute is RemoteMethodAttribute) { GenerateDecription(callback, method); break; } } } // Parse events and generate iface descriptions // EventInfo[] eInfos = type.GetEvents(); foreach (EventInfo objectEvent in eInfos) { object[] attributes = objectEvent.GetCustomAttributes(false); foreach (object attribute in attributes) { if (attribute is RemoteEventAttribute) { GenerateDecription(callback, objectEvent); break; } } } }
/// <summary> /// /// </summary> /// <param name="callback"></param> /// <param name="method"></param> private static void GenerateDecription(AddInterfaceMemberCallback callback, MethodInfo method) { string[] args = new string[4]; args[0] = method.Name; args[1] = ""; args[2] = "" + GetAllJoynCode(method.ReturnType); args[3] = ""; ParameterInfo[] parameters = method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { args[1] += GetAllJoynCode(parameters[i].ParameterType); args[3] += (i == 0 ? "" : ",") + parameters[i].Name; } Console.WriteLine("ifaceDesc.AddMethod(\"" + args[0] + "\",\"" + args[1] + "\",\"" + args[2] + "\",\"" + args[3] + "\")"); callback(args[0], args[1], args[2], args[3], 1 /* Method*/); }