public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
		}
Esempio n. 2
0
		public EventKey (TypeKey typeKey, string type, string name, EventDefinition eventDefinition)
		{
			this.typeKey = typeKey;
			this.type = type;
			this.name = name;
			this.eventDefinition = eventDefinition;
		}
Esempio n. 3
0
    private void CheckSupport(EventDefinition eventInfo, MethodAttributes methodAttributes)
    {
      EventAttributes eventAttributes = eventInfo.Attributes;

      string warningTemplate = "Event '" + name + "' has unsupported attribute: '{0}'.";

      // in order to reduce output we warn only about important attributes which are not currently
      // supported:

      // EventDefinition properties

      // EventAttributes
      //if ((eventAttributes & EventAttributes.RTSpecialName) != 0) { Logger.Warning(warningTemplate, "RTSpecialName"); }
      //if ((eventAttributes & EventAttributes.SpecialName) != 0) { Logger.Warning(warningTemplate, "SpecialName"); }

      // MethodAttributes
      //if ((methodAttributes & MethodAttributes.CheckAccessOnOverride) != 0) { Logger.Warning(warningTemplate, "CheckAccessOnOverride"); }
      //if ((methodAttributes & MethodAttributes.FamANDAssem) != 0) { Logger.Warning(warningTemplate, "FamANDAssem"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.HasSecurity) != 0) { Logger.Warning(warningTemplate, "HasSecurity"); }
      //if ((methodAttributes & MethodAttributes.HideBySig) != 0) { Logger.Warning(warningTemplate, "HideBySig"); }
      //if ((methodAttributes & MethodAttributes.NewSlot) != 0) { Logger.Warning(warningTemplate, "NewSlot"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.PinvokeImpl) != 0) { Logger.Warning(warningTemplate, "PinvokeImpl"); }
      //if ((methodAttributes & MethodAttributes.PrivateScope) != 0) { Logger.Warning(warningTemplate, "PrivateScope"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.RequireSecObject) != 0) { Logger.Warning(warningTemplate, "RequiresSecObject"); }
      //if ((methodAttributes & MethodAttributes.ReuseSlot) != 0) { Logger.Warning(warningTemplate, "ReuseSlot"); }
      //if ((methodAttributes & MethodAttributes.RTSpecialName) != 0) { Logger.Warning(warningTemplate, "RTSpecialName"); }
      //if ((methodAttributes & MethodAttributes.SpecialName) != 0) { Logger.Warning(warningTemplate, "SpecialName"); }
      // TODO: support this: if ((methodAttributes & MethodAttributes.UnmanagedExport) != 0) { Logger.Warning(warningTemplate, "UnmanagedExport"); }
    }
        private static string GetEventArgsTypeForEvent(EventDefinition ei)
        {
            // Find the EventArgs type parameter of the event via digging around via reflection
            var type = ei.EventType.Resolve();
            var invoke = type.Methods.First(x => x.Name == "Invoke");
            if (invoke.Parameters.Count < 2) return null;

            var param = invoke.Parameters[1];
            var ret = RenameBogusWinRTTypes(param.ParameterType.FullName);

            var generic = ei.EventType as GenericInstanceType;
            if (generic != null)
            {
                foreach (
                    var kvp in
                        type.GenericParameters.Zip(generic.GenericArguments, (name, actual) => new {name, actual}))
                {
                    var realType = GetRealTypeName(kvp.actual);

                    ret = ret.Replace(kvp.name.FullName, realType);
                }
            }

            // NB: Inner types in Mono.Cecil get reported as 'Foo/Bar'
            return ret.Replace('/', '.');
        }
