/// <summary>
		/// Initializes a new instance of the <see cref="EventToGenerate"/> class.
		/// </summary>
		/// <param name="emitter">The emitter.</param>
		/// <param name="addMethod">The add method.</param>
		/// <param name="removeMethod">The remove method.</param>
		/// <param name="attributes">The attributes.</param>
		public EventToGenerate(EventEmitter emitter, MethodInfo addMethod, MethodInfo removeMethod, EventAttributes attributes)
		{
			this.addMethod = addMethod;
			this.removeMethod = removeMethod;
			this.emitter = emitter;
			this.attributes = attributes;
		}
	// Constructor.
	internal EventBuilder(TypeBuilder type, String name,
						  EventAttributes attributes, Type eventType)
			{
				// Validate the parameters.
				if(name == null)
				{
					throw new ArgumentNullException("name");
				}
				else if(eventType == null)
				{
					throw new ArgumentNullException("eventType");
				}

				// Register this item to be detached later.
				type.module.assembly.AddDetach(this);

				// Create the event.
				lock(typeof(AssemblyBuilder))
				{
					this.type = type;
					this.privateData = ClrEventCreate
						(((IClrProgramItem)type).ClrHandle, name,
					 	SignatureHelper.CSToILType(type.module, eventType),
					 	attributes);
				}
			}
		internal EventBuilder(TypeBuilder typeBuilder, string name, EventAttributes attributes, Type eventtype)
		{
			this.typeBuilder = typeBuilder;
			this.name = name;
			this.attributes = attributes;
			this.eventtype = typeBuilder.ModuleBuilder.GetTypeTokenForMemberRef(eventtype);
		}
