Exemplo n.º 1
0
 protected abstract void GenerateDelegateCreateExpression(CodeDelegateCreateExpression e);
	protected override void GenerateDelegateCreateExpression
				(CodeDelegateCreateExpression e)
			{
				Output.Write("new ");
				OutputType(e.DelegateType);
				Output.Write("(");
				if(e.TargetObject != null)
				{
					GenerateExpression(e.TargetObject);
					Output.Write(".");
				}
				OutputIdentifier(e.MethodName);
				Output.Write(")");
			}
Exemplo n.º 3
0
 protected override void GenerateDelegateCreateExpression(CodeDelegateCreateExpression e)
 {
 }
Exemplo n.º 4
0
 private void ValidateDelegateCreateExpression(CodeDelegateCreateExpression e)
 {
     ValidateTypeReference(e.DelegateType);
     ValidateExpression(e.TargetObject);
     ValidateIdentifier(e, nameof(e.MethodName), e.MethodName);
 }
Exemplo n.º 5
0
        public override void Serialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
        {
            EventDescriptor eventToSerialize = descriptor as EventDescriptor;

            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (eventToSerialize == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }
            if (statements == null)
            {
                throw new ArgumentNullException(nameof(statements));
            }

            try
            {
                IEventBindingService eventBindings = (IEventBindingService)manager.GetService(typeof(IEventBindingService));

                // If the IEventBindingService is not available, we don't throw - we just don't do anything.
                if (eventBindings != null)
                {
                    PropertyDescriptor prop       = eventBindings.GetEventProperty(eventToSerialize);
                    string             methodName = (string)prop.GetValue(value);

                    if (methodName != null)
                    {
                        CodeDomSerializer.Trace("Event {0} bound to {1}", eventToSerialize.Name, methodName);
                        CodeExpression eventTarget = SerializeToExpression(manager, value);
                        CodeDomSerializer.TraceWarningIf(eventTarget == null, "Object has no name and no propery ref in context so we cannot serialize events: {0}", value);
                        if (eventTarget != null)
                        {
                            CodeTypeReference            delegateTypeRef = new CodeTypeReference(eventToSerialize.EventType);
                            CodeDelegateCreateExpression delegateCreate  = new CodeDelegateCreateExpression(delegateTypeRef, _thisRef, methodName);
                            CodeEventReferenceExpression eventRef        = new CodeEventReferenceExpression(eventTarget, eventToSerialize.Name);
                            CodeAttachEventStatement     attach          = new CodeAttachEventStatement(eventRef, delegateCreate);

                            attach.UserData[typeof(Delegate)] = eventToSerialize.EventType;
                            statements.Add(attach);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Since we usually go through reflection, don't
                // show what our engine does, show what caused
                // the problem.
                //
                if (e is TargetInvocationException)
                {
                    e = e.InnerException;
                }

                manager.ReportError(new CodeDomSerializerException(string.Format(SR.SerializerPropertyGenFailed, eventToSerialize.Name, e.Message), manager));
            }
        }