هل من الممكن تنفيذ واجهة COM مع فئة الأدوية العامة .NET؟

StackOverflow https://stackoverflow.com/questions/134633

  •  02-07-2019
  •  | 
  •  

سؤال

لدي الواجهة التالية التي أحاول جعل COM مرئيًا.عندما أحاول إنشاء مكتبة النوع، لا أحب حقيقة أن فئة التنفيذ الخاصة بي مستمدة من فئة عامة.

هل من الممكن استخدام فئة عامة كفئة تنفيذ COM؟(أعلم أنه يمكنني كتابة غلاف غير عام وتصديره إلى COM، لكن هذا يضيف طبقة أخرى أفضل الاستغناء عنها.)

[ComVisible(true)]
public interface IMyClass
{
   ...
}

[ComVisible(true), ComDefaultInterface(typeof(IMyClass))]
[ClassInterface(ClassInterfaceType.None)]
public class MyClass : BaseClass<IMyClass>, IMyClass
{
   ...
} 

رسالة خطأ:

Warning: Type library exporter encountered a type that derives 
from a generic class and is not marked as 
[ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot
be exposed for such types. Consider marking the type with 
[ClassInterface(ClassInterfaceType.None)] 
and exposing an explicit interface as the default interface to 
COM using the ComDefaultInterface attribute.
هل كانت مفيدة؟

المحلول

لا يمكن تصدير الأنواع العامة والأنواع المشتقة من نوع عام.تعيين ComVisible(false) على الخاص بك MyClass يكتب.ستحتاج إما إلى إنشاء تطبيق فئة غير عام أو استخدام الواجهة فقط.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top