Example #4
0
        public void DefineEvent(string name, EventAttributes attributes, Type eventType, string expectedName, EventAttributes expectedAttributes)
        {
            TypeBuilder type = Helpers.DynamicType(TypeAttributes.Class | TypeAttributes.Public);
            type.DefineGenericParameters("T");

            EventBuilder eventBuilder = type.DefineEvent(name, attributes, eventType);
            MethodBuilder addOnMethod = type.DefineMethod("addOnMethod", MethodAttributes.Public);
            addOnMethod.GetILGenerator().Emit(OpCodes.Ret);

            MethodBuilder removeOnMethod = type.DefineMethod("removeOnMethod", MethodAttributes.Public);
            removeOnMethod.GetILGenerator().Emit(OpCodes.Ret);

            eventBuilder.SetAddOnMethod(addOnMethod);
            eventBuilder.SetRemoveOnMethod(removeOnMethod);

            Type createdType = type.CreateTypeInfo().AsType();
            Assert.Equal(type.AsType().GetEvents(Helpers.AllFlags), createdType.GetEvents(Helpers.AllFlags));
            Assert.Equal(type.AsType().GetEvent(expectedName, Helpers.AllFlags), createdType.GetEvent(expectedName, Helpers.AllFlags));

            EventInfo eventInfo = createdType.GetEvent(expectedName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            Assert.Equal(expectedName, eventInfo.Name);
            Assert.Equal(createdType, eventInfo.DeclaringType);
            Assert.Equal(expectedAttributes, eventInfo.Attributes);
            Assert.Equal((expectedAttributes & EventAttributes.SpecialName) != 0, eventInfo.IsSpecialName);
            Assert.Null(eventInfo.EventHandlerType);
        }
Example #5
0
#pragma warning restore 169, 414

		internal EventBuilder (TypeBuilder tb, string eventName, EventAttributes eventAttrs, Type eventType) {
			name = eventName;
			attrs = eventAttrs;
			type = eventType;
			typeb = tb;
			table_idx = get_next_table_index (this, 0x14, true);
		}
Example #6
0
		public EventEmitter(AbstractTypeEmitter typeEmitter, string name, EventAttributes attributes, Type type)
		{
			this.typeEmitter = typeEmitter;
			this.type = type;
			this.name = name;
			eventBuilder = typeEmitter.TypeBuilder.DefineEvent(name, attributes, type);
		}
 public EventDefinition(string name, TypeReference eventType,
     EventAttributes attrs)
     : base(name)
 {
     m_eventType = eventType;
     m_attributes = attrs;
 }
        public void GeneralNegativeTest(string name, EventAttributes attrs, Type eventType, Type expected)
        {
            AssemblyName myAsmName =
                new AssemblyName("TypeBuilderGetFieldTest");
            AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(
                myAsmName, AssemblyBuilderAccess.Run);
            ModuleBuilder myModule = TestLibrary.Utilities.GetModuleBuilder(myAssembly, "Module1");


            TypeBuilder myType = myModule.DefineType("Sample",
                TypeAttributes.Class | TypeAttributes.Public);

            string[] typeParamNames = { "T" };
            GenericTypeParameterBuilder[] typeParams =
                myType.DefineGenericParameters(typeParamNames);

            if (expected != null)
            {
                Action test = () =>
                {
                    myType.DefineEvent(name, attrs, eventType);
                    Type t = myType.CreateTypeInfo().AsType();
                };

                Assert.Throws(expected, test);
            }
            else
            {
                Type t1 = myType.CreateTypeInfo().AsType();
            }
        }
Example #9
0
		public EventEmitter(AbstractTypeEmitter typeEmitter, string name, EventAttributes attributes, Type type)
		{
			if (name == null) throw new ArgumentNullException("name");
			if (type == null) throw new ArgumentNullException("type");
			this.typeEmitter = typeEmitter;
			this.type = type;
			eventBuilder = typeEmitter.TypeBuilder.DefineEvent(name, attributes, type);
		}
 internal EventBuilder(ModuleBuilder mod, string name, EventAttributes attr, TypeBuilder type, EventToken evToken)
 {
     this.m_name = name;
     this.m_module = mod;
     this.m_attributes = attr;
     this.m_evToken = evToken;
     this.m_type = type;
 }
Example #11
0
 internal CliMetadataEventLockedTableRow(uint index, byte state, ICliMetadataRoot metadataRoot, EventAttributes flags, uint nameIndex, CliMetadataTypeDefOrRefTag signatureSource, uint signatureTypeIndex)
 {
     this.index              = index;
     this.metadataRoot       = metadataRoot;
     this.state              = state;
     this.flags              = flags;
     this.nameIndex          = nameIndex;
     this.signatureSource    = signatureSource;
     this.signatureTypeIndex = signatureTypeIndex;
 }
Example #12
0
		public EventDefOptions(EventDef evt) {
			this.Attributes = evt.Attributes;
			this.Name = evt.Name;
			this.EventType = evt.EventType;
			this.AddMethod = evt.AddMethod;
			this.InvokeMethod = evt.InvokeMethod;
			this.RemoveMethod = evt.RemoveMethod;
			this.OtherMethods.AddRange(evt.OtherMethods);
			this.CustomAttributes.AddRange(evt.CustomAttributes);
		}
Example #13
0
 public DebuggerEvent(Debugger debugger, CorEvent evt)
 {
     debugger.Dispatcher.VerifyAccess();
     this.debugger   = debugger;
     this.evt        = evt;
     this.hashCode   = evt.GetHashCode();
     this.token      = evt.Token;
     this.name       = evt.GetName() ?? string.Empty;
     this.attributes = evt.GetAttributes();
 }
 public TestableCustomEventInfo(
     CustomType declaringType,
     string name,
     EventAttributes attributes,
     MethodInfo addMethod,
     MethodInfo removeMethod,
     MethodInfo raiseMethod)
     : base(declaringType, name, attributes, addMethod, removeMethod, raiseMethod)
 {
 }
Example #15
0
		public EventDefOptions(EventDef evt) {
			Attributes = evt.Attributes;
			Name = evt.Name;
			EventType = evt.EventType;
			AddMethod = evt.AddMethod;
			InvokeMethod = evt.InvokeMethod;
			RemoveMethod = evt.RemoveMethod;
			OtherMethods.AddRange(evt.OtherMethods);
			CustomAttributes.AddRange(evt.CustomAttributes);
		}
Example #16
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MetaEvent" /> class.
 /// </summary>
 /// <param name = "name">The name.</param>
 /// <param name = "declaringType">Type declaring the original event being overriten, or null.</param>
 /// <param name = "eventDelegateType"></param>
 /// <param name = "adder">The add method.</param>
 /// <param name = "remover">The remove method.</param>
 /// <param name = "attributes">The attributes.</param>
 public MetaEvent(string name, Type declaringType, Type eventDelegateType, MetaMethod adder, MetaMethod remover,
                  EventAttributes attributes)
     : base(declaringType)
 {
     this.name    = name;
     type         = eventDelegateType;
     this.adder   = adder ?? throw new ArgumentNullException("adder");
     this.remover = remover ?? throw new ArgumentNullException("remover");
     Attributes   = attributes;
 }
Example #17
0
        public IEventBuilder DefineEvent(string name, EventAttributes attributes, Type eventtype)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("eventtype", eventtype);

            var emittableEventType = EmittableOperandProvider.GetEmittableType(eventtype);
            var eventBuilder       = _typeBuilder.DefineEvent(name, attributes, emittableEventType);

            return(new EventBuilderDecorator(eventBuilder, EmittableOperandProvider));
        }
        public void VerifyAttributes5()
        {
            EventInfo ei = GetEventInfo(typeof(EventInfoPropertyBaseClass), "EventPublicVirtual");

            Assert.NotNull(ei);
            EventAttributes attr         = ei.Attributes;
            EventAttributes expectedAttr = EventAttributes.None;

            Assert.Equal((object)expectedAttr, (object)attr);
        }
