Exemple #1
0
 public FieldData(AccessorKind accessor, IFieldSymbol field, SyntaxNode locationNode, bool useFieldLocation)
 {
     AccessorKind     = accessor;
     Field            = field;
     LocationNode     = locationNode;
     UseFieldLocation = useFieldLocation;
 }
        void Format(DmdMethodBase method, DmdPropertyInfo property, AccessorKind accessorKind)
        {
            if (property.SetMethod is null)
            {
                OutputWrite(Keyword_ReadOnly, DbgTextColor.Keyword);
                WriteSpace();
            }

            OutputWrite(Keyword_Property, DbgTextColor.Keyword);
            WriteSpace();

            WriteAccessor(accessorKind);
            WriteToken(method);

            if (DeclaringTypes)
            {
                FormatType(property.DeclaringType !);
                WritePeriod();
            }

            WriteIdentifier(property.Name, TypeFormatterUtils.GetColor(property));
            WriteToken(property);
            WriteGenericArguments(method);
            WriteMethodParameterList(method, MethodParenOpen, MethodParenClose);
            WriteReturnType(method);
            WriteOffset();
        }
Exemple #3
0
        void WriteAccessor(AccessorKind accessorKind)
        {
            string keyword;

            switch (accessorKind)
            {
            case AccessorKind.None:
            default:
                return;

            case AccessorKind.Getter:
                keyword = Keyword_get;
                break;

            case AccessorKind.Setter:
                keyword = Keyword_set;
                break;

            case AccessorKind.Adder:
                keyword = Keyword_add;
                break;

            case AccessorKind.Remover:
                keyword = Keyword_remove;
                break;
            }
            WritePeriod();
            OutputWrite(keyword, BoxedTextColor.Keyword);
        }
Exemple #4
0
 void Format(DmdMethodBase method, DmdPropertyInfo property, AccessorKind accessorKind)
 {
     if (ReturnTypes)
     {
         FormatReturnType(property.PropertyType, TypeFormatterUtils.IsReadOnlyProperty(property));
         WriteSpace();
     }
     if (DeclaringTypes)
     {
         FormatType(property.DeclaringType);
         WritePeriod();
     }
     if (property.GetIndexParameters().Count != 0)
     {
         OutputWrite(Keyword_this, BoxedTextColor.Keyword);
         WriteToken(property);
         WriteMethodParameterListCore(method, GetAllMethodParameterTypes(property.GetMethodSignature()), IndexerParenOpen, IndexerParenClose, showParameterTypes: true, showParameterNames: false, showParameterValues: false);
     }
     else
     {
         WriteIdentifier(property.Name, TypeFormatterUtils.GetColor(property));
         WriteToken(property);
     }
     WriteAccessor(accessorKind);
     WriteToken(method);
     WriteGenericArguments(method);
     WriteMethodParameterList(method, MethodParenOpen, MethodParenClose);
     WriteOffset();
 }
Exemple #5
0
        private static FieldData?ExtractFieldFromExpression(AccessorKind accessorKind,
                                                            ExpressionSyntax expression,
                                                            Compilation compilation)
        {
            var semanticModel = compilation.GetSemanticModel(expression.SyntaxTree);

            if (semanticModel == null)
            {
                return(null);
            }

            var strippedExpression = expression.RemoveParentheses();

            // Check for direct field access: "foo"
            if (strippedExpression is IdentifierNameSyntax &&
                semanticModel.GetSymbolInfo(strippedExpression).Symbol is IFieldSymbol field)
            {
                return(new FieldData(accessorKind, field, strippedExpression));
            }
            else
            {
                // Check for "this.foo"
                if (strippedExpression is MemberAccessExpressionSyntax member &&
                    member.Expression is ThisExpressionSyntax thisExpression &&
                    semanticModel.GetSymbolInfo(strippedExpression).Symbol is IFieldSymbol field2)
                {
                    return(new FieldData(accessorKind, field2, member.Name));
                }
            }

            return(null);
        }
        public static void AppendAccessorKind(this CSharpColorizer colorizer, AccessorKind accessorKind)
        {
            switch (accessorKind)
            {
            case AccessorKind.ADDER:
                colorizer.AppendKeyword("add");
                return;

            case AccessorKind.REMOVER:
                colorizer.AppendKeyword("remove");
                return;

            case AccessorKind.GETTER:
                colorizer.AppendKeyword("get");
                return;

            case AccessorKind.SETTER:
                colorizer.AppendKeyword("set");
                return;

            case AccessorKind.RAISER:
                colorizer.AppendPlainText("fire");
                return;

            case AccessorKind.UNKNOWN:
                colorizer.AppendPlainText("unknown");
                return;
            }
        }
