• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IndexerDeclaration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IndexerDeclaration的典型用法代码示例。如果您正苦于以下问题:C# IndexerDeclaration类的具体用法?C# IndexerDeclaration怎么用?C# IndexerDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IndexerDeclaration类属于命名空间,在下文中一共展示了IndexerDeclaration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AddRange

		/// <summary>
		/// Adds the elements of an array to the end of this IndexerDeclarationCollection.
		/// </summary>
		/// <param name="items">
		/// The array whose elements are to be added to the end of this IndexerDeclarationCollection.
		/// </param>
		public virtual void AddRange(IndexerDeclaration[] items)
		{
			foreach (IndexerDeclaration item in items)
			{
				this.List.Add(item);
			}
		}
开发者ID:uQr,项目名称:NHibernate.Mapping.Attributes,代码行数:13,代码来源:IndexerDeclarationCollection.cs


示例2: EmitIndexerMethod

        protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, Accessor accessor, bool setter)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                XmlToJsDoc.EmitComment(this, this.IndexerDeclaration);
                var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter);

                string name = overloads.GetOverloadName();
                this.Write((setter ? "set" : "get") + name);

                this.EmitMethodParameters(indexerDeclaration.Parameters, indexerDeclaration, setter);

                if (setter)
                {
                    this.Write(", value");
                    this.WriteColon();
                    name = BridgeTypes.ToTypeScriptName(indexerDeclaration.ReturnType, this.Emitter);
                    this.Write(name);
                    this.WriteCloseParentheses();
                    this.WriteColon();
                    this.Write("void");
                }
                else
                {
                    this.WriteColon();
                    name = BridgeTypes.ToTypeScriptName(indexerDeclaration.ReturnType, this.Emitter);
                    this.Write(name);
                }

                this.WriteSemiColon();
                this.WriteNewLine();
            }
        }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:33,代码来源:IndexerBlock.cs


示例3: AddImplementation

        static void AddImplementation(RefactoringContext context, TypeDeclaration result, ICSharpCode.NRefactory.TypeSystem.IType guessedType)
        {
            foreach (var property in guessedType.GetProperties ()) {
                if (!property.IsAbstract)
                    continue;
                if (property.IsIndexer) {
                    var indexerDecl = new IndexerDeclaration() {
                        ReturnType = context.CreateShortType(property.ReturnType),
                        Modifiers = GetModifiers(property),
                        Name = property.Name
                    };
                    indexerDecl.Parameters.AddRange(ConvertParameters(context, property.Parameters));
                    if (property.CanGet)
                        indexerDecl.Getter = new Accessor();
                    if (property.CanSet)
                        indexerDecl.Setter = new Accessor();
                    result.AddChild(indexerDecl, Roles.TypeMemberRole);
                    continue;
                }
                var propDecl = new PropertyDeclaration() {
                    ReturnType = context.CreateShortType(property.ReturnType),
                    Modifiers = GetModifiers (property),
                    Name = property.Name
                };
                if (property.CanGet)
                    propDecl.Getter = new Accessor();
                if (property.CanSet)
                    propDecl.Setter = new Accessor();
                result.AddChild(propDecl, Roles.TypeMemberRole);
            }

            foreach (var method in guessedType.GetMethods ()) {
                if (!method.IsAbstract)
                    continue;
                var decl = new MethodDeclaration() {
                    ReturnType = context.CreateShortType(method.ReturnType),
                    Modifiers = GetModifiers (method),
                    Name = method.Name,
                    Body = new BlockStatement() {
                        new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")))
                    }
                };
                decl.Parameters.AddRange(ConvertParameters(context, method.Parameters));
                result.AddChild(decl, Roles.TypeMemberRole);
            }

            foreach (var evt in guessedType.GetEvents ()) {
                if (!evt.IsAbstract)
                    continue;
                var decl = new EventDeclaration() {
                    ReturnType = context.CreateShortType(evt.ReturnType),
                    Modifiers = GetModifiers (evt),
                    Name = evt.Name
                };
                result.AddChild(decl, Roles.TypeMemberRole);
            }
        }