Example #19
0
 void SetFlagValue(EventAttributes flag, bool value)
 {
     if (value)
     {
         Attributes |= flag;
     }
     else
     {
         Attributes &= ~flag;
     }
 }
Example #20
0
        public EventBuilder DefineEvent(string name, EventAttributes attributes, Type eventtype)
        {
            if (events == null)
            {
                events = new List <EventBuilder>();
            }
            EventBuilder eb = new EventBuilder(this, name, attributes, eventtype);

            events.Add(eb);
            return(eb);
        }
Example #21
0
 public EventDefOptions(EventDef evt)
 {
     Attributes   = evt.Attributes;
     Name         = evt.Name;
     EventType    = evt.EventType;
     AddMethod    = evt.AddMethod;
     InvokeMethod = evt.InvokeMethod;
     RemoveMethod = evt.RemoveMethod;
     OtherMethods.AddRange(evt.OtherMethods);
     CustomAttributes.AddRange(evt.CustomAttributes);
 }
Example #22
0
 public EventDefOptions(EventDef evt)
 {
     this.Attributes   = evt.Attributes;
     this.Name         = evt.Name;
     this.EventType    = evt.EventType;
     this.AddMethod    = evt.AddMethod;
     this.InvokeMethod = evt.InvokeMethod;
     this.RemoveMethod = evt.RemoveMethod;
     this.OtherMethods.AddRange(evt.OtherMethods);
     this.CustomAttributes.AddRange(evt.CustomAttributes);
 }
Example #23
0
        public EventEmitter(AbstractTypeEmitter typeEmitter, string name, EventAttributes attributes, Type type)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            this.typeEmitter = typeEmitter;
            this.type        = type ?? throw new ArgumentNullException("type");
            eventBuilder     = typeEmitter.TypeBuilder.DefineEvent(name, attributes, type);
        }
Example #24
0
        public unsafe void GetEventProps(
            int mdToken,
            out void *name,
            out EventAttributes eventAttributes
            )
        {
            void *_name;

            _GetEventProps(m_metadataImport2, mdToken, &_name, out int _eventAttributes);
            name            = _name;
            eventAttributes = (EventAttributes)_eventAttributes;
        }
