Ejemplo n.º 1
0
    private EventModuleData ReadEventModuleData(CodeTypeDelegate eventDelegate, CodeMemberEvent eventField)
    {
        EventModuleData data = new EventModuleData();

        data.name       = eventField.Name;
        data.returnType = eventDelegate.ReturnType.BaseType;
        data.paramTypes = new string[eventDelegate.Parameters.Count];
        for (int i = 0; i < eventDelegate.Parameters.Count; i++)
        {
            data.paramTypes[i] = eventDelegate.Parameters[i].Type.BaseType;
        }
        if (eventField.Comments.Count > 0)
        {
            data.comment = eventField.Comments[0].Comment.Text;
        }
        return(data);
    }
Ejemplo n.º 2
0
    private void AddEventModule(CodeTypeDeclaration targetClass, EventModuleData data)
    {
        string capitalizedName = CapitalizeString(data.name);
        string delegateName    = capitalizedName + "Delegate";

        CodeTypeDelegate delegateField = new CodeTypeDelegate(delegateName);

        delegateField.Attributes = MemberAttributes.Public;
        delegateField.ReturnType = new CodeTypeReference(data.returnType);
        for (int i = 0; i < data.paramTypes.Length; i++)
        {
            delegateField.Parameters.Add(new CodeParameterDeclarationExpression(data.paramTypes[i], "a" + i));
        }

        CodeMemberEvent eventField = new CodeMemberEvent();

        eventField.Attributes = MemberAttributes.Public;
        eventField.Name       = data.name;
        eventField.Type       = new CodeTypeReference(delegateName);

        targetClass.Members.Add(delegateField);
        targetClass.Members.Add(eventField);
    }