Esempio n. 5
0
        public void ProcessEvent(EventDefinition eventt)
        {
            _logger.LogDebug("Beginning processing event " + eventt.Name);

            FieldReference eventDelegate = eventt.GetEventDelegate();

            if (eventDelegate != null)
            {
                if (eventDelegate.FieldType.IsValidEventDelegate())
                {
                    WeakEventWeaver weakEventWeaver = new WeakEventWeaver(eventDelegate, _moduleImporter);
                    ProcessAddMethod(eventt.AddMethod, weakEventWeaver);
                    ProcessRemoveMethod(eventt.RemoveMethod, weakEventWeaver);
                }
                else
                {
                    _logger.LogInfo("Skipping event " + eventt + ", incompatible event delegate type");
                }
            }
            else
            {
                _logger.LogInfo("Skipping event " + eventt + ", could not determine the event delegate field");
            }

            _logger.LogDebug("Finished processing event " + eventt.Name);
        }
        protected override void Write(EventDefinition @event)
        {
            WriteEventDeclaration(@event);

            int startIndex = formatter.CurrentPosition;

            WriteStartBlock();

            WriteAttributes(@event.CustomAttributes);

            WriteNestedMethod(".addon", @event.AddMethod);

            WriteLine();

            WriteNestedMethod(".removeon", @event.RemoveMethod);

            WriteNestedMethod(".fire", @event.InvokeMethod);

            foreach (var method in @event.OtherMethods)
            {
                WriteNestedMethod(".other", method);
            }
            WriteEndBlock();

            this.currentWritingInfo.MemberDefinitionToFoldingPositionMap[@event] = new OffsetSpan(startIndex, formatter.CurrentPosition - 1);
        }
        private static MethodDefinition CreateSourceEventMethodFor(EventDefinition eventDefinition)
        {
            var eventField = eventDefinition.DeclaringType.Fields.Single(x => x.FullName == eventDefinition.FullName);
            var domainEventType = ((GenericInstanceType) eventField.FieldType).GenericArguments[0];
            var invokeMethod = eventField.FieldType.Resolve().Methods.Single(x => x.Name == "Invoke").MakeGenericMethod(domainEventType);
            var eventDelegate = eventDefinition.DeclaringType.Module.ImportReference(invokeMethod);

            var noReturnValue = eventDefinition.DeclaringType.Module.TypeSystem.Void;
            var eventSourcingMethod = new MethodDefinition("<Ichnaea>SourceEvent", SourceEventMethodAttributes, noReturnValue);
            eventSourcingMethod.Parameters.Add(new ParameterDefinition("domainEvent", ParameterAttributes.None, domainEventType));
            eventSourcingMethod.Body.Variables.Add(new VariableDefinition("eventSource", eventField.FieldType));
            eventSourcingMethod.Body.MaxStackSize = 3;
            eventSourcingMethod.Body.InitLocals = true;

            var il = eventSourcingMethod.Body.GetILProcessor();
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, eventField);
            il.Emit(OpCodes.Stloc_0);
            il.Emit(OpCodes.Ldloc_0);

            var nullCheckPlaceholder = il.Create(OpCodes.Nop);
            il.Append(nullCheckPlaceholder);
            il.Emit(OpCodes.Ret);

            var startOfCallSequence = il.Create(OpCodes.Ldloc_0);
            il.Append(startOfCallSequence);
            il.Replace(nullCheckPlaceholder, il.Create(OpCodes.Brtrue_S, startOfCallSequence));

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldarg_1);
            il.Emit(OpCodes.Callvirt, eventDelegate);
            il.Emit(OpCodes.Ret);

            return eventSourcingMethod;
        }
Esempio n. 8
0
		public void UnattachedEvent ()
		{
			var int32 = typeof (int).ToDefinition ();
			var evt = new EventDefinition ("Event", EventAttributes.None, int32);

			Assert.AreEqual (null, evt.AddMethod);
		}
        public void Add(EventDefinition value)
        {
            if (!Contains (value))
                Attach (value);

            List.Add (value);
        }
		public override void ProcessEvent (EventDefinition @event)
		{
			foreach (var attribute in GetPreserveAttributes (@event)) {
				MarkMethod (@event.AddMethod, attribute);
				MarkMethod (@event.InvokeMethod, attribute);
				MarkMethod (@event.RemoveMethod, attribute);
			}
		}
		public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
		}
Esempio n. 12
0
		public AnalyzedEventTreeNode(EventDefinition analyzedEvent, string prefix = "")
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");
			this.analyzedEvent = analyzedEvent;
			this.prefix = prefix;
			this.LazyLoading = true;
		}
Esempio n. 13
0
 /// <summary>
 /// Creates an event like the specified event, but doesn't add it anywhere.
 /// </summary>
 /// <param name="yourEvent"></param>
 /// <param name="newName"></param>
 /// <returns></returns>
 private EventDefinition CopyEvent(EventDefinition yourEvent, string newName)
 {
     var targetEventType = FixTypeReference(yourEvent.EventType);
     var targetEvent = new EventDefinition(newName,
         yourEvent.Attributes,
         targetEventType);
     return targetEvent;
 }