Example #25
0
        public override sealed void Read()
        {
            if (this.fullyRead)
            {
                return;
            }
            for (uint index = 1; (index <= this.Count); index++)
            {
                bool gotLock = false;
                Monitor.Enter(this.syncObject, ref gotLock);
                if (!(base.ItemLoaded(index)))
                {
                    this.fStream.Seek((this.streamOffset + ((index - 1) * this.__size)), SeekOrigin.Begin);
                    EventAttributes flags = ((EventAttributes)(this.reader.ReadUInt16()));
                    uint            nameIndex;
                    switch (this.state)
                    {
                    case 1:
                    case 3:
                        nameIndex = this.reader.ReadUInt32();
                        break;

                    default:
                        nameIndex = this.reader.ReadUInt16();
                        break;
                    }
                    uint signatureTypeIndex;
                    CliMetadataTypeDefOrRefTag signatureSource;
                    switch (this.state)
                    {
                    case 2:
                    case 3:
                        signatureTypeIndex = this.reader.ReadUInt32();
                        break;

                    default:
                        signatureTypeIndex = this.reader.ReadUInt16();
                        break;
                    }
                    signatureSource    = ((CliMetadataTypeDefOrRefTag)((signatureTypeIndex & 3)));
                    signatureTypeIndex = (signatureTypeIndex >> 2);
                    base.InjectLoadedItem(new CliMetadataEventLockedTableRow(index, this.state, this.metadataRoot,
                                                                             flags, nameIndex, signatureSource,
                                                                             signatureTypeIndex), index);
                }
                if (gotLock)
                {
                    Monitor.Exit(this.syncObject);
                }
            }
            this.fullyRead = true;
        }
        public static MutableEventInfo Create(
            MutableType declaringType = null,
            string name = "UnspecifiedEvent",
            EventAttributes attributes     = EventAttributes.None,
            MutableMethodInfo addMethod    = null,
            MutableMethodInfo removeMethod = null,
            MutableMethodInfo raiseMethod  = null)
        {
            Assertion.IsTrue(addMethod != null && removeMethod != null);
            declaringType = declaringType ?? MutableTypeObjectMother.Create();

            return(new MutableEventInfo(declaringType, name, attributes, addMethod, removeMethod, raiseMethod));
        }
Example #27
0
 // Define an event for this class.
 public EventBuilder DefineEvent
     (String name, EventAttributes attributes, Type eventType)
 {
     try
     {
         StartSync();
         return(new EventBuilder(this, name, attributes, eventType));
     }
     finally
     {
         EndSync();
     }
 }
Example #28
0
 // Constructs a EventBuilder.
 //
 internal EventBuilder(
     ModuleBuilder mod,              // the module containing this EventBuilder
     String name,                    // Event name
     EventAttributes attr,           // event attribute such as Public, Private, and Protected defined above
                                     //int            eventType,                // event type
     TypeBuilder type,               // containing type
     EventToken evToken)
 {
     m_name       = name;
     m_module     = mod;
     m_attributes = attr;
     m_evToken    = evToken;
     m_type       = type;
 }
Example #29
0
        public MutableEventInfo AddEvent(
            string name, EventAttributes attributes, MutableMethodInfo addMethod, MutableMethodInfo removeMethod, MutableMethodInfo raiseMethod = null)
        {
            ArgumentUtility.CheckNotNullOrEmpty("name", name);
            ArgumentUtility.CheckNotNull("addMethod", addMethod);
            ArgumentUtility.CheckNotNull("removeMethod", removeMethod);
            // Raise method may be null.

            var event_ = _mutableMemberFactory.CreateEvent(this, name, attributes, addMethod, removeMethod, raiseMethod);

            _addedEvents.Add(event_);

            return(event_);
        }
     // Constructs a EventBuilder.  
 	//
     internal EventBuilder(
 		Module			mod,					// the module containing this EventBuilder		
 		String			name,					// Event name
 		EventAttributes attr,					// event attribute such as Public, Private, and Protected defined above
 		int				eventType,				// event type
 		TypeBuilder     type,                   // containing type
         EventToken		evToken)
     {   		
         m_name = name;
         m_module = mod;
         m_attributes = attr;
 		m_evToken = evToken;
         m_type = type;
     }
        /// <summary>
        /// Initialises a new instance of the EventMetadataTableRow class
        /// </summary>
        /// <param name="contents">The contents of the file</param>
        /// <param name="offset">The offset of the current row</param>
        public EventMetadataTableRow(byte[] contents, Offset offset, ICodedIndexResolver resolver, IIndexDetails indexDetails)
        {
            this.FileOffset = offset;

            int  typeDefOrRefIndexSize = resolver.GetSizeOfIndex(CodedIndexes.TypeDefOrRef);
            byte sizeOfStringIndex     = indexDetails.GetSizeOfStringIndex();

            _eventFlags     = (EventAttributes)BitConverter.ToUInt16(contents, offset.Shift(2));
            _nameIndex      = new StringIndex(contents, sizeOfStringIndex, offset);
            _eventTypeIndex = resolver.Resolve(
                CodedIndexes.TypeDefOrRef,
                FieldReader.ToUInt32(contents, offset.Shift(typeDefOrRefIndexSize), typeDefOrRefIndexSize)
                );
        }
