Beispiel #1
0
        private void _Implement(FluentTypeBuilder <TAbstract> typeBuilder, Type interfaceType)
        {
            foreach (var method in interfaceType.GetMethods())
            {
                if (method.IsAbstract)
                {
                    ImplementAnyMethod(typeBuilder, method);
                }
            }

            foreach (var property in interfaceType.GetProperties())
            {
                if (_IsAbstract(property))
                {
                    ImplementAnyProperty(typeBuilder, property);
                }
            }

            foreach (var eventInfo in interfaceType.GetEvents())
            {
                if (eventInfo.GetAddMethod().IsAbstract)
                {
                    ImplementEventUntyped(typeBuilder, eventInfo);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// This method is invoked to implement any method, be it a normal method, a property getter, setter etc.
 /// If you want to implement only normal methods, inherit the ImplementMethod method.
 /// </summary>
 protected virtual void ImplementAnyMethod(FluentTypeBuilder <TAbstract> typeBuilder, MethodInfo method)
 {
     if (!method.IsSpecialName)
     {
         ImplementMethod(typeBuilder, method);
     }
 }
Beispiel #3
0
        private FluentTypeBuilder <TAbstract> _GetTypeBuilder()
        {
            if (_typeBuilder != null)
            {
                return(_typeBuilder);
            }

            var typeBuilder = CreateTypeBuilder(_additionalInterfaces);

            _Implement(typeBuilder, typeof(TAbstract));

            if (typeof(TAbstract).IsInterface)
            {
                var baseInterfaces = typeof(TAbstract).GetInterfaces();
                foreach (var baseInterface in baseInterfaces)
                {
                    _Implement(typeBuilder, baseInterface);
                }
            }

            if (_additionalInterfaces != null)
            {
                foreach (var additionalInterface in _additionalInterfaces)
                {
                    if (!additionalInterface.IsAssignableFrom(typeof(TAbstract)))
                    {
                        _Implement(typeBuilder, additionalInterface);
                    }
                }
            }

            _typeBuilder = typeBuilder;
            return(typeBuilder);
        }
Beispiel #4
0
 /// <summary>
 /// This method is invoked to implement any property, be it a normal property or an indexer.
 /// If you want to generate only properties, override the ImplementPropertyUntyped or the ImplementProperty generic method.
 /// </summary>
 protected virtual void ImplementAnyProperty(FluentTypeBuilder <TAbstract> typeBuilder, PropertyInfo property)
 {
     if (property.GetIndexParameters().Length > 0)
     {
         ImplementIndexerUntyped(typeBuilder, property);
     }
     else
     {
         ImplementPropertyUntyped(typeBuilder, property);
     }
 }
 /// <summary>
 /// Creates a new NotifyPropertyChangedGenerator that will work with the given typeBuilder
 /// and also let you tell where is the field that stores the PropertyChanged delegates.
 /// </summary>
 public static NotifyPropertyChangedGenerator <TBase> Create <TBase>(FluentTypeBuilder <TBase> typeBuilder, Expression <Func <PropertyChangedEventHandler> > eventHandlerFieldExpression)
 {
     return(new NotifyPropertyChangedGenerator <TBase>(typeBuilder, eventHandlerFieldExpression));
 }
 /// <summary>
 /// Creates a new NotifyPropertyChangedGenerator that will work with the given typeBuilder.
 /// </summary>
 public static NotifyPropertyChangedGenerator <TBase> Create <TBase>(FluentTypeBuilder <TBase> typeBuilder)
 {
     return(new NotifyPropertyChangedGenerator <TBase>(typeBuilder));
 }
Beispiel #7
0
 /// <summary>
 /// Method invoked to implement events.
 /// </summary>
 protected abstract void ImplementEvent <T>(FluentTypeBuilder <TAbstract> typeBuilder, EventInfo eventInfo);
Beispiel #8
0
 /// <summary>
 /// Method invoked to implement indexers.
 /// </summary>
 protected abstract void ImplementIndexerUntyped(FluentTypeBuilder <TAbstract> typeBuilder, PropertyInfo indexer);
Beispiel #9
0
 /// <summary>
 /// Method invoked to implement properties.
 /// </summary>
 protected abstract void ImplementProperty <T>(FluentTypeBuilder <TAbstract> typeBuilder, PropertyInfo property);
Beispiel #10
0
 /// <summary>
 /// Method invoked to implement methods.
 /// </summary>
 protected abstract void ImplementMethod(FluentTypeBuilder <TAbstract> typeBuilder, MethodInfo method);
Beispiel #11
0
        /// <summary>
        /// This method is invoked to implement events, but it is not typed. It is usually better to only override the
        /// ImplementEvent generic method.
        /// </summary>
        protected virtual void ImplementEventUntyped(FluentTypeBuilder <TAbstract> typeBuilder, EventInfo eventInfo)
        {
            var implementEvent = _implementEvent.MakeGenericMethod(eventInfo.EventHandlerType);

            implementEvent.Invoke(this, new object[] { typeBuilder, eventInfo });
        }
Beispiel #12
0
        /// <summary>
        /// This method is invoked to implement normal properties (that is, excluding indexers), but it does not have the
        /// parameters rightly typed, which can make it hard to build the expression. You will probably prefer to inherit
        /// the ImplementProperty generic method.
        /// </summary>
        protected virtual void ImplementPropertyUntyped(FluentTypeBuilder <TAbstract> typeBuilder, PropertyInfo property)
        {
            var implementProperty = _implementProperty.MakeGenericMethod(property.PropertyType);

            implementProperty.Invoke(this, new object[] { typeBuilder, property });
        }