Esempio n. 14
0
		public static ImageSource GetIcon(EventDefinition eventDef)
		{
			MethodDefinition accessor = eventDef.AddMethod ?? eventDef.RemoveMethod;
			if (accessor != null)
				return Images.GetIcon(MemberIcon.Event, GetOverlayIcon(eventDef.AddMethod.Attributes), eventDef.AddMethod.IsStatic);
			else
				return Images.GetIcon(MemberIcon.Event, AccessOverlayIcon.Public, false);
		}
Esempio n. 15
0
        public EventSourcingMethod(EventDefinition eventDefinition)
        {
            if (eventDefinition == null)
                throw new ArgumentNullException(nameof(eventDefinition));

            this.eventSourcingMethod = CreateSourceEventMethodFor(eventDefinition);
            this.eventDefinition = eventDefinition;
            this.domainEventType = ((GenericInstanceType) eventDefinition.EventType).GenericArguments[0].Resolve();
        }
Esempio n. 16
0
 public static string Create(EventDefinition evt)
 {
     var method = evt.InvokeMethod ?? evt.AddMethod ?? evt.RemoveMethod;
     if (method.IsPublic) return "event";
     if (method.IsAssembly) return "event internal";
     if (method.IsFamily) return "event protected";
     if (method.IsFamilyOrAssembly) return "event protected_internal";
     return "event private";
 }
		public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.threading = new ThreadingSupport();
			this.LazyLoading = true;
		}
Esempio n. 18
0
 public EventDefinition AddDefinition(EventDefinition def, string name = "")
 {
     CheckOriginMember(def);
     var ret = copier.Copy(def);
     DestinationType.Events.Add(ret);
     if(name != "")
         ret.Name = name;
     return ret;
 }
Esempio n. 19
0
		public override void ProcessEvent (EventDefinition @event)
		{
			var attribute = GetPreserveAttribute (@event);
			if (attribute == null)
				return;

			MarkMethod (@event.AddMethod, attribute);
			MarkMethod (@event.InvokeMethod, attribute);
			MarkMethod (@event.RemoveMethod, attribute);
		}
		public AnalyzedEventFiredByTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;

			this.eventBackingField = GetBackingField(analyzedEvent);
			this.eventFiringMethod = analyzedEvent.EventType.Resolve().Methods.First(md => md.Name == "Invoke");
		}
		public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
			this.threading = new ThreadingSupport();
			this.LazyLoading = true;
		}
		public  DomCecilEvent (EventDefinition eventDefinition)
		{
			this.eventDefinition     = eventDefinition;
			base.name                = eventDefinition.Name;
			base.Modifiers           = DomCecilType.GetModifiers (eventDefinition.AddMethod);
			base.ReturnType          = DomCecilMethod.GetReturnType (eventDefinition.EventType);
			DomCecilMethod.AddAttributes (this, eventDefinition.CustomAttributes);
			if (!eventDefinition.IsSpecialName)
				base.Modifiers &= ~MonoDevelop.Projects.Dom.Modifiers.SpecialName;
		}
Esempio n. 23
0
 private MonoEventInfo(IMonoStructType klass, int index, Cecil.EventDefinition einfo,
                       TargetType type, bool is_static,
                       TargetMemberAccessibility accessibility, MonoFunctionType add,
                       MonoFunctionType remove, MonoFunctionType raise)
     : base(type, einfo.Name, index, is_static, accessibility, add, remove, raise)
 {
     this.Klass      = klass;
     this.AddType    = add;
     this.RemoveType = remove;
     this.RaiseType  = raise;
 }
		public AnalyzedEventAccessorsTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");
			this.analyzedEvent = analyzedEvent;

			if (analyzedEvent.AddMethod != null)
				this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.AddMethod, "add"));
			if (analyzedEvent.RemoveMethod != null)
				this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.RemoveMethod, "remove"));
			foreach (var accessor in analyzedEvent.OtherMethods)
				this.Children.Add(new AnalyzedEventAccessorTreeNode(accessor, null));
		}
