Example #1
0
        private void BuildEvent(ILConversion conversion, ConvertedTypeDefinitionWithEvents_I converted, EventDefinition eventDefinition)
        {
            var eventAttributes = GetEventAttributes(eventDefinition);

            var eventType = Execution.Types.Ensuring.EnsureToType(conversion, eventDefinition.EventType);

            var builder = converted.TypeBuilder.DefineEvent(eventDefinition.Name, eventAttributes, eventType);

            var entry = new ConvertedEvent()
            {
                Name            = eventDefinition.Name,
                Builder         = builder,
                EventDefinition = eventDefinition
            };

            if (!converted.Events.ByName.TryGetValue(entry.Name, out List <SemanticEventMask_I> propertyList))
            {
                propertyList = new List <SemanticEventMask_I>();

                converted.Events.ByName.Add(entry.Name, propertyList);
            }

            propertyList.Add(entry);

            if (eventDefinition.InvokeMethod != null)
            {
                var invokeMethod = Methods.Getting.GetMethod(converted, eventDefinition.InvokeMethod);

                if (invokeMethod?.UnderlyingMethod == null)
                {
                    throw new System.Exception("Expected an invoke method");
                }

                builder.SetRaiseMethod((MethodBuilder)invokeMethod?.UnderlyingMethod);
            }

            if (eventDefinition.AddMethod != null)
            {
                var addMethod = Methods.Getting.GetMethod(converted, eventDefinition.AddMethod);

                if (addMethod?.UnderlyingMethod == null)
                {
                    throw new System.Exception("Expected an add method");
                }

                builder.SetAddOnMethod((MethodBuilder)addMethod?.UnderlyingMethod);
            }



            if (eventDefinition.RemoveMethod != null)
            {
                var removeMethod = Methods.Getting.GetMethod(converted, eventDefinition.RemoveMethod);

                if (removeMethod?.UnderlyingMethod == null)
                {
                    throw new System.Exception("Expected a remove method");
                }



                builder.SetRemoveOnMethod((MethodBuilder)removeMethod?.UnderlyingMethod);
            }

            CustomAttributes.BuildCustomAttributes(conversion, converted, entry);
        }
        public void BuildCustomAttributes(ILConversion conversion, ConvertedTypeDefinitionWithEvents_I converted, ConvertedEvent entry)
        {
            var eventDefinition = entry.EventDefinition;

            var builders = CreateCustomAttributeList(conversion, eventDefinition.CustomAttributes);

            for (int i = 0; i < builders.Count; i++)
            {
                var builder1 = builders[i];

                entry.Builder.SetCustomAttribute(builder1);
            }
        }