Example #32
0
        public EventMetadata(
             EventInfo eventInfo,
            MethodMetadata addHandlerMethod,
            MethodMetadata removeHandlerMethod,
            MethodMetadata raiseHandlerMethod)
            : base(eventInfo)
        {
            _eventInfo = eventInfo;
            _addHandlerMethod = addHandlerMethod;
            _removeHandlerMethod = removeHandlerMethod;
            _raiseHandlerMethod = raiseHandlerMethod;

            _eventAttributes = _eventInfo.Attributes;
        }
Example #33
0
 internal EventBuilder(
     TypeBuilder declaringType,
     string name,
     EventAttributes attrs,
     StringHandle nameHandle,
     EntityHandle eventTypeHandle
     )
 {
     m_declType        = declaringType;
     m_name            = name;
     m_attrs           = attrs;
     m_nameHandle      = nameHandle;
     m_eventTypeHandle = eventTypeHandle;
 }
Example #34
0
        public void SetUp()
        {
            _publicAddMethod       = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.PublicAddMethod(null));
            _publicRemoveMethod    = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.PublicRemoveMethod(null));
            _publicRaiseMethod     = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.PublicRaiseMethod("", 7));
            _nonPublicAddMethod    = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.NonPublicAddMethod(null));
            _nonPublicRemoveMethod = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.NonPublicRemoveMethod(null));
            _nonPublicRaiseMethod  = NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.NonPublicRaiseMethod("", 7));

            _declaringType = CustomTypeObjectMother.Create();
            _name          = "Event";
            _attributes    = (EventAttributes)7;

            _event = new TestableCustomEventInfo(_declaringType, _name, _attributes, _publicAddMethod, _publicRemoveMethod, _publicRaiseMethod);
        }
Example #35
0
 public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
 {
     if (customBuilder.KnownCA == KnownCA.SpecialNameAttribute)
     {
         attributes |= EventAttributes.SpecialName;
     }
     else
     {
         if (lazyPseudoToken == 0)
         {
             lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
         }
         typeBuilder.ModuleBuilder.SetCustomAttribute(lazyPseudoToken, customBuilder);
     }
 }
Example #36
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MetaEvent" /> class.
 /// </summary>
 /// <param name = "event">The event.</param>
 /// <param name = "adder">The add method.</param>
 /// <param name = "remover">The remove method.</param>
 /// <param name = "attributes">The attributes.</param>
 public MetaEvent(EventInfo @event, MetaMethod adder, MetaMethod remover, EventAttributes attributes)
     : base(@event)
 {
     if (adder == null)
     {
         throw new ArgumentNullException(nameof(adder));
     }
     if (remover == null)
     {
         throw new ArgumentNullException(nameof(remover));
     }
     this.adder   = adder;
     this.remover = remover;
     Attributes   = attributes;
 }
Example #37
0
        protected override sealed ICliMetadataEventTableRow ReadElementAt(uint index)
        {
            bool gotLock = false;

            Monitor.Enter(this.syncObject, ref gotLock);
            if (index == 0)
            {
                return(null);
            }
            this.fStream.Seek((this.streamOffset + ((index - 1) * this.__size)), SeekOrigin.Begin);
            EventAttributes flags = ((EventAttributes)(this.reader.ReadUInt16()));
            uint            nameIndex;

            switch (this.state)
            {
            case 1:
            case 3:
                nameIndex = this.reader.ReadUInt32();
                break;

            default:
                nameIndex = this.reader.ReadUInt16();
                break;
            }
            uint signatureTypeIndex;
            CliMetadataTypeDefOrRefTag signatureSource;

            switch (this.state)
            {
            case 2:
            case 3:
                signatureTypeIndex = this.reader.ReadUInt32();
                break;

            default:
                signatureTypeIndex = this.reader.ReadUInt16();
                break;
            }
            signatureSource    = ((CliMetadataTypeDefOrRefTag)((signatureTypeIndex & 3)));
            signatureTypeIndex = (signatureTypeIndex >> 2);
            if (gotLock)
            {
                Monitor.Exit(this.syncObject);
            }
            return(new CliMetadataEventLockedTableRow(index, this.state, this.metadataRoot,
                                                      flags, nameIndex, signatureSource,
                                                      signatureTypeIndex));
        }
        public static bool AppendEventAttributes(StringBuilder sb, EventAttributes attributes, bool all = true)
        {
            List <string> list = new List <string>();

            if ((attributes & EventAttributes.SpecialName) != 0)
            {
                list.Add("specialname");
            }
            if ((attributes & EventAttributes.RTSpecialName) != 0)
            {
                list.Add("rtspecialname");
            }

            sb.Append(list.Join(" "));
            return(list.Count > 0);
        }