开发者ID:Xiaoqing,项目名称:NRefactory,代码行数:57,代码来源:CreateClassDeclarationAction.cs


示例4: Create

        public static OverloadsCollection Create(IEmitter emitter, IndexerDeclaration indexerDeclaration, bool isSetter = false)
        {
            string key = indexerDeclaration.GetHashCode().ToString() + isSetter.GetHashCode().ToString();
            if (emitter.OverloadsCache.ContainsKey(key))
            {
                return emitter.OverloadsCache[key];
            }

            return new OverloadsCollection(emitter, indexerDeclaration, isSetter);
        }
开发者ID:yindongfei,项目名称:bridge.lua,代码行数:10,代码来源:OverloadsCollection.cs


示例5: EmitIndexerMethod

        protected virtual void EmitIndexerMethod(IndexerDeclaration indexerDeclaration, Accessor accessor, bool setter)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                this.EnsureComma();

                this.ResetLocals();

                var prevMap = this.BuildLocalsMap();
                var prevNamesMap = this.BuildLocalsNamesMap();

                if (setter)
                {
                    this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration { Name = "value" } }, accessor.Body);
                }

                XmlToJsDoc.EmitComment(this, this.IndexerDeclaration);
                var overloads = OverloadsCollection.Create(this.Emitter, indexerDeclaration, setter);

                string name = overloads.GetOverloadName();
                this.Write((setter ? "set" : "get") + name);
                this.WriteColon();
                this.WriteFunction();
                this.EmitMethodParameters(indexerDeclaration.Parameters, indexerDeclaration, setter);

                if (setter)
                {
                    this.Write(", value)");
                }
                this.WriteSpace();

                var script = this.Emitter.GetScript(accessor);

                if (script == null)
                {
                    accessor.Body.AcceptVisitor(this.Emitter);
                }
                else
                {
                    this.BeginBlock();

                    foreach (var line in script)
                    {
                        this.Write(line);
                        this.WriteNewLine();
                    }

                    this.EndBlock();
                }

                this.ClearLocalsMap(prevMap);
                this.ClearLocalsNamesMap(prevNamesMap);
                this.Emitter.Comma = true;
            }
        }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:55,代码来源:VisitorIndexerBlock.cs


