Exemplo n.º 1
0
        TypeInfo CreateCcwClass(InterfaceInfo interfaceInfo)
        {
            var typeBuilder = moduleBuilder.DefineType(interfaceInfo.Type.FullName + "<CCW>",
                                                       TypeAttributes.Class | TypeAttributes.Sealed |
                                                       TypeAttributes.NotPublic);

            DefineCcwClass(interfaceInfo, typeBuilder);
            return(typeBuilder.CreateTypeInfo());
        }
Exemplo n.º 2
0
        static void DefineRcwClass(InterfaceInfo interfaceInfo, TypeBuilder typeBuilder)
        {
            var type = typeBuilder;

            var nativeObjectType     = typeof(INativeObject <>).GetTypeInfo().MakeGenericType(type);
            var nativeObjectTypeInfo = nativeObjectType.GetTypeInfo();

            typeBuilder.AddInterfaceImplementation(nativeObjectType);

            foreach (var theInterface in interfaceInfo.AllImplementedInterfaces)
            {
                typeBuilder.AddInterfaceImplementation(theInterface);
            }

            FieldInfo interfacePtrField = typeBuilder.DefineField("interfacePtr", typeof(IntPtr), 0);
            FieldInfo unknownPtrField   = typeBuilder.DefineField("iUnknownPtr", typeof(IntPtr), 0);

            // generate constructor
            var ctor = CreateRcwConstructor(typeBuilder, interfacePtrField, unknownPtrField);

            // generate finalizer
            CreateRcwFinalizer(typeBuilder);

            // generate factory
            CreateRcwFactoryMethod(typeBuilder, ctor);

            var methodNameUniqifier = new Utils.UniqueNameGenerator();

            methodNameUniqifier.Uniquify("interfacePtr");
            methodNameUniqifier.Uniquify("iUnknownPtr");
            methodNameUniqifier.Uniquify("Finalize");
            methodNameUniqifier.Uniquify("Create");
            foreach (var method in interfaceInfo.ComMethodInfos)
            {
                CreateRcwMethod(method, typeBuilder, interfacePtrField, methodNameUniqifier);
            }

            // implement INativeObject
            ImplementFieldGetter(typeBuilder, interfacePtrField,
                                 nativeInterfacePtrProp, TypeBuilder.GetMethod(nativeObjectType, nativeInterfacePtrProp.GetMethod),
                                 methodNameUniqifier);
            ImplementFieldGetter(typeBuilder, unknownPtrField,
                                 nativeIUnknownPtrProp, TypeBuilder.GetMethod(nativeObjectType, nativeIUnknownPtrProp.GetMethod),
                                 methodNameUniqifier);
            ImplementInterfaceProperty(typeBuilder,
                                       interfaceProp, TypeBuilder.GetMethod(nativeObjectType, interfaceProp.GetMethod),
                                       methodNameUniqifier);
        }
Exemplo n.º 3
0
        static void DefineCcwClass(InterfaceInfo interfaceInfo, TypeBuilder typeBuilder)
        {
            var type = typeBuilder;

            var uniqifier = new Utils.UniqueNameGenerator();

            uniqifier.Uniquify("Create"); // reserve

            var methods = new List <CcwMethodInfo>();

            foreach (var method in interfaceInfo.ComMethodInfos)
            {
                methods.Add(CreateCcwMethod(method, typeBuilder, uniqifier));
            }

            CreateCcwFactoryMethod(typeBuilder, methods.ToArray(), uniqifier);
        }