Exemple #7
0
 public InterfaceEventImplementedByNode(EventDef analyzedEvent)
 {
     this.analyzedEvent = analyzedEvent ?? throw new ArgumentNullException(nameof(analyzedEvent));
     if (!(this.analyzedEvent.AddMethod is null))
     {
         analyzedMethod = this.analyzedEvent.AddMethod;
         accessorKind   = AccessorKind.Adder;
     }
 /// <summary>
 /// Creates a new accessor.
 /// </summary>
 /// <param name="parentProperty">
 /// The property in which this accessor is defined.
 /// </param>
 /// <param name="kind">
 /// The accessor's kind.
 /// </param>
 /// <param name="name">
 /// The accessor's name.
 /// </param>
 /// <param name="isStatic">
 /// Tells if the accessor should be a static method
 /// or an instance method.
 /// </param>
 /// <param name="returnType">
 /// The type of value returned by the accessor.
 /// </param>
 public DescribedBodyAccessor(
     IProperty parentProperty,
     AccessorKind kind,
     UnqualifiedName name,
     bool isStatic,
     IType returnType)
     : base(parentProperty, kind, name, isStatic, returnType)
 {
 }
 /// <summary>
 /// Creates a wrapper around an IL accessor definition.
 /// </summary>
 /// <param name="definition">
 /// The method definition to wrap in a Flame accessor.
 /// </param>
 /// <param name="kind">
 /// The kind of definition described by the accessor.
 /// </param>
 /// <param name="parentProperty">
 /// The definition's declaring property.
 /// </param>
 public ClrAccessorDefinition(
     MethodDefinition definition,
     AccessorKind kind,
     ClrPropertyDefinition parentProperty)
     : base(definition, parentProperty.ParentType)
 {
     this.Kind           = kind;
     this.ParentProperty = parentProperty;
 }
Exemple #10
0
 /// <summary>
 /// Creates a new accessor.
 /// </summary>
 /// <param name="parentProperty">
 /// The property in which this accessor is defined.
 /// </param>
 /// <param name="kind">
 /// The accessor's kind.
 /// </param>
 /// <param name="name">
 /// The accessor's name.
 /// </param>
 /// <param name="isStatic">
 /// Tells if the accessor should be a static method
 /// or an instance method.
 /// </param>
 /// <param name="returnType">
 /// The type of value returned by the accessor.
 /// </param>
 public DescribedAccessor(
     IProperty parentProperty,
     AccessorKind kind,
     UnqualifiedName name,
     bool isStatic,
     IType returnType)
     : base(parentProperty.ParentType, name, isStatic, returnType)
 {
     this.Kind           = kind;
     this.ParentProperty = parentProperty;
 }
        private void AssertAccessorCount(int count, AccessorKind accessorKind, string parameterName)
        {
            if (count == 0)
            {
                throw new ArgumentException($"Could not find {accessorKind} accessor", parameterName);
            }

            if (count > 1)
            {
                throw new ArgumentException($"Found more than one {accessorKind} accessor", parameterName);
            }
        }
Exemple #12
0
 void Format(DmdMethodBase method, DmdEventInfo @event, AccessorKind accessorKind)
 {
     if (DeclaringTypes)
     {
         FormatType(@event.DeclaringType);
         WritePeriod();
     }
     WriteIdentifier(@event.Name, TypeFormatterUtils.GetColor(@event));
     WriteToken(@event);
     WriteAccessor(accessorKind);
     WriteToken(method);
     WriteGenericArguments(method);
     WriteMethodParameterList(method, MethodParenOpen, MethodParenClose);
     WriteOffset();
 }
Exemple #13
0
        public ImplementFieldAccessorTask(AccessorKind kind, TypeDefinition type, PropertyDefinition property, string persistentName)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            this.kind           = kind;
            this.type           = type;
            this.property       = property;
            this.persistentName = persistentName;
        }
 public InterfaceEventImplementedByNode(EventDef analyzedEvent)
 {
     this.analyzedEvent = analyzedEvent ?? throw new ArgumentNullException(nameof(analyzedEvent));
     if (this.analyzedEvent.AddMethod is not null)
     {
         analyzedMethod = this.analyzedEvent.AddMethod;
         accessorKind   = AccessorKind.Adder;
     }
     else if (this.analyzedEvent.RemoveMethod is not null)
     {
         analyzedMethod = this.analyzedEvent.RemoveMethod;
         accessorKind   = AccessorKind.Remover;
     }
     else
     {
         analyzedMethod = this.analyzedEvent.InvokeMethod;
         accessorKind   = AccessorKind.Invoker;
     }
 }
        void Format(DmdMethodBase method, DmdEventInfo @event, AccessorKind accessorKind)
        {
            OutputWrite(Keyword_Event, DbgTextColor.Keyword);
            WriteSpace();

            WriteAccessor(accessorKind);
            WriteToken(method);

            if (DeclaringTypes)
            {
                FormatType(@event.DeclaringType !);
                WritePeriod();
            }
            WriteIdentifier(@event.Name, TypeFormatterUtils.GetColor(@event));
            WriteToken(@event);
            WriteSpace();
            OutputWrite(Keyword_As, DbgTextColor.Keyword);
            WriteSpace();
            FormatType(@event.EventHandlerType);
            WriteOffset();
        }
		public static void AppendAccessorKind([NotNull] this CSharpColorizer colorizer, AccessorKind accessorKind) {
			switch (accessorKind) {
				case AccessorKind.ADDER:
					colorizer.AppendKeyword("add");
					return;
				case AccessorKind.REMOVER:
					colorizer.AppendKeyword("remove");
					return;
				case AccessorKind.GETTER:
					colorizer.AppendKeyword("get");
					return;
				case AccessorKind.SETTER:
					colorizer.AppendKeyword("set");
					return;
				case AccessorKind.RAISER:
					colorizer.AppendPlainText("fire");
					return;
				case AccessorKind.UNKNOWN:
					colorizer.AppendPlainText("unknown");
					return;
			}
		}
 public FieldData(AccessorKind accessor, IFieldSymbol field, SyntaxNode locationNode)
 {
     this.AccessorKind = accessor;
     this.Field        = field;
     this.LocationNode = locationNode;
 }
 public static IAccessorDeclaration TryGet(this IEnumerable <IAccessorDeclaration> accessors, AccessorKind kind)
 {
     foreach (var accessor in accessors)
     {
         if (accessor.Kind == kind)
         {
             return(accessor);
         }
     }
     return(null);
 }
        private void AssertAccessorCount(int count, AccessorKind accessorKind, string parameterName)
        {
            if (count == 0)
            {
                throw new ArgumentException(string.Format("Could not find {0} accessor", accessorKind), parameterName);
            }

            if (count > 1)
            {
                throw new ArgumentException(string.Format("Found more than one {0} accessor", accessorKind), parameterName);
            }
        }
 public AccessorDeclarationCompilationResult(AccessorKind kindOfAccesor)
 {
     KindOfAccesor = kindOfAccesor;
 }
 public FieldData(AccessorKind accessor, IFieldSymbol field, SyntaxNode locationNode)
 {
     AccessorKind = accessor;
     Field        = field;
     LocationNode = locationNode;
 }
 private bool HasPublicAccessor(AccessorKind kind) =>
 GetDeclaration()?.AccessorDeclarations.TryGet(kind) is
 {
Exemple #23
0
 private IEnumerable <IFSharpExplicitAccessor> GetAccessors(AccessorKind kind)
 {
     foreach (var declaration in GetDeclarations())
     {
         if (declaration is IMemberDeclaration member &&
             member.AccessorDeclarations.TryGet(kind) is { DeclaredElement: IFSharpExplicitAccessor accessor })