示例6: VisitIndexerDeclaration

			public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
			{
				if (indexerDeclaration.Modifiers.HasFlag(Modifiers.Override)) {
					var rr = ctx.Resolve (indexerDeclaration) as MemberResolveResult;
					if (rr == null)
						return;
					var baseType = rr.Member.DeclaringType.DirectBaseTypes.FirstOrDefault (t => t.Kind != TypeKind.Interface);
					var method = baseType != null ? baseType.GetProperties (m => m.IsIndexer && m.IsOverridable && m.Parameters.Count == indexerDeclaration.Parameters.Count).FirstOrDefault () : null;
					if (method == null)
						return;
					int i = 0;
					foreach (var par in indexerDeclaration.Parameters) {
						if (method.Parameters[i++].Name != par.Name) {
							par.AcceptVisitor (this);
						}
					}
					return;
				}
				base.VisitIndexerDeclaration(indexerDeclaration);
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:20,代码来源:InconsistentNamingIssue.cs


示例7: VisitIndexerDeclaration

        public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
        {
            var resolveResult = _resolver.Resolve(indexerDeclaration);
            if (!(resolveResult is MemberResolveResult)) {
                _errorReporter.Region = indexerDeclaration.GetRegion();
                _errorReporter.InternalError("Event declaration " + indexerDeclaration.Name + " does not resolve to a member.");
                return;
            }

            var prop = ((MemberResolveResult)resolveResult).Member as IProperty;
            if (prop == null) {
                _errorReporter.Region = indexerDeclaration.GetRegion();
                _errorReporter.InternalError("Event declaration " + indexerDeclaration.Name + " does not resolve to a property (resolves to " + resolveResult.ToString() + ")");
                return;
            }

            var jsClass = GetJsClass(prop.DeclaringTypeDefinition);
            if (jsClass == null)
                return;

            var impl = _metadataImporter.GetPropertySemantics(prop);

            switch (impl.Type) {
                case PropertyScriptSemantics.ImplType.GetAndSetMethods: {
                    if (!indexerDeclaration.Getter.IsNull)
                        MaybeCompileAndAddMethodToType(jsClass, indexerDeclaration.Getter, indexerDeclaration.Getter.Body, prop.Getter, impl.GetMethod);
                    if (!indexerDeclaration.Setter.IsNull)
                        MaybeCompileAndAddMethodToType(jsClass, indexerDeclaration.Setter, indexerDeclaration.Setter.Body, prop.Setter, impl.SetMethod);
                    break;
                }
                case PropertyScriptSemantics.ImplType.NotUsableFromScript:
                    break;
                default:
                    throw new InvalidOperationException("Invalid indexer implementation type " + impl.Type);
            }
        }
开发者ID:jack128,项目名称:SaltarelleCompiler,代码行数:36,代码来源:Compiler.cs


示例8: Visit

			public override void Visit (Indexer indexer)
			{
				IndexerDeclaration newIndexer = new IndexerDeclaration ();
				
				var location = LocationsBag.GetMemberLocation (indexer);
				AddModifiers (newIndexer, location);
				
				newIndexer.AddChild ((INode)indexer.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
				
				if (location != null)
					newIndexer.AddChild (new CSharpTokenNode (Convert (location[0]), 1), IndexerDeclaration.Roles.LBracket);
				AddParameter (newIndexer, indexer.Parameters);
				if (location != null)
					newIndexer.AddChild (new CSharpTokenNode (Convert (location[1]), 1), IndexerDeclaration.Roles.RBracket);
				
				if (location != null)
					newIndexer.AddChild (new CSharpTokenNode (Convert (location[2]), 1), IndexerDeclaration.Roles.LBrace);
				if (indexer.Get != null) {
					MonoDevelop.CSharp.Dom.Accessor getAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
					var getLocation = LocationsBag.GetMemberLocation (indexer.Get);
					AddModifiers (getAccessor, getLocation);
					if (getLocation != null)
						getAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Get.Location), "get".Length), PropertyDeclaration.Roles.Keyword);
					if (indexer.Get.Block != null) {
						getAccessor.AddChild ((INode)indexer.Get.Block.Accept (this), MethodDeclaration.Roles.Body);
					} else {
						if (getLocation != null && getLocation.Count > 0)
							newIndexer.AddChild (new CSharpTokenNode (Convert (getLocation[0]), 1), MethodDeclaration.Roles.Semicolon);
					}
					newIndexer.AddChild (getAccessor, PropertyDeclaration.PropertyGetRole);
				}
				
				if (indexer.Set != null) {
					MonoDevelop.CSharp.Dom.Accessor setAccessor = new MonoDevelop.CSharp.Dom.Accessor ();
					var setLocation = LocationsBag.GetMemberLocation (indexer.Set);
					AddModifiers (setAccessor, setLocation);
					if (setLocation != null)
						setAccessor.AddChild (new CSharpTokenNode (Convert (indexer.Set.Location), "set".Length), PropertyDeclaration.Roles.Keyword);
					
					if (indexer.Set.Block != null) {
						setAccessor.AddChild ((INode)indexer.Set.Block.Accept (this), MethodDeclaration.Roles.Body);
					} else {
						if (setLocation != null && setLocation.Count > 0)
							newIndexer.AddChild (new CSharpTokenNode (Convert (setLocation[0]), 1), MethodDeclaration.Roles.Semicolon);
					}
					newIndexer.AddChild (setAccessor, PropertyDeclaration.PropertySetRole);
				}
				
				if (location != null)
					newIndexer.AddChild (new CSharpTokenNode (Convert (location[3]), 1), IndexerDeclaration.Roles.RBrace);
				
				typeStack.Peek ().AddChild (newIndexer, TypeDeclaration.Roles.Member);
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:53,代码来源:CSharpParser.cs