Esempio n. 25
0
        public static bool IsMatch(EventDefinition event1, EventDefinition event2)
        {
            if (event1.Name != event2.Name) {
            return false;
              }

              if (!TypeMatcher.IsMatch(event1.EventType, event2.EventType)) {
            return false;
              }

              // TODO: event accessors comparison??

              return true;
        }
 private void ImplementEventAccessorMethods(EventDefinition implementedEvent, MemberComposer propertyAccessorComposer)
 {
     if (RoleEvent.AddMethod != null) {
     var addMethodRoleGroup = Container.ResolveGroup(Role, RoleEvent.AddMethod);
     implementedEvent.AddMethod = (MethodDefinition)propertyAccessorComposer.Compose(addMethodRoleGroup, _accessSpecifier);
       }
       if (RoleEvent.RemoveMethod != null) {
     var removeMethodRoleGroup = Container.ResolveGroup(Role, RoleEvent.RemoveMethod);
     implementedEvent.RemoveMethod = (MethodDefinition)propertyAccessorComposer.Compose(removeMethodRoleGroup, _accessSpecifier);
       }
       if (RoleEvent.InvokeMethod != null) {
     var invokeMethodRoleGroup = Container.ResolveGroup(Role, RoleEvent.InvokeMethod);
     implementedEvent.RemoveMethod = (MethodDefinition)propertyAccessorComposer.Compose(invokeMethodRoleGroup, _accessSpecifier);
       }
 }
Esempio n. 27
0
        static NotifierWeaver()
        {
            var type = typeof(Template);
            var assemblyPath = type.Assembly.Location;
            var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
            var module = assembly.MainModule;
            originType = module.Import(type).Resolve();

            tNotifierEvent  = originType.Events.Single(e => e.Name == "PropertyChanged");
            tNotifierMethod = originType.Methods.Single(e => e.Name == "EventInvoke");
            tNotifierField  = originType.Fields.Single(e => e.Name == "handlers");

            tPropertyProperty = originType.Properties.Single(e => e.Name == "Property");
            tPropertyField    = originType.Fields.Single(e => e.Name == "pValue");
            tPropertyNameC    = originType.Fields.Single(e => e.Name == "pNameC");
        }
Esempio n. 28
0
        public EventTreeNode(EventDefinition ev)
        {
            if (ev == null)
                throw new ArgumentNullException("ev");
            this.ev = ev;

            if (ev.AddMethod != null)
                this.Children.Add(new MethodTreeNode(ev.AddMethod));
            if (ev.RemoveMethod != null)
                this.Children.Add(new MethodTreeNode(ev.RemoveMethod));
            if (ev.InvokeMethod != null)
                this.Children.Add(new MethodTreeNode(ev.InvokeMethod));
            if (ev.HasOtherMethods) {
                foreach (var m in ev.OtherMethods)
                    this.Children.Add(new MethodTreeNode(m));
            }
        }
        protected override void ProcessEvent(EventDefinition eventDef)
        {
            if (eventDef.AddMethod != null && eventDef.AddMethod.Module == null) {
                eventDef.AddMethod = null;
            }
            if (eventDef.RemoveMethod != null && eventDef.RemoveMethod.Module == null) {
                eventDef.RemoveMethod = null;
            }
            eventDef.OtherMethods.RemoveWhere(methodDef => methodDef.Module == null);

            if (eventDef.AddMethod == null && eventDef.RemoveMethod == null && !eventDef.OtherMethods.Any()) {
                Trace.WriteLine(string.Format("Removing event {0}.", eventDef), "RemovePrivateMembers");
                eventDef.DeclaringType.Events.Remove(eventDef);
            }

            base.ProcessEvent(eventDef);
        }
Esempio n. 30
0
        void get_events()
        {
            lock (this) {
                if (events != null)
                {
                    return;
                }

                events = new MonoEventInfo [TypeDef.Events.Count];

                for (int i = 0; i < events.Length; i++)
                {
                    Cecil.EventDefinition ev = TypeDef.Events [i];
                    events [i] = MonoEventInfo.Create(this, i, ev);
                }
            }
        }
