Example #1
0
        /// <inheritdoc />
        public override IEnumerable <PipelineWorkUnit <IntrospectiveMethodInfo> > GenerateImplementation(PipelineWorkUnit <IntrospectiveMethodInfo> workUnit)
        {
            var definition = workUnit.Definition;

            var backingFieldType = typeof(IntPtr);

            var backingField = Options.HasFlagFast(UseLazyBinding)
            ? TargetType.DefineField
                               (
                $"{workUnit.GetUniqueBaseMemberName()}_ptr_lazy",
                typeof(Lazy <>).MakeGenericType(backingFieldType),
                FieldAttributes.Private | FieldAttributes.InitOnly
                               )
            : TargetType.DefineField
                               (
                $"{workUnit.GetUniqueBaseMemberName()}_ptr",
                backingFieldType,
                FieldAttributes.Private | FieldAttributes.InitOnly
                               );

            AugmentHostingTypeConstructorWithNativeInitialization(workUnit.SymbolName, backingFieldType, backingField);
            GenerateNativeInvokerBody(definition, definition.GetNativeCallingConvention(), backingField);

            yield break;
        }
        /// <inheritdoc />
        public override IEnumerable <PipelineWorkUnit <IntrospectiveMethodInfo> > GenerateImplementation(PipelineWorkUnit <IntrospectiveMethodInfo> workUnit)
        {
            var definition = workUnit.Definition;

            var delegateBuilder = GenerateDelegateType(workUnit);

            // Create a delegate field
            var backingFieldType = delegateBuilder.CreateTypeInfo();

            var backingField = Options.HasFlagFast(UseLazyBinding)
            ? TargetType.DefineField
                               (
                $"{workUnit.GetUniqueBaseMemberName()}_delegate_lazy",
                typeof(Lazy <>).MakeGenericType(backingFieldType),
                FieldAttributes.Private | FieldAttributes.InitOnly
                               )
            : TargetType.DefineField
                               (
                $"{workUnit.GetUniqueBaseMemberName()}_delegate",
                backingFieldType,
                FieldAttributes.Private | FieldAttributes.InitOnly
                               );

            AugmentHostingTypeConstructorWithDelegateInitialization(workUnit.SymbolName, backingFieldType, backingField);
            GenerateDelegateInvokerBody(definition, backingFieldType, backingField);

            yield break;
        }
        /// <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.
        }
Example #4
0
        /// <inheritdoc />
        public override IntrospectiveMethodInfo GenerateImplementationForDefinition(IntrospectiveMethodInfo definition, string symbolName, string uniqueMemberIdentifier)
        {
            var metadataAttribute = definition.GetCustomAttribute <NativeSymbolAttribute>() ??
                                    new NativeSymbolAttribute(definition.Name);

            if (Options.HasFlagFast(UseIndirectCalls))
            {
                var backingFieldType = typeof(IntPtr);

                var backingField = Options.HasFlagFast(UseLazyBinding)
                ? TargetType.DefineField
                                   (
                    $"{uniqueMemberIdentifier}_ptr_lazy",
                    typeof(Lazy <>).MakeGenericType(backingFieldType),
                    FieldAttributes.Private | FieldAttributes.InitOnly
                                   )
                : TargetType.DefineField
                                   (
                    $"{uniqueMemberIdentifier}_ptr",
                    backingFieldType,
                    FieldAttributes.Private | FieldAttributes.InitOnly
                                   );

                AugmentHostingTypeConstructorWithNativeInitialization(symbolName, backingFieldType, backingField);
                GenerateNativeInvokerBody(definition, metadataAttribute.CallingConvention, backingFieldType, backingField);
            }
            else
            {
                var delegateBuilder = GenerateDelegateType(definition, uniqueMemberIdentifier, metadataAttribute.CallingConvention);

                // Create a delegate field
                var backingFieldType = delegateBuilder.CreateTypeInfo();

                var backingField = Options.HasFlagFast(UseLazyBinding)
                ? TargetType.DefineField
                                   (
                    $"{uniqueMemberIdentifier}_delegate_lazy",
                    typeof(Lazy <>).MakeGenericType(backingFieldType),
                    FieldAttributes.Private | FieldAttributes.InitOnly
                                   )
                : TargetType.DefineField
                                   (
                    $"{uniqueMemberIdentifier}_delegate",
                    backingFieldType,
                    FieldAttributes.Private | FieldAttributes.InitOnly
                                   );

                AugmentHostingTypeConstructorWithDelegateInitialization(symbolName, backingFieldType, backingField);
                GenerateDelegateInvokerBody(definition, backingFieldType, backingField);
            }

            return(definition);
        }
        /// <inheritdoc />
        public override IntrospectiveMethodInfo GenerateImplementationForDefinition(IntrospectiveMethodInfo definition, string symbolName, string uniqueMemberIdentifier)
        {
            var metadataAttribute = definition.GetCustomAttribute <NativeSymbolAttribute>() ??
                                    new NativeSymbolAttribute(definition.Name);

            var delegateBuilder = GenerateDelegateType(definition, uniqueMemberIdentifier, metadataAttribute.CallingConvention);

            // Create a delegate field
            var delegateBuilderType = delegateBuilder.CreateTypeInfo();

            var delegateField = Options.HasFlagFast(UseLazyBinding) ?
                                TargetType.DefineField($"{uniqueMemberIdentifier}_dtm", typeof(Lazy <>).MakeGenericType(delegateBuilderType), FieldAttributes.Public) :
                                TargetType.DefineField($"{uniqueMemberIdentifier}_dtm", delegateBuilderType, FieldAttributes.Public);

            AugmentHostingTypeConstructor(symbolName, delegateBuilderType, delegateField);

            GenerateDelegateInvokerBody(definition, delegateBuilderType, delegateField);
            return(definition);
        }
Example #6
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;
        }