示例9: IndexOf

 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this IndexerDeclarationCollection
 /// </summary>
 /// <param name="value">
 /// The IndexerDeclaration value to locate in the IndexerDeclarationCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(IndexerDeclaration value)
 {
     return this.List.IndexOf(value);
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:15,代码来源:IndexerDeclarationCollection.cs


示例10: VisitIndexerDeclaration

			public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
			{
				FindIssuesInNode(indexerDeclaration.Setter, indexerDeclaration.Setter.Body);
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:4,代码来源:ValueParameterUnusedIssue.cs


示例11: Visit

			public override void Visit(Indexer i)
			{
				var newIndexer = new IndexerDeclaration();
				AddAttributeSection(newIndexer, i);
				var location = LocationsBag.GetMemberLocation(i);
				AddModifiers(newIndexer, location);
				newIndexer.AddChild(ConvertToType(i.TypeExpression), Roles.Type);
				AddExplicitInterface(newIndexer, i.MemberName);
				var name = i.MemberName;
				newIndexer.AddChild(new CSharpTokenNode(Convert(name.Location), IndexerDeclaration.ThisKeywordRole), IndexerDeclaration.ThisKeywordRole);
				
				if (location != null && location.Count > 0)
					newIndexer.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LBracket), Roles.LBracket);
				AddParameter(newIndexer, i.ParameterInfo);
				if (location != null && location.Count > 1)
					newIndexer.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RBracket), Roles.RBracket);
				
				if (location != null && location.Count > 2)
					newIndexer.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.LBrace), Roles.LBrace);
				if (i.Get != null) {
					var getAccessor = new Accessor();
					var getLocation = LocationsBag.GetMemberLocation(i.Get);
					AddAttributeSection(getAccessor, i.Get);
					AddModifiers(getAccessor, getLocation);
					if (getLocation != null)
						getAccessor.AddChild(new CSharpTokenNode(Convert(i.Get.Location), PropertyDeclaration.GetKeywordRole), PropertyDeclaration.GetKeywordRole);
					if (i.Get.Block != null) {
						getAccessor.AddChild((BlockStatement)i.Get.Block.Accept(this), Roles.Body);
					} else {
						if (getLocation != null && getLocation.Count > 0)
							newIndexer.AddChild(new CSharpTokenNode(Convert(getLocation [0]), Roles.Semicolon), Roles.Semicolon);
					}
					newIndexer.AddChild(getAccessor, PropertyDeclaration.GetterRole);
				}
				
				if (i.Set != null) {
					var setAccessor = new Accessor();
					var setLocation = LocationsBag.GetMemberLocation(i.Set);
					AddAttributeSection(setAccessor, i.Set);
					AddModifiers(setAccessor, setLocation);
					if (setLocation != null)
						setAccessor.AddChild(new CSharpTokenNode(Convert(i.Set.Location), PropertyDeclaration.SetKeywordRole), PropertyDeclaration.SetKeywordRole);
					
					if (i.Set.Block != null) {
						setAccessor.AddChild((BlockStatement)i.Set.Block.Accept(this), Roles.Body);
					} else {
						if (setLocation != null && setLocation.Count > 0)
							newIndexer.AddChild(new CSharpTokenNode(Convert(setLocation [0]), Roles.Semicolon), Roles.Semicolon);
					}
					newIndexer.AddChild(setAccessor, PropertyDeclaration.SetterRole);
				}
				
				if (location != null) {
					if (location.Count > 3)
						newIndexer.AddChild(new CSharpTokenNode(Convert(location [3]), Roles.RBrace), Roles.RBrace);
				} else {
					// parser error, set end node to max value.
					newIndexer.AddChild(new ErrorNode(), Roles.Error);
				}
				typeStack.Peek().AddChild(newIndexer, Roles.TypeMemberRole);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:61,代码来源:CSharpParser.cs