Esempio n. 31
0
        internal static MonoEventInfo Create(IMonoStructType klass, int index,
                                             Cecil.EventDefinition einfo)
        {
            TargetType type = klass.File.MonoLanguage.LookupMonoType(einfo.EventType);

            bool             is_static = false;
            MonoFunctionType add, remove, raise;

            TargetMemberAccessibility accessibility = TargetMemberAccessibility.Private;

            if (einfo.AddMethod != null)
            {
                add           = klass.LookupFunction(einfo.AddMethod);
                is_static     = einfo.AddMethod.IsStatic;
                accessibility = MonoMethodInfo.GetAccessibility(einfo.AddMethod);
            }
            else
            {
                add = null;
            }

            if (einfo.RemoveMethod != null)
            {
                remove        = klass.LookupFunction(einfo.RemoveMethod);
                is_static     = einfo.RemoveMethod.IsStatic;
                accessibility = MonoMethodInfo.GetAccessibility(einfo.RemoveMethod);
            }
            else
            {
                remove = null;
            }

            if (einfo.InvokeMethod != null)
            {
                raise         = klass.LookupFunction(einfo.InvokeMethod);
                is_static     = einfo.InvokeMethod.IsStatic;
                accessibility = MonoMethodInfo.GetAccessibility(einfo.InvokeMethod);
            }
            else
            {
                raise = null;
            }

            return(new MonoEventInfo(
                       klass, index, einfo, type, is_static, accessibility, add, remove, raise));
        }
Esempio n. 32
0
		public void VisitEvent(EventDefinition evt)
		{							
			if (evt.AddMethod.ExternallyVisible(Cache))
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "event: {0}", evt.Name);	
				Log.DebugLine(this, "type: {0}", evt.EventType);	
				
				TypeDefinition type = evt.EventType as TypeDefinition;
				if (type != null)
				{
					MethodDefinition[] methods = type.Methods.GetMethod("Invoke");
					if (methods.Length == 1)
					{
						MethodDefinition method = methods[0];
						
						string details = string.Empty;
						if (method.ReturnType.ReturnType.ToString() != "System.Void")
							details += "Return type should be void. ";
							
						if (method.Parameters.Count == 2)
						{
							ParameterDefinition arg1 = method.Parameters[0];
							if (arg1.Name != "sender")
								details += "First argument should be named 'sender'. ";
							if (arg1.ParameterType.FullName != "System.Object")
								details += "First argument should be a System.Object. ";

							ParameterDefinition arg2 = method.Parameters[1];
							if (arg2.Name != "e")
								details += "Second argument should be named 'e'. ";
							if (!arg2.ParameterType.IsSameOrSubclassOf("System.EventArgs", Cache))
								details += "Second argument should be a System.EventArgs or a subclass. ";
						}
						else
							details += "The event should have two arguments. ";
							
						if (details.Length > 0)
						{
							Log.DebugLine(this, details);
							Reporter.TypeFailed(type, CheckID, details);
						}
					}
				}
			}
		}
Esempio n. 33
0
		public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options)
		{
			ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
			rd.DisassembleEvent(ev);
			if (ev.AddMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(ev.AddMethod);
			}
			if (ev.RemoveMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(ev.RemoveMethod);
			}
			foreach (var m in ev.OtherMethods) {
				output.WriteLine();
				rd.DisassembleMethod(m);
			}
		}
        public void Insert(int index, EventDefinition value)
        {
            Attach(value);

            List.Insert(index, value);
        }
Esempio n. 35
0
 public int IndexOf(EventDefinition value)
 {
     return(m_items.IndexOf(value));
 }
Esempio n. 36
0
 public bool Contains(EventDefinition value)
 {
     return(m_items.Contains(value));
 }
        public void Add(EventDefinition value)
        {
            Attach(value);

            List.Add(value);
        }
Esempio n. 38
0
 public virtual void VisitEventDefinition(EventDefinition evt)
 {
 }
 public bool Contains(EventDefinition value)
 {
     return(List.Contains(value));
 }
        public new void RemoveAt(int index)
        {
            EventDefinition item = this [index];

            Remove(item);
        }
 public int IndexOf(EventDefinition value)
 {
     return(List.IndexOf(value));
 }
        public void Remove(EventDefinition value)
        {
            List.Remove(value);

            Detach(value);
        }
 public EventDefinitionEventArgs(EventDefinition item)
 {
     m_item = item;
 }