Example #1
0
        /// <summary>
        /// Mark all eachable items in argument as such.
        /// </summary>
        private static void Walk(ReachableContext context, CustomAttribute attr)
        {
            // Attribute ctor
            MethodReference ctor = attr.Constructor;

            ctor.MarkReachable(context);
            TypeReference declType = ctor.DeclaringType;

            // Try to resolve attribute
            // Ctor parameters
            if (ctor.HasParameters)
            {
                int paramCount = ctor.Parameters.Count;
                for (int i = 0; i < paramCount; i++)
                {
                    if (ctor.Parameters[i].ParameterType.FullName == "System.Type")
                    {
                        var type = (TypeReference)attr.ConstructorArguments[i].Value;
                        type.MarkReachable(context);
                    }
                }
            }

            // Fields
            foreach (var arg in attr.Fields)
            {
                arg.Argument.Type.MarkReachable(context);
                declType.MarkFieldsReachable(arg.Name, context);
                if (arg.Argument.Type.FullName == "System.Type")
                {
                    var type = (TypeReference)arg.Argument.Value;
                    type.MarkReachable(context);
                }
            }

            // Properties
            foreach (var arg in attr.Properties)
            {
                arg.Argument.Type.MarkReachable(context);
                declType.MarkPropertiesReachable(arg.Name, context);
                if (arg.Argument.Type.FullName == "System.Type")
                {
                    var type = (TypeReference)arg.Argument.Value;
                    type.MarkReachable(context);
                }
            }
        }