Example #1
0
        /// <summary>
        /// Automatically creates a writer for a field
        /// </summary>
        /// <returns>A <see cref="ClassMethod"/></returns>
        private ClassMethod CreateWriter()
        {
            Block block = null;

            switch (Modifier)
            {
            case Modifier.Abstract:
                break;

            case Modifier.Static:
                var qName = new QualifiedName(Definer.Name, BackingFieldName);
                block = new Block(new Assignment(new StaticPropertyRef(qName),
                                                 new VariableRef(WRITER_PARAMETER_NAME)),
                                  new Return());
                break;

            default:
                block = new Block(new Assignment(PropertyRef.This(BackingFieldName),
                                                 new VariableRef(WRITER_PARAMETER_NAME)),
                                  new Return());
                break;
            }

            var function = new Function(new[] { new Parameter(WRITER_PARAMETER_NAME) }, block);

            return(new ClassMethod(GetWriterName(Name), WriterScope, Modifier, function));
        }
Example #2
0
        /// <summary>
        /// Generates a method to make it easier to unregister handlers for this event.
        /// </summary>
        /// <returns>A <see cref="ClassMethod"/></returns>
        public ClassMethod CreateRemoveHandlerMethod()
        {
            var removeHandlerFunc = new Function(new[] { new Parameter("handler") },
                                                 new Block(new MethodCall(PropertyRef.This(HandlerSetName),
                                                                          "remove",
                                                                          new VariableRef("handler")),
                                                           new Return()));

            return(new ClassMethod(RemoveHandlerName, Scope, Modifier, removeHandlerFunc));
        }
Example #3
0
        /// <summary>
        /// Generates a method to make it easier to trigger this event.
        /// </summary>
        /// <returns>A <see cref="ClassMethod"/></returns>
        /// <remarks>The so generated method is always private</remarks>
        public ClassMethod CreateTriggerEventMethod()
        {
            var arguments = new Expression[Parameters.Length];

            for (int i = 0; i < arguments.Length; ++i)
            {
                arguments[i] = new VariableRef(Parameters[i].Name);
            }

            var triggerEventFunc = new Function(Parameters,
                                                new Block(new ForEachLoop(ForEachLoop.DEFAULT_KEY_NAME,
                                                                          "handler",
                                                                          PropertyRef.This(HandlerSetName),
                                                                          new FunctionCall("handler", arguments)),
                                                          new Return()));

            return(new ClassMethod(TriggerEventName, Scope.Private, Modifier, triggerEventFunc));
        }
Example #4
0
        /// <summary>
        /// Automatically creates a reader for a field
        /// </summary>
        /// <returns>A <see cref="ClassMethod"/></returns>
        private ClassMethod CreateReader()
        {
            Block block = null;

            switch (Modifier)
            {
            case Modifier.Abstract:
                break;

            case Modifier.Static:
                var qName = new QualifiedName(Definer.Name, BackingFieldName);
                block = Block.Return(new StaticPropertyRef(qName));
                break;

            default:
                block = Block.Return(PropertyRef.This(BackingFieldName));
                break;
            }

            var function = new Function(Parameter.EmptyArray, block);

            return(new ClassMethod(GetReaderName(Name), ReaderScope, Modifier, function));
        }