Example #39
0
		public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
		{
			Universe u = typeBuilder.ModuleBuilder.universe;
			if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
			{
				attributes |= EventAttributes.SpecialName;
			}
			else
			{
				if (lazyPseudoToken == 0)
				{
					lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
				}
				typeBuilder.ModuleBuilder.SetCustomAttribute(lazyPseudoToken, customBuilder);
			}
		}
Example #40
0
        public static MutableEventInfo AddEvent2(
            this MutableType mutableType,
            string name = null,
            EventAttributes attributes     = EventAttributes.None,
            MutableMethodInfo addMethod    = null,
            MutableMethodInfo removeMethod = null,
            MutableMethodInfo raiseMethod  = null)
        {
            name = name ?? "Event_" + ++s_counter;
            var handlerMethod = addMethod ?? removeMethod;
            var handlerType   = handlerMethod != null?handlerMethod.GetParameters().Single().ParameterType : typeof(Action);

            addMethod    = addMethod ?? MutableMethodInfoObjectMother.Create(mutableType, "Adder", parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });
            removeMethod = removeMethod ?? MutableMethodInfoObjectMother.Create(mutableType, "Adder", parameters: new[] { ParameterDeclarationObjectMother.Create(handlerType) });

            return(mutableType.AddEvent(name, attributes, addMethod, removeMethod, raiseMethod));
        }
Example #41
0
        public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
        {
            Universe u = typeBuilder.ModuleBuilder.universe;

            if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
            {
                attributes |= EventAttributes.SpecialName;
            }
            else
            {
                if (lazyPseudoToken == 0)
                {
                    lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
                }
                typeBuilder.ModuleBuilder.SetCustomAttribute(lazyPseudoToken, customBuilder);
            }
        }
Example #42
0
        static EventAttributes MigrateEventStateToAttributes(VisualEffectActivationBehaviour.EventState[] eventStates)
        {
            EventAttributes eventAttributes = new EventAttributes();

            if (eventStates == null)
            {
                return(eventAttributes);
            }

            if (eventStates.Length == 0)
            {
                return(eventAttributes);
            }

            eventAttributes.content = eventStates.Select(o => MigrateEventStateToAttributes(o)).ToArray();
            return(eventAttributes);
        }
