Пример #1
0
        /// <summary>
        /// Maps a member from the type's definition to its constructed version.
        /// </summary>
        public IEntity MapMember(IEntity source)
        {
            if (source == null)
            {
                return(null);
            }

            if (_mappedMembers.ContainsKey(source))
            {
                return(_mappedMembers[source]);
            }

            IEntity mapped = null;

            switch (source.EntityType)
            {
            case EntityType.Method:
                mapped = new MappedMethod(_typeSystemServices, ((ExternalMethod)source).MethodInfo, this);
                break;

            case EntityType.Constructor:
                mapped = new MappedConstructor(_typeSystemServices, ((ExternalConstructor)source).ConstructorInfo, this);
                break;

            case EntityType.Field:
                mapped = new MappedField(_typeSystemServices, ((ExternalField)source).FieldInfo, this);
                break;

            case EntityType.Property:
                mapped = new MappedProperty(_typeSystemServices, ((ExternalProperty)source).PropertyInfo, this);
                break;

            case EntityType.Type:
                mapped = MapType((IType)source);
                break;

            case EntityType.Event:
                mapped = new MappedEvent(_typeSystemServices, ((ExternalEvent)source).EventInfo, this);
                break;

            default:
                throw new ArgumentException(
                          string.Format("Invalid entity type for mapping: {0}.", source.EntityType));
            }

            _mappedMembers[source] = mapped;
            return(mapped);
        }
    /// <summary>
    /// Run the event mapper over the supplied MappedEvent type.
    /// </summary>
    /// <param name="eventType">MappedEvent to run through the event mapper.</param>
    private static void MapEvent(MappedEvent.MappingEvent eventType)
    {
      foreach (MappedEvent mappedEvent in EventMappings)
      {
        if (mappedEvent.EventType == eventType)
        {
          if (mappedEvent.MatchParam)
            continue;

          Log.Debug("MPControlPlugin: Event Mapper - Event \"{0}\"",
                    Enum.GetName(typeof (MappedEvent.MappingEvent), eventType));

          try
          {
            ProcessCommand(mappedEvent.Command, false);
          }
          catch (Exception ex)
          {
            Log.Error("MPControlPlugin: Failed to execute Event Mapper command \"{0}\" - {1}", mappedEvent.EventType,
                      ex.ToString());
          }
        }
      }
    }