示例12: GetActions

        public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
        {
            var indexer = context.GetNode<IndexerExpression>();
            if (indexer == null)
                yield break;
            if (!(context.Resolve(indexer).IsError))
                yield break;

            var state = context.GetResolverStateBefore(indexer);
            if (state.CurrentTypeDefinition == null)
                yield break;
            var guessedType = CreateFieldAction.GuessAstType(context, indexer);

            bool createInOtherType = false;
            ResolveResult targetResolveResult = null;
            targetResolveResult = context.Resolve(indexer.Target);
            createInOtherType = !state.CurrentTypeDefinition.Equals(targetResolveResult.Type.GetDefinition());

            bool isStatic;
            if (createInOtherType) {
                if (targetResolveResult.Type.GetDefinition() == null || targetResolveResult.Type.GetDefinition().Region.IsEmpty)
                    yield break;
                isStatic = targetResolveResult is TypeResolveResult;
                if (isStatic && targetResolveResult.Type.Kind == TypeKind.Interface || targetResolveResult.Type.Kind == TypeKind.Enum)
                    yield break;
            } else {
                isStatic = indexer.Target is IdentifierExpression && state.CurrentMember.IsStatic;
            }

            yield return new CodeAction(context.TranslateString("Create indexer"), script => {
                var decl = new IndexerDeclaration() {
                    ReturnType = guessedType,
                    Getter = new Accessor() {
                        Body = new BlockStatement() {
                            new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")))
                        }
                    },
                    Setter = new Accessor() {
                        Body = new BlockStatement() {
                            new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")))
                        }
                    },
                };
                decl.Parameters.AddRange(CreateMethodDeclarationAction.GenerateParameters(context, indexer.Arguments));
                if (isStatic)
                    decl.Modifiers |= Modifiers.Static;

                if (createInOtherType) {
                    if (targetResolveResult.Type.Kind == TypeKind.Interface) {
                        decl.Getter.Body = null;
                        decl.Setter.Body = null;
                        decl.Modifiers = Modifiers.None;
                    } else {
                        decl.Modifiers |= Modifiers.Public;
                    }

                    script.InsertWithCursor(context.TranslateString("Create indexer"), targetResolveResult.Type.GetDefinition(), (s, c) => decl);
                    return;
                }

                script.InsertWithCursor(context.TranslateString("Create indexer"), Script.InsertPosition.Before, decl);
            }, indexer);
        }
开发者ID:porcus,项目名称:NRefactory,代码行数:63,代码来源:CreateIndexerAction.cs