Example #43
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MetaEvent" /> class.
 /// </summary>
 /// <param name = "name">The name.</param>
 /// <param name = "declaringType">Type declaring the original event being overridden, or null.</param>
 /// <param name = "eventDelegateType">The event delegate type.</param>
 /// <param name = "adder">The add method.</param>
 /// <param name = "remover">The remove method.</param>
 /// <param name = "attributes">The attributes.</param>
 public MetaEvent(string name, Type declaringType, Type eventDelegateType, MetaMethod adder, MetaMethod remover,
                  EventAttributes attributes)
     : base(declaringType)
 {
     if (adder == null)
     {
         throw new ArgumentNullException(nameof(adder));
     }
     if (remover == null)
     {
         throw new ArgumentNullException(nameof(remover));
     }
     this.name    = name;
     type         = eventDelegateType;
     this.adder   = adder;
     this.remover = remover;
     Attributes   = attributes;
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref = "MetaEvent" /> class.
 /// </summary>
 /// <param name = "name">The name.</param>
 /// <param name = "declaringType">Type declaring the original event being overriten, or null.</param>
 /// <param name = "eventDelegateType"></param>
 /// <param name = "adder">The add method.</param>
 /// <param name = "remover">The remove method.</param>
 /// <param name = "attributes">The attributes.</param>
 public MetaEvent(EventInfo @event, MetaMethod adder, MetaMethod remover,
                  EventAttributes attributes)
     : base(@event.DeclaringType)
 {
     if (adder == null)
     {
         throw new ArgumentNullException("adder");
     }
     if (remover == null)
     {
         throw new ArgumentNullException("remover");
     }
     this.Event   = @event;
     this.name    = @event.Name;
     type         = @event.EventHandlerType;
     this.adder   = adder;
     this.remover = remover;
     Attributes   = attributes;
 }
Example #45
0
        public static CustomEventInfo Create(
            CustomType declaringType = null,
            string name = "Event",
            EventAttributes attributes = (EventAttributes)7,
            MethodInfo addMethod       = null,
            MethodInfo removeMethod    = null,
            MethodInfo raiseMethod     = null,
            IEnumerable <ICustomAttributeData> customAttributes = null)
        {
            declaringType = declaringType ?? CustomTypeObjectMother.Create();
            addMethod     = addMethod ?? NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.AddMethod(null));
            removeMethod  = removeMethod ?? NormalizingMemberInfoFromExpressionUtility.GetMethod((DomainType o) => o.RemoveMethod(null));
            // Raise method stays null.
            customAttributes = customAttributes ?? new ICustomAttributeData[0];

            return(new TestableCustomEventInfo(declaringType, name, attributes, addMethod, removeMethod, raiseMethod)
            {
                CustomAttributeDatas = customAttributes
            });
        }
Example #46
0
        public ApiTypeBuilder Event(string name, Type eventType, EventAttributes attributes = EventAttributes.None, bool @static = false)
        {
            EventBuilder eventBuilder = _typeBuilder.DefineEvent(name, attributes, eventType);

              MethodBuilder addMethodBuilder = _typeBuilder.DefineMethod(string.Format("add_{0}", name),
            @static ? MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Static :
            MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Virtual
            , null, new[] { eventType });
              addMethodBuilder.GetILGenerator().Emit(OpCodes.Ret);

              MethodBuilder removeMethodBuilder = _typeBuilder.DefineMethod(string.Format("remove_{0}", name),
            @static ? MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Static :
            MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Virtual
            , null, new[] { eventType });
              removeMethodBuilder.GetILGenerator().Emit(OpCodes.Ret);

              eventBuilder.SetAddOnMethod(addMethodBuilder);
              eventBuilder.SetRemoveOnMethod(removeMethodBuilder);
              return this;
        }
Example #47
0
		public EventBuilder DefineEvent(string name, EventAttributes attributes, Type eventtype)
		{
			if (events == null)
			{
				events = new List<EventBuilder>();
			}
			EventBuilder eb = new EventBuilder(this, name, attributes, eventtype);
			events.Add(eb);
			return eb;
		}
Example #48
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="name">Name</param>
		/// <param name="type">Type</param>
		/// <param name="flags">Flags</param>
		public EventDefUser(UTF8String name, ITypeDefOrRef type, EventAttributes flags) {
			this.name = name;
			this.eventType = type;
			this.attributes = (int)flags;
		}
Example #49
0
		/// <summary>
		/// Set or clear flags in <see cref="attributes"/>
		/// </summary>
		/// <param name="set"><c>true</c> if flags should be set, <c>false</c> if flags should
		/// be cleared</param>
		/// <param name="flags">Flags to set or clear</param>
		void ModifyAttributes(bool set, EventAttributes flags) {
#if THREAD_SAFE
			int origVal, newVal;
			do {
				origVal = attributes;
				if (set)
					newVal = origVal | (int)flags;
				else
					newVal = origVal & ~(int)flags;
			} while (Interlocked.CompareExchange(ref attributes, newVal, origVal) != origVal);
#else
			if (set)
				attributes |= (int)flags;
			else
				attributes &= ~(int)flags;
#endif
		}
Example #50
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventRow"/> struct.
 /// </summary>
 /// <param name="flags">The flags.</param>
 /// <param name="name">The name.</param>
 /// <param name="eventType">Type of the event.</param>
 public EventRow(EventAttributes flags, HeapIndexToken name, Token eventType)
 {
     this.flags = flags;
     this.name = name;
     this.eventType = eventType;
 }
