2 // attribute.cs: Attribute Handler
4 // Author: Ravi Pratap (ravi@ximian.com)
5 // Marek Safar (marek.safar@seznam.cz)
7 // Licensed under the terms of the GNU GPL
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
14 using System.Diagnostics;
15 using System.Collections;
16 using System.Collections.Specialized;
17 using System.Reflection;
18 using System.Reflection.Emit;
19 using System.Runtime.InteropServices;
20 using System.Runtime.CompilerServices;
21 using System.Security;
22 using System.Security.Permissions;
26 namespace Mono.CSharp {
29 /// Base class for objects that can have Attributes applied to them.
31 public abstract class Attributable {
33 /// Attributes for this type
35 protected Attributes attributes;
37 public Attributable (Attributes attrs)
40 OptAttributes = attrs;
43 public Attributes OptAttributes
51 if (attributes != null) {
52 attributes.AttachTo (this);
58 /// Use member-specific procedure to apply attribute @a in @cb to the entity being built in @builder
60 public abstract void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb);
63 /// Returns one AttributeTarget for this element.
65 public abstract AttributeTargets AttributeTargets { get; }
67 public abstract IResolveContext ResolveContext { get; }
69 public abstract bool IsClsComplianceRequired ();
72 /// Gets list of valid attribute targets for explicit target declaration.
73 /// The first array item is default target. Don't break this rule.
75 public abstract string[] ValidAttributeTargets { get; }
78 public class Attribute : Expression
80 public readonly string ExplicitTarget;
81 public AttributeTargets Target;
83 // TODO: remove this member
84 public readonly string Name;
85 public readonly Expression LeftExpr;
86 public readonly string Identifier;
88 ArrayList PosArguments;
89 ArrayList NamedArguments;
92 readonly bool nameEscaped;
94 // It can contain more onwers when the attribute is applied to multiple fiels.
95 protected Attributable[] owners;
97 static readonly AttributeUsageAttribute DefaultUsageAttribute = new AttributeUsageAttribute (AttributeTargets.All);
98 static Assembly orig_sec_assembly;
99 public static readonly object[] EmptyObject = new object [0];
101 // non-null if named args present after Resolve () is called
102 PropertyInfo [] prop_info_arr;
103 FieldInfo [] field_info_arr;
104 object [] field_values_arr;
105 object [] prop_values_arr;
106 object [] pos_values;
108 static PtrHashtable usage_attr_cache;
109 // Cache for parameter-less attributes
110 static PtrHashtable att_cache;
112 public Attribute (string target, Expression left_expr, string identifier, object[] args, Location loc, bool nameEscaped)
114 LeftExpr = left_expr;
115 Identifier = identifier;
116 Name = LeftExpr == null ? identifier : LeftExpr + "." + identifier;
118 PosArguments = (ArrayList)args [0];
119 NamedArguments = (ArrayList)args [1];
122 ExplicitTarget = target;
123 this.nameEscaped = nameEscaped;
131 public static void Reset ()
133 usage_attr_cache = new PtrHashtable ();
134 att_cache = new PtrHashtable ();
137 public virtual void AttachTo (Attributable owner)
139 if (this.owners == null) {
140 this.owners = new Attributable[1] { owner };
144 // When the same attribute is attached to multiple fiels
145 // we use this extra_owners as a list of owners. The attribute
146 // then can be removed because will be emitted when first owner
148 Attributable[] new_array = new Attributable [this.owners.Length + 1];
149 owners.CopyTo (new_array, 0);
150 new_array [owners.Length] = owner;
151 this.owners = new_array;
152 owner.OptAttributes = null;
155 void Error_InvalidNamedArgument (string name)
157 Report.Error (617, Location, "`{0}' is not a valid named attribute argument. Named attribute arguments " +
158 "must be fields which are not readonly, static, const or read-write properties which are " +
159 "public and not static",
163 void Error_InvalidNamedAgrumentType (string name)
165 Report.Error (655, Location, "`{0}' is not a valid named attribute argument because it is not a valid " +
166 "attribute parameter type", name);
169 public static void Error_AttributeArgumentNotValid (Location loc)
171 Report.Error (182, loc,
172 "An attribute argument must be a constant expression, typeof " +
173 "expression or array creation expression");
176 static void Error_TypeParameterInAttribute (Location loc)
179 -202, loc, "Can not use a type parameter in an attribute");
182 public void Error_MissingGuidAttribute ()
184 Report.Error (596, Location, "The Guid attribute must be specified with the ComImport attribute");
187 public void Error_MisusedExtensionAttribute ()
189 Report.Error (1112, Location, "Do not use `{0}' directly. Use parameter modifier `this' instead", GetSignatureForError ());
193 /// This is rather hack. We report many emit attribute error with same error to be compatible with
194 /// csc. But because csc has to report them this way because error came from ilasm we needn't.
196 public void Error_AttributeEmitError (string inner)
198 Report.Error (647, Location, "Error during emitting `{0}' attribute. The reason is `{1}'",
199 TypeManager.CSharpName (Type), inner);
202 public void Error_InvalidSecurityParent ()
204 Error_AttributeEmitError ("it is attached to invalid parent");
213 protected virtual TypeExpr ResolveAsTypeTerminal (Expression expr, IResolveContext ec, bool silent)
215 return expr.ResolveAsTypeTerminal (ec, silent);
218 Type ResolvePossibleAttributeType (string name, bool silent, ref bool is_attr)
220 IResolveContext rc = Owner.ResolveContext;
223 if (LeftExpr == null) {
224 te = ResolveAsTypeTerminal (new SimpleName (name, Location), rc, silent);
226 te = ResolveAsTypeTerminal (new MemberAccess (LeftExpr, name), rc, silent);
233 if (TypeManager.IsSubclassOf (t, TypeManager.attribute_type)) {
235 } else if (!silent) {
236 Report.SymbolRelatedToPreviousError (t);
237 Report.Error (616, Location, "`{0}': is not an attribute class", TypeManager.CSharpName (t));
243 /// Tries to resolve the type of the attribute. Flags an error if it can't, and complain is true.
245 void ResolveAttributeType ()
247 bool t1_is_attr = false;
248 Type t1 = ResolvePossibleAttributeType (Identifier, true, ref t1_is_attr);
250 bool t2_is_attr = false;
251 Type t2 = nameEscaped ? null :
252 ResolvePossibleAttributeType (Identifier + "Attribute", true, ref t2_is_attr);
254 if (t1_is_attr && t2_is_attr) {
255 Report.Error (1614, Location, "`{0}' is ambiguous between `{0}' and `{0}Attribute'. " +
256 "Use either `@{0}' or `{0}Attribute'", GetSignatureForError ());
257 resolve_error = true;
271 if (t1 == null && t2 == null)
272 ResolvePossibleAttributeType (Identifier, false, ref t1_is_attr);
274 ResolvePossibleAttributeType (Identifier, false, ref t1_is_attr);
276 ResolvePossibleAttributeType (Identifier + "Attribute", false, ref t2_is_attr);
278 resolve_error = true;
281 public virtual Type ResolveType ()
283 if (Type == null && !resolve_error)
284 ResolveAttributeType ();
288 public override string GetSignatureForError ()
291 return TypeManager.CSharpName (Type);
293 return LeftExpr == null ? Identifier : LeftExpr.GetSignatureForError () + "." + Identifier;
296 bool IsValidArgumentType (Type t)
299 t = t.GetElementType ();
301 return TypeManager.IsPrimitiveType (t) ||
302 TypeManager.IsEnumType (t) ||
303 t == TypeManager.string_type ||
304 t == TypeManager.object_type ||
305 t == TypeManager.type_type;
308 [Conditional ("GMCS_SOURCE")]
309 void ApplyModuleCharSet ()
311 if (Type != TypeManager.dllimport_type)
314 if (!CodeGen.Module.HasDefaultCharSet)
317 const string CharSetEnumMember = "CharSet";
318 if (NamedArguments == null) {
319 NamedArguments = new ArrayList (1);
321 foreach (DictionaryEntry de in NamedArguments) {
322 if ((string)de.Key == CharSetEnumMember)
327 NamedArguments.Add (new DictionaryEntry (CharSetEnumMember,
328 new Argument (Constant.CreateConstant (typeof (CharSet), CodeGen.Module.DefaultCharSet, Location))));
331 public CustomAttributeBuilder Resolve ()
336 resolve_error = true;
339 ResolveAttributeType ();
344 if (Type.IsAbstract) {
345 Report.Error (653, Location, "Cannot apply attribute class `{0}' because it is abstract", GetSignatureForError ());
349 ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (Type);
350 if (obsolete_attr != null) {
351 AttributeTester.Report_ObsoleteMessage (obsolete_attr, TypeManager.CSharpName (Type), Location);
354 if (PosArguments == null && NamedArguments == null) {
355 object o = att_cache [Type];
357 resolve_error = false;
358 return (CustomAttributeBuilder)o;
362 Attributable owner = Owner;
363 DeclSpace ds = owner.ResolveContext as DeclSpace;
365 ds = owner.ResolveContext.DeclContainer;
367 EmitContext ec = new EmitContext (owner.ResolveContext, ds, owner.ResolveContext.DeclContainer,
368 Location, null, typeof (Attribute), owner.ResolveContext.DeclContainer.ModFlags, false);
369 ec.IsAnonymousMethodAllowed = false;
371 ConstructorInfo ctor = ResolveConstructor (ec);
373 if (Type is TypeBuilder &&
374 TypeManager.LookupDeclSpace (Type).MemberCache == null)
375 // The attribute type has been DefineType'd, but not Defined. Let's not treat it as an error.
376 // It'll be resolved again when the attached-to entity is emitted.
377 resolve_error = false;
381 ApplyModuleCharSet ();
383 CustomAttributeBuilder cb;
385 // SRE does not allow private ctor but we want to report all source code errors
389 if (NamedArguments == null) {
390 cb = new CustomAttributeBuilder (ctor, pos_values);
392 if (pos_values.Length == 0)
393 att_cache.Add (Type, cb);
395 resolve_error = false;
399 if (!ResolveNamedArguments (ec)) {
403 cb = new CustomAttributeBuilder (ctor, pos_values,
404 prop_info_arr, prop_values_arr,
405 field_info_arr, field_values_arr);
407 resolve_error = false;
411 Error_AttributeArgumentNotValid (Location);
416 protected virtual ConstructorInfo ResolveConstructor (EmitContext ec)
418 if (PosArguments != null) {
419 for (int i = 0; i < PosArguments.Count; i++) {
420 Argument a = (Argument) PosArguments [i];
422 if (!a.Resolve (ec, Location))
427 MethodGroupExpr mg = MemberLookupFinal (ec, ec.ContainerType,
428 Type, ".ctor", MemberTypes.Constructor,
429 BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
430 Location) as MethodGroupExpr;
435 mg = mg.OverloadResolve (ec, ref PosArguments, false, Location);
439 ConstructorInfo constructor = (ConstructorInfo)mg;
441 // TODO: move to OverloadResolve
442 ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (constructor);
443 if (oa != null && !Owner.ResolveContext.IsInObsoleteScope) {
444 AttributeTester.Report_ObsoleteMessage (oa, mg.GetSignatureForError (), mg.Location);
447 if (PosArguments == null) {
448 pos_values = EmptyObject;
452 ParameterData pd = TypeManager.GetParameterData (constructor);
454 int pos_arg_count = PosArguments.Count;
455 pos_values = new object [pos_arg_count];
456 for (int j = 0; j < pos_arg_count; ++j) {
457 Argument a = (Argument) PosArguments [j];
459 if (!a.Expr.GetAttributableValue (a.Type, out pos_values [j]))
463 // Here we do the checks which should be done by corlib or by runtime.
464 // However Zoltan doesn't like it and every Mono compiler has to do it again.
466 if (Type == TypeManager.guid_attr_type) {
468 new Guid ((string)pos_values [0]);
470 catch (Exception e) {
471 Error_AttributeEmitError (e.Message);
476 if (Type == TypeManager.attribute_usage_type && (int)pos_values [0] == 0) {
477 Report.Error (591, Location, "Invalid value for argument to `System.AttributeUsage' attribute");
481 if (Type == TypeManager.indexer_name_type || Type == TypeManager.conditional_attribute_type) {
482 if (!Tokenizer.IsValidIdentifier ((string)pos_values [0])) {
483 Report.Error (633, ((Argument)PosArguments[0]).Expr.Location,
484 "The argument to the `{0}' attribute must be a valid identifier", GetSignatureForError ());
489 if (Type == TypeManager.methodimpl_attr_type && pos_values.Length == 1 &&
490 pd.ParameterType (0) == TypeManager.short_type &&
491 !System.Enum.IsDefined (typeof (MethodImplOptions), pos_values [0].ToString ())) {
492 Error_AttributeEmitError ("Incorrect argument value.");
496 return (ConstructorInfo)constructor;
499 protected virtual bool ResolveNamedArguments (EmitContext ec)
501 int named_arg_count = NamedArguments.Count;
503 ArrayList field_infos = new ArrayList (named_arg_count);
504 ArrayList prop_infos = new ArrayList (named_arg_count);
505 ArrayList field_values = new ArrayList (named_arg_count);
506 ArrayList prop_values = new ArrayList (named_arg_count);
508 ArrayList seen_names = new ArrayList(named_arg_count);
510 foreach (DictionaryEntry de in NamedArguments) {
511 string member_name = (string) de.Key;
513 if (seen_names.Contains(member_name)) {
514 Report.Error(643, Location, "'" + member_name + "' duplicate named attribute argument");
517 seen_names.Add(member_name);
519 Argument a = (Argument) de.Value;
520 if (!a.Resolve (ec, Location))
523 Expression member = Expression.MemberLookup (
524 ec.ContainerType, Type, member_name,
525 MemberTypes.Field | MemberTypes.Property,
526 BindingFlags.Public | BindingFlags.Instance,
529 if (member == null) {
530 member = Expression.MemberLookup (ec.ContainerType, Type, member_name,
531 MemberTypes.Field | MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Instance,
534 if (member != null) {
535 Report.SymbolRelatedToPreviousError (member.Type);
536 Expression.ErrorIsInaccesible (Location, member.GetSignatureForError ());
542 Expression.Error_TypeDoesNotContainDefinition (Location, Type, member_name);
546 if (!(member is PropertyExpr || member is FieldExpr)) {
547 Error_InvalidNamedArgument (member_name);
551 if (a.Expr is TypeParameterExpr){
552 Error_TypeParameterInAttribute (Location);
556 ObsoleteAttribute obsolete_attr;
558 if (member is PropertyExpr) {
559 PropertyInfo pi = ((PropertyExpr) member).PropertyInfo;
561 if (!pi.CanWrite || !pi.CanRead) {
562 Report.SymbolRelatedToPreviousError (pi);
563 Error_InvalidNamedArgument (member_name);
567 if (!IsValidArgumentType (pi.PropertyType)) {
568 Report.SymbolRelatedToPreviousError (pi);
569 Error_InvalidNamedAgrumentType (member_name);
574 if (!a.Expr.GetAttributableValue (pi.PropertyType, out value))
577 PropertyBase pb = TypeManager.GetProperty (pi);
579 obsolete_attr = pb.GetObsoleteAttribute ();
581 obsolete_attr = AttributeTester.GetMemberObsoleteAttribute (pi);
583 prop_values.Add (value);
587 FieldInfo fi = ((FieldExpr) member).FieldInfo;
590 Error_InvalidNamedArgument (member_name);
594 if (!IsValidArgumentType (fi.FieldType)) {
595 Report.SymbolRelatedToPreviousError (fi);
596 Error_InvalidNamedAgrumentType (member_name);
601 if (!a.Expr.GetAttributableValue (fi.FieldType, out value))
604 FieldBase fb = TypeManager.GetField (fi);
606 obsolete_attr = fb.GetObsoleteAttribute ();
608 obsolete_attr = AttributeTester.GetMemberObsoleteAttribute (fi);
610 field_values.Add (value);
611 field_infos.Add (fi);
614 if (obsolete_attr != null && !Owner.ResolveContext.IsInObsoleteScope)
615 AttributeTester.Report_ObsoleteMessage (obsolete_attr, member.GetSignatureForError (), member.Location);
618 prop_info_arr = new PropertyInfo [prop_infos.Count];
619 field_info_arr = new FieldInfo [field_infos.Count];
620 field_values_arr = new object [field_values.Count];
621 prop_values_arr = new object [prop_values.Count];
623 field_infos.CopyTo (field_info_arr, 0);
624 field_values.CopyTo (field_values_arr, 0);
626 prop_values.CopyTo (prop_values_arr, 0);
627 prop_infos.CopyTo (prop_info_arr, 0);
633 /// Get a string containing a list of valid targets for the attribute 'attr'
635 public string GetValidTargets ()
637 StringBuilder sb = new StringBuilder ();
638 AttributeTargets targets = GetAttributeUsage (Type).ValidOn;
640 if ((targets & AttributeTargets.Assembly) != 0)
641 sb.Append ("assembly, ");
643 if ((targets & AttributeTargets.Module) != 0)
644 sb.Append ("module, ");
646 if ((targets & AttributeTargets.Class) != 0)
647 sb.Append ("class, ");
649 if ((targets & AttributeTargets.Struct) != 0)
650 sb.Append ("struct, ");
652 if ((targets & AttributeTargets.Enum) != 0)
653 sb.Append ("enum, ");
655 if ((targets & AttributeTargets.Constructor) != 0)
656 sb.Append ("constructor, ");
658 if ((targets & AttributeTargets.Method) != 0)
659 sb.Append ("method, ");
661 if ((targets & AttributeTargets.Property) != 0)
662 sb.Append ("property, indexer, ");
664 if ((targets & AttributeTargets.Field) != 0)
665 sb.Append ("field, ");
667 if ((targets & AttributeTargets.Event) != 0)
668 sb.Append ("event, ");
670 if ((targets & AttributeTargets.Interface) != 0)
671 sb.Append ("interface, ");
673 if ((targets & AttributeTargets.Parameter) != 0)
674 sb.Append ("parameter, ");
676 if ((targets & AttributeTargets.Delegate) != 0)
677 sb.Append ("delegate, ");
679 if ((targets & AttributeTargets.ReturnValue) != 0)
680 sb.Append ("return, ");
683 if ((targets & AttributeTargets.GenericParameter) != 0)
684 sb.Append ("type parameter, ");
686 return sb.Remove (sb.Length - 2, 2).ToString ();
690 /// Returns AttributeUsage attribute based on types hierarchy
692 static AttributeUsageAttribute GetAttributeUsage (Type type)
694 AttributeUsageAttribute ua = usage_attr_cache [type] as AttributeUsageAttribute;
698 Class attr_class = TypeManager.LookupClass (type);
700 if (attr_class == null) {
701 object[] usage_attr = type.GetCustomAttributes (TypeManager.attribute_usage_type, true);
702 ua = (AttributeUsageAttribute)usage_attr [0];
703 usage_attr_cache.Add (type, ua);
708 if (attr_class.OptAttributes != null)
709 a = attr_class.OptAttributes.Search (TypeManager.attribute_usage_type);
712 if (attr_class.TypeBuilder.BaseType != TypeManager.attribute_type)
713 ua = GetAttributeUsage (attr_class.TypeBuilder.BaseType);
715 ua = DefaultUsageAttribute;
717 ua = a.GetAttributeUsageAttribute ();
720 usage_attr_cache.Add (type, ua);
724 AttributeUsageAttribute GetAttributeUsageAttribute ()
726 if (pos_values == null)
727 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
728 // But because a lot of attribute class code must be rewritten will be better to wait...
732 return DefaultUsageAttribute;
734 AttributeUsageAttribute usage_attribute = new AttributeUsageAttribute ((AttributeTargets)pos_values [0]);
736 object field = GetPropertyValue ("AllowMultiple");
738 usage_attribute.AllowMultiple = (bool)field;
740 field = GetPropertyValue ("Inherited");
742 usage_attribute.Inherited = (bool)field;
744 return usage_attribute;
748 /// Returns custom name of indexer
750 public string GetIndexerAttributeValue ()
752 if (pos_values == null)
753 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
754 // But because a lot of attribute class code must be rewritten will be better to wait...
760 return pos_values [0] as string;
764 /// Returns condition of ConditionalAttribute
766 public string GetConditionalAttributeValue ()
768 if (pos_values == null)
769 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
770 // But because a lot of attribute class code must be rewritten will be better to wait...
776 return (string)pos_values [0];
780 /// Creates the instance of ObsoleteAttribute from this attribute instance
782 public ObsoleteAttribute GetObsoleteAttribute ()
784 if (pos_values == null)
785 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
786 // But because a lot of attribute class code must be rewritten will be better to wait...
792 if (pos_values == null || pos_values.Length == 0)
793 return new ObsoleteAttribute ();
795 if (pos_values.Length == 1)
796 return new ObsoleteAttribute ((string)pos_values [0]);
798 return new ObsoleteAttribute ((string)pos_values [0], (bool)pos_values [1]);
802 /// Returns value of CLSCompliantAttribute contructor parameter but because the method can be called
803 /// before ApplyAttribute. We need to resolve the arguments.
804 /// This situation occurs when class deps is differs from Emit order.
806 public bool GetClsCompliantAttributeValue ()
808 if (pos_values == null)
809 // TODO: It is not neccessary to call whole Resolve (ApplyAttribute does it now) we need only ctor args.
810 // But because a lot of attribute class code must be rewritten will be better to wait...
816 return (bool)pos_values [0];
819 public Type GetCoClassAttributeValue ()
821 if (pos_values == null)
827 return (Type)pos_values [0];
830 public bool CheckTarget ()
832 string[] valid_targets = Owner.ValidAttributeTargets;
833 if (ExplicitTarget == null || ExplicitTarget == valid_targets [0]) {
834 Target = Owner.AttributeTargets;
838 // TODO: we can skip the first item
839 if (((IList) valid_targets).Contains (ExplicitTarget)) {
840 switch (ExplicitTarget) {
841 case "return": Target = AttributeTargets.ReturnValue; return true;
842 case "param": Target = AttributeTargets.Parameter; return true;
843 case "field": Target = AttributeTargets.Field; return true;
844 case "method": Target = AttributeTargets.Method; return true;
845 case "property": Target = AttributeTargets.Property; return true;
847 throw new InternalErrorException ("Unknown explicit target: " + ExplicitTarget);
850 StringBuilder sb = new StringBuilder ();
851 foreach (string s in valid_targets) {
855 sb.Remove (sb.Length - 2, 2);
856 Report.Error (657, Location, "`{0}' is not a valid attribute location for this declaration. " +
857 "Valid attribute locations for this declaration are `{1}'", ExplicitTarget, sb.ToString ());
862 /// Tests permitted SecurityAction for assembly or other types
864 public bool CheckSecurityActionValidity (bool for_assembly)
866 SecurityAction action = GetSecurityActionValue ();
869 case SecurityAction.Demand:
870 case SecurityAction.Assert:
871 case SecurityAction.Deny:
872 case SecurityAction.PermitOnly:
873 case SecurityAction.LinkDemand:
874 case SecurityAction.InheritanceDemand:
879 case SecurityAction.RequestMinimum:
880 case SecurityAction.RequestOptional:
881 case SecurityAction.RequestRefuse:
887 Error_AttributeEmitError ("SecurityAction is out of range");
891 Error_AttributeEmitError (String.Concat ("SecurityAction `", action, "' is not valid for this declaration"));
895 System.Security.Permissions.SecurityAction GetSecurityActionValue ()
897 return (SecurityAction)pos_values [0];
901 /// Creates instance of SecurityAttribute class and add result of CreatePermission method to permission table.
903 /// <returns></returns>
904 public void ExtractSecurityPermissionSet (ListDictionary permissions)
906 Type orig_assembly_type = null;
908 if (TypeManager.LookupDeclSpace (Type) != null) {
909 if (!RootContext.StdLib) {
910 orig_assembly_type = Type.GetType (Type.FullName);
912 string orig_version_path = Environment.GetEnvironmentVariable ("__SECURITY_BOOTSTRAP_DB");
913 if (orig_version_path == null) {
914 Error_AttributeEmitError ("security custom attributes can not be referenced from defining assembly");
918 if (orig_sec_assembly == null) {
919 string file = Path.Combine (orig_version_path, Driver.OutputFile);
920 orig_sec_assembly = Assembly.LoadFile (file);
923 orig_assembly_type = orig_sec_assembly.GetType (Type.FullName, true);
924 if (orig_assembly_type == null) {
925 Report.Warning (-112, 1, Location, "Self-referenced security attribute `{0}' " +
926 "was not found in previous version of assembly");
932 SecurityAttribute sa;
933 // For all non-selfreferencing security attributes we can avoid all hacks
934 if (orig_assembly_type == null) {
935 sa = (SecurityAttribute) Activator.CreateInstance (Type, pos_values);
937 if (prop_info_arr != null) {
938 for (int i = 0; i < prop_info_arr.Length; ++i) {
939 PropertyInfo pi = prop_info_arr [i];
940 pi.SetValue (sa, prop_values_arr [i], null);
944 // HACK: All security attributes have same ctor syntax
945 sa = (SecurityAttribute) Activator.CreateInstance (orig_assembly_type, new object[] { GetSecurityActionValue () } );
947 // All types are from newly created assembly but for invocation with old one we need to convert them
948 if (prop_info_arr != null) {
949 for (int i = 0; i < prop_info_arr.Length; ++i) {
950 PropertyInfo emited_pi = prop_info_arr [i];
951 PropertyInfo pi = orig_assembly_type.GetProperty (emited_pi.Name, emited_pi.PropertyType);
953 object old_instance = pi.PropertyType.IsEnum ?
954 System.Enum.ToObject (pi.PropertyType, prop_values_arr [i]) :
957 pi.SetValue (sa, old_instance, null);
963 perm = sa.CreatePermission ();
964 SecurityAction action = GetSecurityActionValue ();
966 // IS is correct because for corlib we are using an instance from old corlib
967 if (!(perm is System.Security.CodeAccessPermission)) {
969 case SecurityAction.Demand:
970 action = (SecurityAction)13;
972 case SecurityAction.LinkDemand:
973 action = (SecurityAction)14;
975 case SecurityAction.InheritanceDemand:
976 action = (SecurityAction)15;
981 PermissionSet ps = (PermissionSet)permissions [action];
983 if (sa is PermissionSetAttribute)
984 ps = new PermissionSet (sa.Unrestricted ? PermissionState.Unrestricted : PermissionState.None);
986 ps = new PermissionSet (PermissionState.None);
988 permissions.Add (action, ps);
989 } else if (!ps.IsUnrestricted () && (sa is PermissionSetAttribute) && sa.Unrestricted) {
990 ps = ps.Union (new PermissionSet (PermissionState.Unrestricted));
991 permissions [action] = ps;
993 ps.AddPermission (perm);
996 static object GetValue (object value)
998 if (value is EnumConstant)
999 return ((EnumConstant) value).GetValue ();
1004 public object GetPropertyValue (string name)
1006 if (prop_info_arr == null)
1009 for (int i = 0; i < prop_info_arr.Length; ++i) {
1010 if (prop_info_arr [i].Name == name)
1011 return prop_values_arr [i];
1017 object GetFieldValue (string name)
1020 if (field_info_arr == null)
1023 foreach (FieldInfo fi in field_info_arr) {
1024 if (fi.Name == name)
1025 return GetValue (field_values_arr [i]);
1032 // Theoretically, we can get rid of this, since FieldBuilder.SetCustomAttribute()
1033 // and ParameterBuilder.SetCustomAttribute() are supposed to handle this attribute.
1034 // However, we can't, since it appears that the .NET 1.1 SRE hangs when given a MarshalAsAttribute.
1036 public UnmanagedMarshal GetMarshal (Attributable attr)
1038 UnmanagedType UnmanagedType;
1039 if (!RootContext.StdLib || pos_values [0].GetType () != typeof (UnmanagedType))
1040 UnmanagedType = (UnmanagedType) System.Enum.ToObject (typeof (UnmanagedType), pos_values [0]);
1042 UnmanagedType = (UnmanagedType) pos_values [0];
1044 object value = GetFieldValue ("SizeParamIndex");
1045 if (value != null && UnmanagedType != UnmanagedType.LPArray) {
1046 Error_AttributeEmitError ("SizeParamIndex field is not valid for the specified unmanaged type");
1050 object o = GetFieldValue ("ArraySubType");
1051 UnmanagedType array_sub_type = o == null ? (UnmanagedType) 0x50 /* NATIVE_MAX */ : (UnmanagedType) o;
1053 switch (UnmanagedType) {
1054 case UnmanagedType.CustomMarshaler: {
1055 MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",
1056 BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
1057 if (define_custom == null) {
1058 Report.RuntimeMissingSupport (Location, "set marshal info");
1062 object [] args = new object [4];
1063 args [0] = GetFieldValue ("MarshalTypeRef");
1064 args [1] = GetFieldValue ("MarshalCookie");
1065 args [2] = GetFieldValue ("MarshalType");
1066 args [3] = Guid.Empty;
1067 return (UnmanagedMarshal) define_custom.Invoke (null, args);
1069 case UnmanagedType.LPArray: {
1070 object size_const = GetFieldValue ("SizeConst");
1071 object size_param_index = GetFieldValue ("SizeParamIndex");
1073 if ((size_const != null) || (size_param_index != null)) {
1074 MethodInfo define_array = typeof (UnmanagedMarshal).GetMethod ("DefineLPArrayInternal",
1075 BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
1076 if (define_array == null) {
1077 Report.RuntimeMissingSupport (Location, "set marshal info");
1081 object [] args = new object [3];
1082 args [0] = array_sub_type;
1083 args [1] = size_const == null ? -1 : size_const;
1084 args [2] = size_param_index == null ? -1 : size_param_index;
1085 return (UnmanagedMarshal) define_array.Invoke (null, args);
1088 return UnmanagedMarshal.DefineLPArray (array_sub_type);
1090 case UnmanagedType.SafeArray:
1091 return UnmanagedMarshal.DefineSafeArray (array_sub_type);
1093 case UnmanagedType.ByValArray:
1094 FieldBase fm = attr as FieldBase;
1096 Error_AttributeEmitError ("Specified unmanaged type is only valid on fields");
1099 return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));
1101 case UnmanagedType.ByValTStr:
1102 return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue ("SizeConst"));
1105 return UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType);
1109 public CharSet GetCharSetValue ()
1111 return (CharSet)System.Enum.Parse (typeof (CharSet), pos_values [0].ToString ());
1114 public bool IsInternalMethodImplAttribute {
1116 if (Type != TypeManager.methodimpl_attr_type)
1119 MethodImplOptions options;
1120 if (pos_values[0].GetType () != typeof (MethodImplOptions))
1121 options = (MethodImplOptions)System.Enum.ToObject (typeof (MethodImplOptions), pos_values[0]);
1123 options = (MethodImplOptions)pos_values[0];
1125 return (options & MethodImplOptions.InternalCall) != 0;
1129 public LayoutKind GetLayoutKindValue ()
1131 if (!RootContext.StdLib || pos_values [0].GetType () != typeof (LayoutKind))
1132 return (LayoutKind)System.Enum.ToObject (typeof (LayoutKind), pos_values [0]);
1134 return (LayoutKind)pos_values [0];
1137 public object GetParameterDefaultValue ()
1139 return pos_values [0];
1142 public override bool Equals (object obj)
1144 Attribute a = obj as Attribute;
1148 return Type == a.Type && Target == a.Target;
1151 public override int GetHashCode ()
1153 return base.GetHashCode ();
1157 /// Emit attribute for Attributable symbol
1159 public void Emit (ListDictionary allEmitted)
1161 CustomAttributeBuilder cb = Resolve ();
1165 AttributeUsageAttribute usage_attr = GetAttributeUsage (Type);
1166 if ((usage_attr.ValidOn & Target) == 0) {
1167 Report.Error (592, Location, "The attribute `{0}' is not valid on this declaration type. " +
1168 "It is valid on `{1}' declarations only",
1169 GetSignatureForError (), GetValidTargets ());
1174 foreach (Attributable owner in owners)
1175 owner.ApplyAttributeBuilder (this, cb);
1177 catch (Exception e) {
1178 Error_AttributeEmitError (e.Message);
1182 if (!usage_attr.AllowMultiple && allEmitted != null) {
1183 if (allEmitted.Contains (this)) {
1184 ArrayList a = allEmitted [this] as ArrayList;
1186 a = new ArrayList (2);
1187 allEmitted [this] = a;
1191 allEmitted.Add (this, null);
1195 if (!RootContext.VerifyClsCompliance)
1198 // Here we are testing attribute arguments for array usage (error 3016)
1199 if (Owner.IsClsComplianceRequired ()) {
1200 if (PosArguments != null) {
1201 foreach (Argument arg in PosArguments) {
1202 // Type is undefined (was error 246)
1203 if (arg.Type == null)
1206 if (arg.Type.IsArray) {
1207 Report.Error (3016, Location, "Arrays as attribute arguments are not CLS-compliant");
1213 if (NamedArguments == null)
1216 foreach (DictionaryEntry de in NamedArguments) {
1217 Argument arg = (Argument) de.Value;
1219 // Type is undefined (was error 246)
1220 if (arg.Type == null)
1223 if (arg.Type.IsArray) {
1224 Report.Error (3016, Location, "Arrays as attribute arguments are not CLS-compliant");
1231 private Expression GetValue ()
1233 if (PosArguments == null || PosArguments.Count < 1)
1236 return ((Argument) PosArguments [0]).Expr;
1239 public string GetString ()
1241 Expression e = GetValue ();
1242 if (e is StringConstant)
1243 return ((StringConstant)e).Value;
1247 public bool GetBoolean ()
1249 Expression e = GetValue ();
1250 if (e is BoolConstant)
1251 return ((BoolConstant)e).Value;
1255 public Type GetArgumentType ()
1257 TypeOf e = GetValue () as TypeOf;
1260 return e.TypeArgument;
1263 public override Expression DoResolve (EmitContext ec)
1265 throw new NotImplementedException ();
1268 public override void Emit (EmitContext ec)
1270 throw new NotImplementedException ();
1276 /// For global attributes (assembly, module) we need special handling.
1277 /// Attributes can be located in the several files
1279 public class GlobalAttribute : Attribute
1281 public readonly NamespaceEntry ns;
1283 public GlobalAttribute (NamespaceEntry ns, string target,
1284 Expression left_expr, string identifier, object[] args, Location loc, bool nameEscaped):
1285 base (target, left_expr, identifier, args, loc, nameEscaped)
1288 this.owners = new Attributable[1];
1291 public override void AttachTo (Attributable owner)
1293 if (ExplicitTarget == "assembly") {
1294 owners [0] = CodeGen.Assembly;
1297 if (ExplicitTarget == "module") {
1298 owners [0] = CodeGen.Module;
1301 throw new NotImplementedException ("Unknown global explicit target " + ExplicitTarget);
1306 // RootContext.ToplevelTypes has a single NamespaceEntry which gets overwritten
1307 // each time a new file is parsed. However, we need to use the NamespaceEntry
1308 // in effect where the attribute was used. Since code elsewhere cannot assume
1309 // that the NamespaceEntry is right, just overwrite it.
1311 // Precondition: RootContext.ToplevelTypes == null
1313 if (RootContext.ToplevelTypes.NamespaceEntry != null)
1314 throw new InternalErrorException (Location + " non-null NamespaceEntry");
1316 RootContext.ToplevelTypes.NamespaceEntry = ns;
1321 RootContext.ToplevelTypes.NamespaceEntry = null;
1324 protected override TypeExpr ResolveAsTypeTerminal (Expression expr, IResolveContext ec, bool silent)
1328 return base.ResolveAsTypeTerminal (expr, ec, silent);
1335 protected override ConstructorInfo ResolveConstructor (EmitContext ec)
1339 return base.ResolveConstructor (ec);
1346 protected override bool ResolveNamedArguments (EmitContext ec)
1350 return base.ResolveNamedArguments (ec);
1358 public class Attributes {
1359 public readonly ArrayList Attrs;
1361 public Attributes (Attribute a)
1363 Attrs = new ArrayList ();
1367 public Attributes (ArrayList attrs)
1372 public void AddAttributes (ArrayList attrs)
1374 Attrs.AddRange (attrs);
1377 public void AttachTo (Attributable attributable)
1379 foreach (Attribute a in Attrs)
1380 a.AttachTo (attributable);
1384 /// Checks whether attribute target is valid for the current element
1386 public bool CheckTargets ()
1388 foreach (Attribute a in Attrs) {
1389 if (!a.CheckTarget ())
1395 public Attribute Search (Type t)
1397 foreach (Attribute a in Attrs) {
1398 if (a.ResolveType () == t)
1405 /// Returns all attributes of type 't'. Use it when attribute is AllowMultiple = true
1407 public Attribute[] SearchMulti (Type t)
1409 ArrayList ar = null;
1411 foreach (Attribute a in Attrs) {
1412 if (a.ResolveType () == t) {
1414 ar = new ArrayList ();
1419 return ar == null ? null : ar.ToArray (typeof (Attribute)) as Attribute[];
1426 ListDictionary ld = Attrs.Count > 1 ? new ListDictionary () : null;
1428 foreach (Attribute a in Attrs)
1431 if (ld == null || ld.Count == 0)
1434 foreach (DictionaryEntry d in ld) {
1435 if (d.Value == null)
1438 foreach (Attribute collision in (ArrayList)d.Value)
1439 Report.SymbolRelatedToPreviousError (collision.Location, "");
1441 Attribute a = (Attribute)d.Key;
1442 Report.Error (579, a.Location, "The attribute `{0}' cannot be applied multiple times",
1443 a.GetSignatureForError ());
1447 public bool Contains (Type t)
1449 return Search (t) != null;
1454 /// Helper class for attribute verification routine.
1456 sealed class AttributeTester
1458 static PtrHashtable analyzed_types;
1459 static PtrHashtable analyzed_types_obsolete;
1460 static PtrHashtable analyzed_member_obsolete;
1461 static PtrHashtable analyzed_method_excluded;
1464 static PtrHashtable fixed_buffer_cache;
1467 static object TRUE = new object ();
1468 static object FALSE = new object ();
1470 static AttributeTester ()
1475 private AttributeTester ()
1479 public static void Reset ()
1481 analyzed_types = new PtrHashtable ();
1482 analyzed_types_obsolete = new PtrHashtable ();
1483 analyzed_member_obsolete = new PtrHashtable ();
1484 analyzed_method_excluded = new PtrHashtable ();
1486 fixed_buffer_cache = new PtrHashtable ();
1490 public enum Result {
1497 /// Returns true if parameters of two compared methods are CLS-Compliant.
1498 /// It tests differing only in ref or out, or in array rank.
1500 public static Result AreOverloadedMethodParamsClsCompliant (Type[] types_a, Type[] types_b)
1502 if (types_a == null || types_b == null)
1505 if (types_a.Length != types_b.Length)
1508 Result result = Result.Ok;
1509 for (int i = 0; i < types_b.Length; ++i) {
1510 Type aType = types_a [i];
1511 Type bType = types_b [i];
1513 if (aType.IsArray && bType.IsArray) {
1514 Type a_el_type = aType.GetElementType ();
1515 Type b_el_type = bType.GetElementType ();
1516 if (aType.GetArrayRank () != bType.GetArrayRank () && a_el_type == b_el_type) {
1517 result = Result.RefOutArrayError;
1521 if (a_el_type.IsArray || b_el_type.IsArray) {
1522 result = Result.ArrayArrayError;
1527 Type aBaseType = aType;
1528 bool is_either_ref_or_out = false;
1530 if (aType.IsByRef || aType.IsPointer) {
1531 aBaseType = aType.GetElementType ();
1532 is_either_ref_or_out = true;
1535 Type bBaseType = bType;
1536 if (bType.IsByRef || bType.IsPointer)
1538 bBaseType = bType.GetElementType ();
1539 is_either_ref_or_out = !is_either_ref_or_out;
1542 if (aBaseType != bBaseType)
1545 if (is_either_ref_or_out)
1546 result = Result.RefOutArrayError;
1552 /// This method tests the CLS compliance of external types. It doesn't test type visibility.
1554 public static bool IsClsCompliant (Type type)
1559 object type_compliance = analyzed_types[type];
1560 if (type_compliance != null)
1561 return type_compliance == TRUE;
1563 if (type.IsPointer) {
1564 analyzed_types.Add (type, null);
1569 if (type.IsArray || type.IsByRef) {
1570 result = IsClsCompliant (TypeManager.GetElementType (type));
1571 } else if (TypeManager.IsNullableType (type)) {
1572 result = IsClsCompliant (TypeManager.GetTypeArguments (type) [0]);
1574 result = AnalyzeTypeCompliance (type);
1576 analyzed_types.Add (type, result ? TRUE : FALSE);
1581 /// Returns IFixedBuffer implementation if field is fixed buffer else null.
1583 public static IFixedBuffer GetFixedBuffer (FieldInfo fi)
1585 // Fixed buffer helper type is generated as value type
1586 if (!fi.FieldType.IsValueType)
1589 FieldBase fb = TypeManager.GetField (fi);
1591 return fb as IFixedBuffer;
1594 if (TypeManager.GetConstant (fi) != null)
1598 object o = fixed_buffer_cache [fi];
1600 if (!fi.IsDefined (TypeManager.fixed_buffer_attr_type, false)) {
1601 fixed_buffer_cache.Add (fi, FALSE);
1605 IFixedBuffer iff = new FixedFieldExternal (fi);
1606 fixed_buffer_cache.Add (fi, iff);
1613 return (IFixedBuffer)o;
1619 public static void VerifyModulesClsCompliance ()
1621 Module[] modules = RootNamespace.Global.Modules;
1622 if (modules == null)
1625 // The first module is generated assembly
1626 for (int i = 1; i < modules.Length; ++i) {
1627 Module module = modules [i];
1628 if (!IsClsCompliant (module)) {
1629 Report.Error (3013, "Added modules must be marked with the CLSCompliant attribute " +
1630 "to match the assembly", module.Name);
1636 public static Type GetImportedIgnoreCaseClsType (string name)
1638 foreach (Assembly a in RootNamespace.Global.Assemblies) {
1639 Type t = a.GetType (name, false, true);
1643 if (IsClsCompliant (t))
1649 static bool IsClsCompliant (ICustomAttributeProvider attribute_provider)
1651 object[] CompliantAttribute = attribute_provider.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
1652 if (CompliantAttribute.Length == 0)
1655 return ((CLSCompliantAttribute)CompliantAttribute[0]).IsCompliant;
1658 static bool AnalyzeTypeCompliance (Type type)
1660 type = TypeManager.DropGenericTypeArguments (type);
1661 DeclSpace ds = TypeManager.LookupDeclSpace (type);
1663 return ds.IsClsComplianceRequired ();
1666 if (TypeManager.IsGenericParameter (type))
1669 object[] CompliantAttribute = type.GetCustomAttributes (TypeManager.cls_compliant_attribute_type, false);
1670 if (CompliantAttribute.Length == 0)
1671 return IsClsCompliant (type.Assembly);
1673 return ((CLSCompliantAttribute)CompliantAttribute[0]).IsCompliant;
1676 // Registers the core type as we assume that they will never be obsolete which
1677 // makes things easier for bootstrap and faster (we don't need to query Obsolete attribute).
1678 public static void RegisterNonObsoleteType (Type type)
1680 analyzed_types_obsolete [type] = FALSE;
1684 /// Returns instance of ObsoleteAttribute when type is obsolete
1686 public static ObsoleteAttribute GetObsoleteAttribute (Type type)
1688 object type_obsolete = analyzed_types_obsolete [type];
1689 if (type_obsolete == FALSE)
1692 if (type_obsolete != null)
1693 return (ObsoleteAttribute)type_obsolete;
1695 ObsoleteAttribute result = null;
1696 if (TypeManager.HasElementType (type)) {
1697 result = GetObsoleteAttribute (TypeManager.GetElementType (type));
1698 } else if (TypeManager.IsGenericParameter (type) || TypeManager.IsGenericType (type))
1701 DeclSpace type_ds = TypeManager.LookupDeclSpace (type);
1703 // Type is external, we can get attribute directly
1704 if (type_ds == null) {
1705 object[] attribute = type.GetCustomAttributes (TypeManager.obsolete_attribute_type, false);
1706 if (attribute.Length == 1)
1707 result = (ObsoleteAttribute)attribute [0];
1709 result = type_ds.GetObsoleteAttribute ();
1713 // Cannot use .Add because of corlib bootstrap
1714 analyzed_types_obsolete [type] = result == null ? FALSE : result;
1719 /// Returns instance of ObsoleteAttribute when method is obsolete
1721 public static ObsoleteAttribute GetMethodObsoleteAttribute (MethodBase mb)
1723 IMethodData mc = TypeManager.GetMethod (mb);
1725 return mc.GetObsoleteAttribute ();
1727 // compiler generated methods are not registered by AddMethod
1728 if (mb.DeclaringType is TypeBuilder)
1731 MemberInfo mi = TypeManager.GetPropertyFromAccessor (mb);
1733 return GetMemberObsoleteAttribute (mi);
1735 mi = TypeManager.GetEventFromAccessor (mb);
1737 return GetMemberObsoleteAttribute (mi);
1739 return GetMemberObsoleteAttribute (mb);
1743 /// Returns instance of ObsoleteAttribute when member is obsolete
1745 public static ObsoleteAttribute GetMemberObsoleteAttribute (MemberInfo mi)
1747 object type_obsolete = analyzed_member_obsolete [mi];
1748 if (type_obsolete == FALSE)
1751 if (type_obsolete != null)
1752 return (ObsoleteAttribute)type_obsolete;
1754 if ((mi.DeclaringType is TypeBuilder) || TypeManager.IsGenericType (mi.DeclaringType))
1757 ObsoleteAttribute oa = System.Attribute.GetCustomAttribute (mi, TypeManager.obsolete_attribute_type, false)
1758 as ObsoleteAttribute;
1759 analyzed_member_obsolete.Add (mi, oa == null ? FALSE : oa);
1764 /// Common method for Obsolete error/warning reporting.
1766 public static void Report_ObsoleteMessage (ObsoleteAttribute oa, string member, Location loc)
1769 Report.Error (619, loc, "`{0}' is obsolete: `{1}'", member, oa.Message);
1773 if (oa.Message == null || oa.Message.Length == 0) {
1774 Report.Warning (612, 1, loc, "`{0}' is obsolete", member);
1777 Report.Warning (618, 2, loc, "`{0}' is obsolete: `{1}'", member, oa.Message);
1780 public static bool IsConditionalMethodExcluded (MethodBase mb)
1782 object excluded = analyzed_method_excluded [mb];
1783 if (excluded != null)
1784 return excluded == TRUE ? true : false;
1786 ConditionalAttribute[] attrs = mb.GetCustomAttributes (TypeManager.conditional_attribute_type, true)
1787 as ConditionalAttribute[];
1788 if (attrs.Length == 0) {
1789 analyzed_method_excluded.Add (mb, FALSE);
1793 foreach (ConditionalAttribute a in attrs) {
1794 if (RootContext.AllDefines.Contains (a.ConditionString)) {
1795 analyzed_method_excluded.Add (mb, FALSE);
1799 analyzed_method_excluded.Add (mb, TRUE);
1804 /// Analyzes class whether it has attribute which has ConditionalAttribute
1805 /// and its condition is not defined.
1807 public static bool IsAttributeExcluded (Type type)
1812 Class class_decl = TypeManager.LookupDeclSpace (type) as Class;
1814 // TODO: add caching
1815 // TODO: merge all Type bases attribute caching to one cache to save memory
1816 if (class_decl == null) {
1817 object[] attributes = type.GetCustomAttributes (TypeManager.conditional_attribute_type, false);
1818 foreach (ConditionalAttribute ca in attributes) {
1819 if (RootContext.AllDefines.Contains (ca.ConditionString))
1822 return attributes.Length > 0;
1825 return class_decl.IsExcluded ();
1828 public static Type GetCoClassAttribute (Type type)
1830 TypeContainer tc = TypeManager.LookupInterface (type);
1832 object[] o = type.GetCustomAttributes (TypeManager.coclass_attr_type, false);
1835 return ((System.Runtime.InteropServices.CoClassAttribute)o[0]).CoClass;
1838 if (tc.OptAttributes == null)
1841 Attribute a = tc.OptAttributes.Search (TypeManager.coclass_attr_type);
1845 return a.GetCoClassAttributeValue ();