Beispiel #1
0
        /// <summary>
        /// Create dictionaries for serializable and non-serializable parameters
        /// and put the parameters into the dictionaries
        /// </summary>
        static void CreateAndPopulateDictionaries(ParameterInfo[] pinfos, out bool serArgsFound, out bool nonSerArgsFound)
        {
            // Determine whether any serializable and non-serializable arguments are present
            serArgsFound    = false;
            nonSerArgsFound = false;
            foreach (ParameterInfo pinfo in pinfos)
            {
                if (IsSerializableType(pinfo.ParameterType))
                {
                    serArgsFound = true;
                }
                else
                {
                    nonSerArgsFound = true;
                }
                if (serArgsFound && nonSerArgsFound)
                {
                    break;
                }
            }

            // Generate code for creation of dictionaries for argKeys and argValues (both optional)
            string pattern = Indent3 + "var {0} = new Dictionary<int, object>();";

            if (serArgsFound)
            {
                DCEvHndlrFile.WriteLine(string.Format(pattern, "serArgs"));
            }
            if (nonSerArgsFound)
            {
                DCEvHndlrFile.WriteLine(string.Format(pattern, "nonSerArgs"));
            }

            // Populate serArgs and nonSerArgs dictionaries
            pattern = Indent3 + "{0}[{1}] = {2};";
            for (int i = 0; i < pinfos.Length; i++)
            {
                ParameterInfo pinfo     = pinfos[i];
                string        paramName = GetParamName(pinfo);
                if (IsSerializableType(pinfo.ParameterType))
                {
                    DCEvHndlrFile.WriteLine(string.Format(pattern, "serArgs", i, paramName));
                }
                else
                {
                    DCEvHndlrFile.WriteLine(string.Format(pattern, "nonSerArgs", i, paramName));
                }
            }
        }
Beispiel #2
0
        static void CreateServerEventHandler(MethodInfo minfo, Type type)
        {
            CreateEventHandlerSignature(type.Name, minfo.GetParameters());

            DCEvHndlrFile.WriteLine(Indent2 + "{");

            string eventName      = type.Name;
            string afterEventName = "EventHandler";

            //Searching of second '_' position and deleting characters from the start of a string till the start of event name
            eventName = eventName.Remove(0, eventName.IndexOf("_", 1) + 1);

            //Removing characters following after event name
            eventName = eventName.Remove(eventName.IndexOf(afterEventName), afterEventName.Length);

            DCEvHndlrFile.WriteLine(Indent3 + "string name = \"" + eventName + "\";");

            ParameterInfo[] pinfos = minfo.GetParameters();

            string args;

            if (pinfos.Length != 0)
            {
                // Write a line of code that collects all the arguments into object[] as following:
                // var args = new object[] { arg1, arg2, ..., argn }
                CreateArgsObjectArray(DCEvHndlrFile, Indent3, pinfos);

                args = ", args";
            }
            else
            {
                args = string.Empty;
            }

            DCEvHndlrFile.WriteLine(Indent3 + "EventHandler.CommonEventHandler(name" + args + ");");

            DCEvHndlrFile.WriteLine(Indent2 + "}" + Environment.NewLine);
        }
Beispiel #3
0
 static void CreateEventHandlerSignature(string typeName, ParameterInfo[] pinfos)
 {
     DCEvHndlrFile.Write(Indent2 + "public static void " + typeName + "Impl(");
     CreateMethodArguments(pinfos, true);
     DCEvHndlrFile.WriteLine(")");
 }