Example #51
0
 internal static extern int DefineEvent(RuntimeModule module, int tkParent, String name, EventAttributes attributes, int tkEventType);
Example #52
0
		public EventBuilder DefineEvent (string name, EventAttributes attributes, Type eventtype)
		{
			check_name ("name", name);
			if (eventtype == null)
				throw new ArgumentNullException ("type");
			check_not_created ();

			EventBuilder res = new EventBuilder (this, name, attributes, eventtype);
			if (events != null) {
				EventBuilder[] new_events = new EventBuilder [events.Length+1];
				System.Array.Copy (events, new_events, events.Length);
				new_events [events.Length] = res;
				events = new_events;
			} else {
				events = new EventBuilder [1];
				events [0] = res;
			}
			return res;
		}
Example #53
0
 [System.Security.SecuritySafeCritical]  // auto-generated
 public EventBuilder DefineEvent(String name, EventAttributes attributes, Type eventtype)
 {
     lock(SyncRoot)
     {
         return DefineEventNoLock(name, attributes, eventtype);
     }
 }
Example #54
0
 public EventDefinition(string name, EventAttributes attributes, TypeReference eventType)
     : base(name, eventType)
 {
     this.attributes = (ushort) attributes;
     this.token = new MetadataToken (TokenType.Event);
 }
Example #55
0
		public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
			if (customBuilder == null)
				throw new ArgumentNullException ("customBuilder");
			RejectIfCreated ();
			string attrname = customBuilder.Ctor.ReflectedType.FullName;
			if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
				attrs |= EventAttributes.SpecialName;
				return;
			}
			if (cattrs != null) {
				CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
				cattrs.CopyTo (new_array, 0);
				new_array [cattrs.Length] = customBuilder;
				cattrs = new_array;
			} else {
				cattrs = new CustomAttributeBuilder [1];
				cattrs [0] = customBuilder;
			}
		}
        public static bool AppendEventAttributes(StringBuilder sb, EventAttributes attributes, bool all = true)
        {
            List<string> list = new List<string>();

            if ((attributes & EventAttributes.SpecialName) != 0) list.Add("specialname");
            if ((attributes & EventAttributes.RTSpecialName) != 0) list.Add("rtspecialname");

            sb.Append(list.Join(" "));
            return list.Count > 0;
        }
Example #57
0
        public static EventBuilder DefineEvent(this TypeBuilder typeBuilder, EventInfo @event, EventAttributes? attributes = null)
        {
            attributes = attributes ?? @event.Attributes | EventAttributes.None;

            return typeBuilder.DefineEvent(@event.Name, attributes.Value, @event.EventHandlerType);
        }
Example #58
0
        [System.Security.SecurityCritical]  // auto-generated
        private EventBuilder DefineEventNoLock(String name, EventAttributes attributes, Type eventtype)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            if (name.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
            if (name[0] == '\0')
                throw new ArgumentException(Environment.GetResourceString("Argument_IllegalName"), "name");
            Contract.EndContractBlock();

            int tkType;
            EventToken      evToken;
            
            CheckContext(eventtype);

            ThrowIfCreated();

            tkType = m_module.GetTypeTokenInternal( eventtype ).Token;

            // Internal helpers to define property records
            evToken = new EventToken(DefineEvent(
                m_module.GetNativeHandle(),
                m_tdType.Token,
                name,
                attributes,
                tkType));

            // create the property builder now.
            return new EventBuilder(
                    m_module,
                    name,
                    attributes,
                    //tkType,
                    this,
                    evToken);
        }
Example #59
0
 public void AddEvent(EventAttributes attributes, StringHandle name, EntityHandle type)
 {
     _eventTable.Add(new EventRow
     {
         EventFlags = (ushort)attributes,
         Name = name,
         EventType = (uint)CodedIndex.ToTypeDefOrRef(type)
     });
 }
 public EventRow CreateEventRow(EventAttributes _eventFlags, uint _name, MetadataToken _eventType)
 {
     EventRow row = new EventRow ();
     row.EventFlags = _eventFlags;
     row.Name = _name;
     row.EventType = _eventType;
     return row;
 }