예제 #1
0
        /// <summary>
        /// Creates a nested class
        /// </summary>
        /// <returns>TypeSpecifier for a new nested class</returns>
        internal TypeSpecifier CreateDisplayClass()
        {
            var identifier = _identifiers.GetDisplayClassIdentifier();
            var nestedTb   = TypeBuilder.DefineNestedType(identifier.TypeName, TypeAttributes.NestedPrivate | TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Abstract);

            nestedTb.SetCustomAttribute(Specification <string> .GeneratedCode);

            var ts = new TypeSpecifier(nestedTb)
            {
                _identifiers = identifier
            };

            _nestedClasses.Add(ts);
            return(ts);
        }
        /// <summary>
        /// Emits the IL for this method
        /// </summary>
        /// <param name="il">IL Generator</param>
        /// <param name="sourceField">The field containing the source component</param>
        /// <param name="typeBeingBuilt">The type being built</param>
        internal override void Emit(ILGenerator il, FieldBuilder sourceField, TypeSpecifier typeBeingBuilt)
        {
            var nestedType   = typeBeingBuilt.CreateDisplayClass();
            var backingField = nestedType.TypeBuilder.DefineField(nestedType.GetInvokeName(_name),
                                                                  _invoke.GetType(),
                                                                  FieldAttributes.Static | FieldAttributes.Public);

            typeBeingBuilt.RunAfterCreation(() =>
            {
                backingField.SafeSetValue(null, _invoke);
            });

            il.Emit(OpCodes.Ldsfld, backingField);

            foreach (var p in _params)
            {
                p.Emit(il, sourceField, typeBeingBuilt.TypeBuilder);
            }

            il.Emit(OpCodes.Callvirt, _invoke.GetType().GetMethod("Invoke"));
            il.Emit(OpCodes.Ret);
        }
예제 #3
0
        /// <summary>
        /// Emits the IL for setting a backing component property
        /// </summary>
        /// <param name="setterIL">ILGenerator</param>
        /// <param name="sourceField">The field where the source component is stored</param>
        /// <param name="nestedType">Builder for a nested type, in case this property needs to
        /// make one</param>
        /// <param name="thisType">Builder for the current type</param>
        protected override void ProtectedEmitSetter(ILGenerator setterIL, FieldBuilder sourceField, Lazy <TypeSpecifier> nestedType, TypeSpecifier thisType, string name)
        {
            if (_invokeSetter == null)
            {
                setterIL.Emit(OpCodes.Ldarg_0);
                setterIL.Emit(OpCodes.Ldfld, sourceField);
                setterIL.Emit(OpCodes.Ldloc_0);
                setterIL.Emit(OpCodes.Callvirt, _componentProperty.GetSetMethod(true));
            }
            else
            {
                var nested        = nestedType.Value;
                var backingSetter = nested.TypeBuilder.DefineField(nested.GetBackingSetterIdentifier(name),
                                                                   _setterType,
                                                                   FieldAttributes.Public | FieldAttributes.Static);

                thisType.RunAfterCreation(() =>
                {
                    backingSetter.SafeSetValue(null, _invokeSetter);
                });

                setterIL.Emit(OpCodes.Ldsfld, backingSetter);
                setterIL.Emit(OpCodes.Ldarg_0);
                setterIL.Emit(OpCodes.Ldfld, sourceField);
                setterIL.Emit(OpCodes.Ldloc_0);
                setterIL.Emit(OpCodes.Callvirt, _setterType.GetMethod("Invoke"));
            }
        }
예제 #4
0
        /// <summary>
        /// Emits the IL for the setter
        /// </summary>
        /// <param name="setterIL">ILGenerator</param>
        /// <param name="sourceField">The field where the source component is stored</param>
        /// <param name="nestedType">Builder for nested type in case this property needs
        /// to make one</param>
        /// <param name="thisType">Builder for the declaring type</param>
        protected override void ProtectedEmitSetter(ILGenerator setterIL, FieldBuilder sourceField, Lazy <TypeSpecifier> nestedType, TypeSpecifier thisType, string name)
        {
            var backingSetter = nestedType.Value.TypeBuilder.DefineField(
                nestedType.Value.GetBackingSetterIdentifier(name),
                _setter.GetType(),
                FieldAttributes.Public | FieldAttributes.Static);

            thisType.RunAfterCreation(() =>
            {
                backingSetter.SafeSetValue(null, _setter);
            });

            setterIL.Emit(OpCodes.Ldsfld, backingSetter);
            setterIL.Emit(OpCodes.Ldarg_0);
            setterIL.Emit(OpCodes.Ldfld, sourceField);
            setterIL.Emit(OpCodes.Ldloc_0);
            setterIL.Emit(OpCodes.Callvirt, typeof(Action <TComponent, TValue>).GetMethod("Invoke"));
        }
 /// <summary>
 /// Emits the IL for a setter
 /// </summary>
 /// <param name="setterIL">ILGenerator</param>
 /// <param name="sourceField">The field where the source component is stored</param>
 /// <param name="nestedType">Builder for a nested type in case this property needs to make one</param>
 /// <param name="thisType">Builder for the declaring type</param>
 protected override void ProtectedEmitSetter(ILGenerator setterIL, FieldBuilder sourceField, Lazy <TypeSpecifier> nestedType, TypeSpecifier thisType, string name)
 {
     setterIL.Emit(OpCodes.Ldarg_0);
     setterIL.Emit(OpCodes.Ldloc_0);
     setterIL.Emit(OpCodes.Stfld, BackingField);
 }
        /// <summary>
        /// Emits the IL for a getter
        /// </summary>
        /// <param name="getterIL">ILGenerator</param>
        /// <param name="sourceField">The field where the source component is stored</param>
        /// <param name="nestedType">Builder for a nested type in case this property needs to make one</param>
        /// <param name="thisType">Builder for the declaring type</param>
        protected override void ProtectedEmitGetter(ILGenerator getterIL, FieldBuilder sourceField, Lazy <TypeSpecifier> nestedType, TypeSpecifier thisType, string name)
        {
            BackingField = thisType.TypeBuilder.DefineField(thisType.GetBackingFieldIdentifier(name), typeof(TField), FieldAttributes.Private);
            BackingField.SetCustomAttribute(Specification <string> .GeneratedCode);

            getterIL.Emit(OpCodes.Ldarg_0);
            getterIL.Emit(OpCodes.Ldfld, BackingField);
        }