/// <inheritdoc />
        protected override void GenerateImplementation(IntrospectivePropertyInfo property, string symbolName, string uniqueMemberIdentifier)
        {
            var propertyBuilder = TargetType.DefineProperty
                                  (
                property.Name,
                PropertyAttributes.None,
                CallingConventions.HasThis,
                property.PropertyType,
                property.IndexParameterTypes.ToArray()
                                  );

            // Note, the field is going to have to be a pointer, because it is pointing to global variable
            var fieldType            = Options.HasFlagFast(UseLazyBinding) ? typeof(Lazy <IntPtr>) : typeof(IntPtr);
            var propertyFieldBuilder = TargetType.DefineField
                                       (
                uniqueMemberIdentifier,
                fieldType,
                FieldAttributes.Private
                                       );

            if (property.CanRead)
            {
                GeneratePropertyGetter(property, propertyFieldBuilder, propertyBuilder);
            }

            if (property.CanWrite)
            {
                GeneratePropertySetter(property, propertyFieldBuilder, propertyBuilder);
            }

            PropertyInitializationInConstructor(symbolName, propertyFieldBuilder); // This is ok for all 3 types of properties.
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public override IEnumerable <PipelineWorkUnit <IntrospectivePropertyInfo> > GenerateImplementation(PipelineWorkUnit <IntrospectivePropertyInfo> workUnit)
        {
            var property = workUnit.Definition;

            var propertyBuilder = TargetType.DefineProperty
                                  (
                property.Name,
                PropertyAttributes.None,
                CallingConventions.HasThis,
                property.PropertyType,
                property.IndexParameterTypes.ToArray()
                                  );

            // Note, the field is going to have to be a pointer, because it is pointing to global variable
            var fieldType            = Options.HasFlagFast(UseLazyBinding) ? typeof(Lazy <IntPtr>) : typeof(IntPtr);
            var propertyFieldBuilder = TargetType.DefineField
                                       (
                $"{workUnit.GetUniqueBaseMemberName()}_backing",
                fieldType,
                FieldAttributes.Private
                                       );

            if (property.CanRead)
            {
                GeneratePropertyGetter(property, propertyFieldBuilder, propertyBuilder);
            }

            if (property.CanWrite)
            {
                GeneratePropertySetter(property, propertyFieldBuilder, propertyBuilder);
            }

            AugmentHostingTypeConstructor(workUnit.SymbolName, propertyFieldBuilder);

            yield break;
        }