示例13: VisitIndexerDeclaration

			public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
			{
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:3,代码来源:CS0127ReturnMustNotBeFollowedByAnyExpression.cs


示例14: Add

 /// <summary>
 /// Adds an instance of type IndexerDeclaration to the end of this IndexerDeclarationCollection.
 /// </summary>
 /// <param name="value">
 /// The IndexerDeclaration to be added to the end of this IndexerDeclarationCollection.
 /// </param>
 public virtual void Add(IndexerDeclaration value)
 {
     this.List.Add(value);
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:10,代码来源:IndexerDeclarationCollection.cs


示例15: ConvertPropertyToIndexer

		IndexerDeclaration ConvertPropertyToIndexer(PropertyDeclaration astProp, PropertyDefinition propDef)
		{
			var astIndexer = new IndexerDeclaration();
			astIndexer.Name = astProp.Name;
			astIndexer.CopyAnnotationsFrom(astProp);
			astProp.Attributes.MoveTo(astIndexer.Attributes);
			astIndexer.Modifiers = astProp.Modifiers;
			astIndexer.PrivateImplementationType = astProp.PrivateImplementationType.Detach();
			astIndexer.ReturnType = astProp.ReturnType.Detach();
			astIndexer.Getter = astProp.Getter.Detach();
			astIndexer.Setter = astProp.Setter.Detach();
			astIndexer.Parameters.AddRange(MakeParameters(propDef.Parameters));
			return astIndexer;
		}
开发者ID:eldersantos,项目名称:ILSpy,代码行数:14,代码来源:AstBuilder.cs


示例16: IndexerDeclarationCollection

 /// <summary>
 /// Initializes a new instance of the IndexerDeclarationCollection class, containing elements
 /// copied from an array.
 /// </summary>
 /// <param name="items">
 /// The array whose elements are to be added to the new IndexerDeclarationCollection.
 /// </param>
 public IndexerDeclarationCollection(IndexerDeclaration[] items)
 {
     this.AddRange(items);
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:11,代码来源:IndexerDeclarationCollection.cs


示例17: Remove

 /// <summary>
 /// Removes the first occurrence of a specific IndexerDeclaration from this IndexerDeclarationCollection.
 /// </summary>
 /// <param name="value">
 /// The IndexerDeclaration value to remove from this IndexerDeclarationCollection.
 /// </param>
 public virtual void Remove(IndexerDeclaration value)
 {
     this.List.Remove(value);
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:10,代码来源:IndexerDeclarationCollection.cs


示例18: Insert

 /// <summary>
 /// Inserts an element into the IndexerDeclarationCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the IndexerDeclaration is to be inserted.
 /// </param>
 /// <param name="value">
 /// The IndexerDeclaration to insert.
 /// </param>
 public virtual void Insert(int index, IndexerDeclaration value)
 {
     this.List.Insert(index, value);
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:13,代码来源:IndexerDeclarationCollection.cs


示例19: VisitIndexerDeclaration

        public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
        {
            FixAttributesAndDocComment(indexerDeclaration);

            ForceSpacesBefore(indexerDeclaration.LBracketToken, policy.SpaceBeforeIndexerDeclarationBracket);
            ForceSpacesAfter(indexerDeclaration.LBracketToken, policy.SpaceWithinIndexerDeclarationBracket);

            FormatArguments(indexerDeclaration);

            bool oneLine = false;
            bool fixClosingBrace = false;
            switch (policy.SimplePropertyFormatting) {
                case PropertyFormatting.AllowOneLine:
                    bool isSimple = IsSimpleAccessor(indexerDeclaration.Getter) && IsSimpleAccessor(indexerDeclaration.Setter);
                    int accessorLine = indexerDeclaration.RBraceToken.StartLocation.Line;
                    if (!indexerDeclaration.Getter.IsNull && indexerDeclaration.Setter.IsNull) {
                        accessorLine = indexerDeclaration.Getter.StartLocation.Line;
                    } else if (indexerDeclaration.Getter.IsNull && !indexerDeclaration.Setter.IsNull) {
                        accessorLine = indexerDeclaration.Setter.StartLocation.Line;
                    } else {
                        var acc = indexerDeclaration.Getter.StartLocation < indexerDeclaration.Setter.StartLocation ?
                            indexerDeclaration.Getter : indexerDeclaration.Setter;
                        accessorLine = acc.StartLocation.Line;
                    }
                    if (!isSimple || indexerDeclaration.LBraceToken.StartLocation.Line != accessorLine) {
                        fixClosingBrace = true;
                        FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken);
                    } else {
                        ForceSpacesBefore(indexerDeclaration.Getter, true);
                        ForceSpacesBefore(indexerDeclaration.Setter, true);
                        ForceSpacesBeforeRemoveNewLines(indexerDeclaration.RBraceToken, true);
                        oneLine = true;
                    }
                    break;
                case PropertyFormatting.ForceNewLine:
                    fixClosingBrace = true;
                    FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken);
                    break;
                case PropertyFormatting.ForceOneLine:
                    isSimple = IsSimpleAccessor(indexerDeclaration.Getter) && IsSimpleAccessor(indexerDeclaration.Setter);
                    if (isSimple) {
                        int offset = this.document.GetOffset(indexerDeclaration.LBraceToken.StartLocation);

                        int start = SearchWhitespaceStart(offset);
                        int end = SearchWhitespaceEnd(offset);
                        AddChange(start, offset - start, " ");
                        AddChange(offset + 1, end - offset - 2, " ");

                        offset = this.document.GetOffset(indexerDeclaration.RBraceToken.StartLocation);
                        start = SearchWhitespaceStart(offset);
                        AddChange(start, offset - start, " ");
                        oneLine = true;

                    } else {
                        fixClosingBrace = true;
                        FixOpenBrace(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken);
                    }
                    break;
            }

            if (policy.IndentPropertyBody)
                curIndent.Push(IndentType.Block);

            FormatAccessor(indexerDeclaration.Getter, policy.PropertyGetBraceStyle, policy.SimpleGetBlockFormatting, oneLine);
            FormatAccessor(indexerDeclaration.Setter, policy.PropertySetBraceStyle, policy.SimpleSetBlockFormatting, oneLine);
            if (policy.IndentPropertyBody)
                curIndent.Pop();

            if (fixClosingBrace)
                FixClosingBrace(policy.PropertyBraceStyle, indexerDeclaration.RBraceToken);
        }
开发者ID:porcus,项目名称:NRefactory,代码行数:71,代码来源:FormattingVisitor_TypeMembers.cs


示例20: VisitIndexerDeclaration

		public override void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
		{
			ForceSpacesBefore(indexerDeclaration.LBracketToken, policy.SpaceBeforeIndexerDeclarationBracket);
			ForceSpacesAfter(indexerDeclaration.LBracketToken, policy.SpaceWithinIndexerDeclarationBracket);
			ForceSpacesBefore(indexerDeclaration.RBracketToken, policy.SpaceWithinIndexerDeclarationBracket);

			FormatCommas(indexerDeclaration, policy.SpaceBeforeIndexerDeclarationParameterComma, policy.SpaceAfterIndexerDeclarationParameterComma);

			
			FormatAttributedNode(indexerDeclaration);
			EnforceBraceStyle(policy.PropertyBraceStyle, indexerDeclaration.LBraceToken, indexerDeclaration.RBraceToken);
			if (policy.IndentPropertyBody) {
				curIndent.Push(IndentType.Block);
			}
			
			if (!indexerDeclaration.Getter.IsNull) {
				FixIndentation(indexerDeclaration.Getter.StartLocation);
				if (!indexerDeclaration.Getter.Body.IsNull) {
					if (!policy.AllowPropertyGetBlockInline || indexerDeclaration.Getter.Body.LBraceToken.StartLocation.Line != indexerDeclaration.Getter.Body.RBraceToken.StartLocation.Line) {
						EnforceBraceStyle(policy.PropertyGetBraceStyle, indexerDeclaration.Getter.Body.LBraceToken, indexerDeclaration.Getter.Body.RBraceToken);
					} else {
						nextStatementIndent = " ";
					}
					VisitBlockWithoutFixingBraces(indexerDeclaration.Getter.Body, policy.IndentBlocks);
				}
			}
			
			if (!indexerDeclaration.Setter.IsNull) {
				FixIndentation(indexerDeclaration.Setter.StartLocation);
				if (!indexerDeclaration.Setter.Body.IsNull) {
					if (!policy.AllowPropertySetBlockInline || indexerDeclaration.Setter.Body.LBraceToken.StartLocation.Line != indexerDeclaration.Setter.Body.RBraceToken.StartLocation.Line) {
						EnforceBraceStyle(policy.PropertySetBraceStyle, indexerDeclaration.Setter.Body.LBraceToken, indexerDeclaration.Setter.Body.RBraceToken);
					} else {
						nextStatementIndent = " ";
					}
					VisitBlockWithoutFixingBraces(indexerDeclaration.Setter.Body, policy.IndentBlocks);
				}
			}
			if (policy.IndentPropertyBody) {
				curIndent.Pop ();
			}
			if (IsMember(indexerDeclaration.NextSibling)) {
				EnsureBlankLinesAfter(indexerDeclaration, policy.BlankLinesBetweenMembers);
			}
		}
开发者ID:txdv,项目名称:monodevelop,代码行数:45,代码来源:AstFormattingVisitor.cs



注:本文中的IndexerDeclaration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IndexerExpression类代码示例发布时间:2022-05-24
下一篇:
C# Indexer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap