コード例 #1
0
		public ApplyAttributeTask(CompilerContext context, Ast.Attribute attribute, Type type)
		{
			_context = context;
			_attribute = attribute;
			_type = type;
			_targetNode = TargetNode();
		}
コード例 #2
0
 public ApplyAttributeTask(CompilerContext context, Ast.Attribute attribute, Type type)
 {
     _context    = context;
     _attribute  = attribute;
     _type       = type;
     _targetNode = TargetNode();
 }
コード例 #3
0
        public static JToken ToJson(Ast.Attribute a)
        {
            var obj = (JObject)ToJson((SyntaxNode)a);

            obj["type"]  = "Attribute";
            obj["id"]    = ToJson((dynamic)a.Id);
            obj["value"] = ToJson(a.Value);
            return(obj);
        }
コード例 #4
0
 private void CheckAttributeParameters(Ast.Attribute node)
 {
     foreach (var e in node.Arguments)
     {
         if (e.NodeType == NodeType.BinaryExpression && ((BinaryExpression)e).Operator == BinaryOperatorType.Assign)
         {
             Error(node, CompilerErrorFactory.ColonInsteadOfEquals(node));
         }
     }
 }
コード例 #5
0
        private static Type AttributeType(Ast.Attribute node)
        {
            IExternalEntity attr = node.Entity as IExternalEntity;

            if (null == attr)
            {
                return(null);
            }
            return(attr.MemberInfo.DeclaringType);
        }
コード例 #6
0
ファイル: MetadataUtil.cs プロジェクト: richardbang83/GNet
        private static bool IsOfType(Ast.Attribute attribute, IType attributeType)
        {
            var entity = TypeSystemServices.GetEntity(attribute);

            if (entity == attributeType)
            {
                return(true);
            }

            var constructor = entity as IConstructor;

            return(constructor != null && constructor.DeclaringType == attributeType);
        }
コード例 #7
0
        private static AttributeTargets?TargetFor(Ast.Attribute node)
        {
            if (node.ParentNode is Method)
            {
                AttributeCollection returnTypeAttributes = ((Method)node.ParentNode).ReturnTypeAttributes;
                if (returnTypeAttributes.Contains(node))
                {
                    return(AttributeTargets.ReturnValue);
                }
            }
            AttributeTargets target;

            if (NodeUsageTargets().TryGetValue(node.ParentNode.GetType(), out target))
            {
                return(target);
            }
            return(null);
        }
コード例 #8
0
 void ScheduleAttributeApplication(Ast.Attribute attribute, Type type)
 {
     _pendingApplications.Add(new ApplyAttributeTask(Context, attribute, type));
 }
コード例 #9
0
 void Error(Ast.Attribute node, CompilerError error)
 {
     node.Entity = TypeSystemServices.ErrorEntity;
     Errors.Add(error);
 }
コード例 #10
0
        override public void OnAttribute(Ast.Attribute attribute)
        {
            if (null != attribute.Entity)
            {
                return;
            }

            var entity = NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, true))
                         ?? NameResolutionService.ResolveQualifiedName(BuildAttributeName(attribute.Name, false))
                         ?? NameResolutionService.ResolveQualifiedName(attribute.Name);

            if (entity == null)
            {
                var suggestion = NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, true))
                                 ?? NameResolutionService.GetMostSimilarTypeName(BuildAttributeName(attribute.Name, false));

                Error(attribute, CompilerErrorFactory.UnknownAttribute(attribute, attribute.Name, suggestion));
                return;
            }

            if (entity.IsAmbiguous())
            {
                Error(attribute, CompilerErrorFactory.AmbiguousReference(
                          attribute,
                          attribute.Name,
                          ((Ambiguous)entity).Entities));
                return;
            }

            if (EntityType.Type != entity.EntityType)
            {
                Error(attribute, CompilerErrorFactory.NameNotType(attribute, attribute.Name, entity, null));
                return;
            }

            IType attributeType = ((ITypedEntity)entity).Type;

            if (IsAstAttribute(attributeType))
            {
                ExternalType externalType = attributeType as ExternalType;
                if (null == externalType)
                {
                    Error(attribute, CompilerErrorFactory.AstAttributeMustBeExternal(attribute, attributeType));
                }
                else
                {
                    ScheduleAttributeApplication(attribute, externalType.ActualType);
                    RemoveCurrentNode();
                }
            }
            else
            {
                if (!IsSystemAttribute(attributeType))
                {
                    Error(attribute, CompilerErrorFactory.TypeNotAttribute(attribute, attributeType));
                }
                else
                {
                    // remember the attribute's type
                    attribute.Name   = attributeType.FullName;
                    attribute.Entity = entity;
                    CheckAttributeParameters(attribute);
                }
            }
        }
コード例 #11
0
ファイル: AstBuilder.cs プロジェクト: eldersantos/ILSpy
		static Ast.Attribute CreateNonCustomAttribute(Type attributeType, ModuleDefinition module)
		{
			Debug.Assert(attributeType.Name.EndsWith("Attribute", StringComparison.Ordinal));
			Ast.Attribute attr = new Ast.Attribute();
			attr.Type = new SimpleType(attributeType.Name.Substring(0, attributeType.Name.Length - "Attribute".Length));
			if (module != null) {
				attr.Type.AddAnnotation(new TypeReference(attributeType.Namespace, attributeType.Name, module, module.TypeSystem.Corlib));
			}
			return attr;
		}