Esempio n. 1
0
 internal static bool ClassInterfaceAttributeExists(IEnumerable <object> customAttributes)
 {
     foreach (object item in customAttributes)
     {
         ClassInterfaceAttribute attribute = item as ClassInterfaceAttribute;
         if (null != attribute)
         {
             return(true);
         }
     }
     return(false);
 }
 private static bool HasClassInterface2(Type t)
 {
     object[] customAttributes = t.GetCustomAttributes(typeof(ClassInterfaceAttribute), false);
     if ((customAttributes != null) && (customAttributes.Length > 0))
     {
         ClassInterfaceAttribute attribute = (ClassInterfaceAttribute)customAttributes[0];
         if ((attribute.Value == ClassInterfaceType.AutoDual) || (attribute.Value == ClassInterfaceType.AutoDispatch))
         {
             return(true);
         }
     }
     customAttributes = t.Assembly.GetCustomAttributes(typeof(ClassInterfaceAttribute), true);
     if ((customAttributes != null) && (customAttributes.Length > 0))
     {
         ClassInterfaceAttribute attribute2 = (ClassInterfaceAttribute)customAttributes[0];
         if ((attribute2.Value == ClassInterfaceType.AutoDual) || (attribute2.Value == ClassInterfaceType.AutoDispatch))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 3
0
        public void Ctor_ClassInterfaceType(ClassInterfaceType classInterfaceType)
        {
            var attribute = new ClassInterfaceAttribute(classInterfaceType);

            Assert.Equal(classInterfaceType, attribute.Value);
        }
Esempio n. 4
0
        public void Ctor_ShortClassInterfaceType(short classInterfaceType)
        {
            var attribute = new ClassInterfaceAttribute(classInterfaceType);

            Assert.Equal((ClassInterfaceType)classInterfaceType, attribute.Value);
        }
Esempio n. 5
0
        static string TypeToText(Type t)
        {
            StringBuilder builder = new StringBuilder();

            if (t.IsInterface)
            {
                builder.AppendFormat("[Guid(\"{0}\")]", t.GUID).AppendLine();
                builder.AppendFormat("interface {0}", t.Name).AppendLine();
            }
            else if (t.IsEnum)
            {
                builder.AppendFormat("enum {0}", t.Name).AppendLine();
            }
            else if (t.IsClass)
            {
                builder.AppendFormat("[Guid(\"{0}\")]", t.GUID).AppendLine();
                ClassInterfaceAttribute class_attr = t.GetCustomAttribute <ClassInterfaceAttribute>();
                if (class_attr != null)
                {
                    builder.AppendFormat("[ClassInterface(ClassInterfaceType.{0})]", class_attr.Value).AppendLine();
                }
                builder.AppendFormat("class {0}", t.Name).AppendLine();
            }
            else
            {
                builder.AppendFormat("struct {0}", t.Name).AppendLine();
            }
            builder.AppendLine("{");

            if (t.IsInterface || t.IsClass)
            {
                MethodInfo[] methods = t.GetMethods().Where(m => !m.IsStatic && (m.Attributes & MethodAttributes.SpecialName) == 0).ToArray();
                if (methods.Length > 0)
                {
                    builder.AppendLine("   /* Methods */");

                    Dictionary <MethodInfo, string> name_mapping = new Dictionary <MethodInfo, string>();
                    if (t.IsClass)
                    {
                        name_mapping = MapMethodNamesToCOM(methods);
                    }

                    foreach (MethodInfo mi in methods)
                    {
                        if (name_mapping.ContainsKey(mi) && name_mapping[mi] != mi.Name)
                        {
                            builder.AppendFormat("    /* Exposed as {0} */", name_mapping[mi]).AppendLine();
                        }

                        EmitMember(builder, mi);
                    }
                }

                var props = t.GetProperties().Where(p => !p.GetMethod.IsStatic);
                if (props.Count() > 0)
                {
                    builder.AppendLine("   /* Properties */");
                    foreach (PropertyInfo pi in props)
                    {
                        EmitMember(builder, pi);
                    }
                }
            }
            else if (t.IsEnum)
            {
                foreach (var value in Enum.GetValues(t))
                {
                    builder.Append("   ");
                    try
                    {
                        builder.AppendFormat("{0} = {1};", value, Convert.ToInt64(value));
                    }
                    catch
                    {
                        builder.AppendFormat("{0};");
                    }
                    builder.AppendLine();
                }
            }
            else
            {
                FieldInfo[] fields = t.GetFields();
                if (fields.Length > 0)
                {
                    builder.AppendLine("   /* Fields */");
                    foreach (FieldInfo fi in fields)
                    {
                        EmitMember(builder, fi);
                    }
                }
            }

            builder.AppendLine("}");

            return(builder.ToString());
        }