当前位置: 首页>>代码示例>>C#>>正文


C# AstType类代码示例

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


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

示例1: AddLocal

        public string AddLocal(string name, AstType type)
        {
            this.Emitter.Locals.Add(name, type);

            name = name.StartsWith(Bridge.Translator.Emitter.FIX_ARGUMENT_NAME) ? name.Substring(Bridge.Translator.Emitter.FIX_ARGUMENT_NAME.Length) : name;
            string vName = name;

            if (Helpers.IsReservedWord(name))
            {
                vName = this.GetUniqueName(name);
            }

            if (!this.Emitter.LocalsNamesMap.ContainsKey(name))
            {
                this.Emitter.LocalsNamesMap.Add(name, vName);
            }
            else
            {
                this.Emitter.LocalsNamesMap[name] = this.GetUniqueName(vName);
            }

            var result = this.Emitter.LocalsNamesMap[name];

            if (this.Emitter.IsAsync && !this.Emitter.AsyncVariables.Contains(result))
            {
                this.Emitter.AsyncVariables.Add(result);
            }

            return result;
        }
开发者ID:Cestbienmoi,项目名称:Bridge,代码行数:30,代码来源:AbstractEmitterBlock.Locals.cs

示例2: AddTypeArguments

			void AddTypeArguments (ATypeNameExpression texpr, AstType result)
			{
				if (!texpr.HasTypeArguments)
					return;
				foreach (var arg in texpr.TypeArguments.Args) {
					result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
				}
			}
开发者ID:madkat,项目名称:NRefactory,代码行数:8,代码来源:CSharpParser.cs

示例3: GetDefaultFieldValue

        public static object GetDefaultFieldValue(AstType type, IMemberResolver resolver)
        {
            if (type is PrimitiveType)
            {
                var primitiveType = (PrimitiveType)type;

                switch (primitiveType.KnownTypeCode)
                {
                    case KnownTypeCode.Decimal:
                        return 0m;

                    case KnownTypeCode.Int16:
                    case KnownTypeCode.Int32:
                    case KnownTypeCode.Int64:
                    case KnownTypeCode.UInt16:
                    case KnownTypeCode.UInt32:
                    case KnownTypeCode.UInt64:
                    case KnownTypeCode.Byte:
                    case KnownTypeCode.Double:
                    case KnownTypeCode.SByte:
                    case KnownTypeCode.Single:
                        return 0;

                    case KnownTypeCode.Boolean:
                        return false;
                }
            }

            var resolveResult = resolver.ResolveNode(type, null);

            var o = GetDefaultFieldValue(resolveResult.Type, false);

            if (o != null)
            {
                return o;
            }

            if (!resolveResult.IsError && NullableType.IsNullable(resolveResult.Type))
            {
                return null;
            }

            if (!resolveResult.IsError && resolveResult.Type.IsKnownType(KnownTypeCode.Enum))
            {
                return 0;
            }

            if (!resolveResult.IsError && resolveResult.Type.Kind == TypeKind.Struct)
            {
                return type;
            }

            return null;
        }
开发者ID:TinkerWorX,项目名称:Bridge,代码行数:54,代码来源:Inspector.cs

示例4: GetFieldDeclaration

        protected FieldDeclaration GetFieldDeclaration(String name, AstType propertyType)
        {
            var declaration = new FieldDeclaration();
            declaration.Name = name;
            declaration.Modifiers = Modifiers.Public;
            declaration.ReturnType = propertyType;

            IDELogger.Log("BaseRefactoringDialog::GetFieldDeclaration -- {0}", declaration.Name);

            return declaration;
        }
开发者ID:Monobjc,项目名称:monobjc-monodevelop,代码行数:11,代码来源:BaseRefactoringDialog.cs

示例5: GetVariableDeclarationStatement

		static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType)
		{
			var result = context.GetNode<VariableDeclarationStatement> ();
			if (result != null && result.Variables.Count == 1 && !result.Variables.First ().Initializer.IsNull && result.Variables.First ().NameToken.Contains (context.Location.Line, context.Location.Column)) {
				resolvedType = context.ResolveType (result.Variables.First ().Initializer);
				if (resolvedType == null)
					return null;
				return result;
			}
			resolvedType = null;
			return null;
		}
开发者ID:hduregger,项目名称:monodevelop,代码行数:12,代码来源:SplitDeclarationAndAssignment.cs

示例6: GetVariableDeclarationStatement

		static VariableDeclarationStatement GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType, CancellationToken cancellationToken = default(CancellationToken))
		{
			var result = context.GetNode<VariableDeclarationStatement> ();
			if (result != null && result.Variables.Count == 1 && !result.Variables.First ().Initializer.IsNull && result.Variables.First ().NameToken.Contains (context.Location.Line, context.Location.Column)) {
				resolvedType = result.Type.Clone ();
				// resolvedType = context.Resolve (result.Variables.First ().Initializer).Type.ConvertToAstType ();
				// if (resolvedType == null)
				// 	return null;
				return result;
			}
			resolvedType = null;
			return null;
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:13,代码来源:SplitDeclarationAndAssignmentAction.cs

示例7: GetVariableDeclarationStatement

		static VariableInitializer GetVariableDeclarationStatement (RefactoringContext context, out AstType resolvedType, CancellationToken cancellationToken = default(CancellationToken))
		{
			var result = context.GetNode<VariableInitializer> ();
			if (result != null && !result.Initializer.IsNull && context.Location <= result.Initializer.StartLocation) {
				var type = context.Resolve(result).Type;
				if (type.Equals(SpecialType.NullType) || type.Equals(SpecialType.UnknownType)) {
					resolvedType = new PrimitiveType ("object");
				} else {
					resolvedType = context.CreateShortType (type);
				}
				return result;
			}
			resolvedType = null;
			return null;
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:15,代码来源:SplitDeclarationAndAssignmentAction.cs

示例8: GetVariableDeclarationStatement

 static VariableDeclarationStatement GetVariableDeclarationStatement(RefactoringContext context, out AstType resolvedType, CancellationToken cancellationToken = default(CancellationToken))
 {
     var result = context.GetNode<VariableDeclarationStatement> ();
     if (result != null && result.Variables.Count == 1 && !result.Variables.First ().Initializer.IsNull && result.Variables.First ().NameToken.Contains (context.Location.Line, context.Location.Column)) {
         var type = context.Resolve(result.Variables.First ().Initializer).Type;
         if (type.Equals(SpecialType.NullType) || type.Equals(SpecialType.UnknownType)) {
             resolvedType = new PrimitiveType ("object");
         } else {
             resolvedType = context.CreateShortType (type);
         }
         return result;
     }
     resolvedType = null;
     return null;
 }
开发者ID:CSRedRat,项目名称:NRefactory,代码行数:15,代码来源:SplitDeclarationAndAssignmentAction.cs

示例9: GetDefaultValueExpression

			Expression GetDefaultValueExpression (AstType astType)
			{
				var type = ctx.ResolveType (astType);

				if ((type.IsReferenceType ?? false) || type.Kind == TypeKind.Dynamic)
					return new NullReferenceExpression ();

				var typeDefinition = type.GetDefinition ();
				if (typeDefinition != null) {
					switch (typeDefinition.KnownTypeCode) {
						case KnownTypeCode.Boolean:
							return new PrimitiveExpression (false);

						case KnownTypeCode.Char:
							return new PrimitiveExpression ('\0');

						case KnownTypeCode.SByte:
						case KnownTypeCode.Byte:
						case KnownTypeCode.Int16:
						case KnownTypeCode.UInt16:
						case KnownTypeCode.Int32:
							return new PrimitiveExpression (0);

						case KnownTypeCode.Int64:
							return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0L) };
						case KnownTypeCode.UInt32:
							return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0U) };
						case KnownTypeCode.UInt64:
							return new Choice {
								new PrimitiveExpression (0), new PrimitiveExpression (0U), new PrimitiveExpression (0UL)
							};
						case KnownTypeCode.Single:
							return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0F) };
						case KnownTypeCode.Double:
							return new Choice {
								new PrimitiveExpression (0), new PrimitiveExpression (0F), new PrimitiveExpression (0D)
							};
						case KnownTypeCode.Decimal:
							return new Choice { new PrimitiveExpression (0), new PrimitiveExpression (0M) };

						case KnownTypeCode.NullableOfT:
							return new NullReferenceExpression ();
					}
					if (type.Kind == TypeKind.Struct)
						return new ObjectCreateExpression (astType.Clone ());
				}
				return new DefaultValueExpression (astType.Clone ());
			} 
开发者ID:Gobiner,项目名称:ILSpy,代码行数:48,代码来源:RedundantFieldInitializerIssue.cs

示例10: AddTypeArguments

			void AddTypeArguments (ATypeNameExpression texpr, AstType result)
			{
				if (texpr.TypeArguments == null || texpr.TypeArguments.Args == null)
					return;
				var loc = LocationsBag.GetLocations (texpr.TypeArguments);
				if (loc != null && loc.Count >= 2)
					result.AddChild (new CSharpTokenNode (Convert (loc [loc.Count - 2]), 1), AstType.Roles.LChevron);
				int i = 0;
				foreach (var arg in texpr.TypeArguments.Args) {
					result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
					if (loc != null && i < loc.Count - 2)
						result.AddChild (new CSharpTokenNode (Convert (loc [i++]), 1), AstType.Roles.Comma);
				}
				if (loc != null && loc.Count >= 2)
					result.AddChild (new CSharpTokenNode (Convert (loc [loc.Count - 1]), 1), AstType.Roles.RChevron);
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:16,代码来源:CSharpParser.cs

示例11: DeclareVariable

 /// <summary>
 /// Declares a variable in the smallest required scope.
 /// </summary>
 /// <param name="node">The root of the subtree being searched for the best insertion position</param>
 /// <param name="type">The type of the new variable</param>
 /// <param name="name">The name of the new variable</param>
 /// <param name="allowPassIntoLoops">Whether the variable is allowed to be placed inside a loop</param>
 public static VariableDeclarationStatement DeclareVariable(AstNode node, AstType type, string name, bool allowPassIntoLoops = true)
 {
     VariableDeclarationStatement result = null;
     AstNode pos = FindInsertPos(node, name, allowPassIntoLoops);
     if (pos != null) {
         Match m = assignmentPattern.Match(pos);
         if (m != null && m.Get<IdentifierExpression>("ident").Single().Identifier == name) {
             result = new VariableDeclarationStatement(type, name, m.Get<Expression>("init").Single().Detach());
             pos.ReplaceWith(result);
         } else {
             result = new VariableDeclarationStatement(type, name);
             pos.Parent.InsertChildBefore(pos, result, BlockStatement.StatementRole);
         }
     }
     return result;
 }
开发者ID:petr-k,项目名称:ILSpy,代码行数:23,代码来源:DeclareVariableInSmallestScope.cs

示例12: GenerateNameProposals

		public static IEnumerable<string> GenerateNameProposals(AstType type)
		{
			if (type is PrimitiveType) {
				var pt = (PrimitiveType)type;
				switch (pt.Keyword) {
					case "object":
						yield return "o";
						yield return "obj";
						break;
					case "bool":
						yield return "b";
						yield return "pred";
						break;
					case "double":
					case "float":
					case "decimal":
						yield return "d";
						yield return "f";
						yield return "m";
						break;
					case "char":
						yield return "c";
						break;
					default:
						yield return "i";
						yield return "j";
						yield return "k";
						break;
				}
				yield break;
			}
			string name;
			if (type is SimpleType) {
				name = ((SimpleType)type).Identifier;
			} else if (type is MemberType) {
				name = ((MemberType)type).MemberName;
			} else {
				yield break;
			}

			var names = WordParser.BreakWords(name);
			if (names.Count > 0) {
				names [0] = Char.ToLower(names [0] [0]) + names [0].Substring(1);
			}
			yield return string.Join("", names);
		}
开发者ID:0xd4d,项目名称:NRefactory,代码行数:46,代码来源:NamingHelper.cs

示例13: TypeMetadata

 public TypeMetadata(string typeName, string @namespace, string csharpName, string scriptName, IReadOnlyList<string> tagNames, bool generate, bool inherit, TypeKind typeKind, bool includeConstructors, IReadOnlyList<TypeOverride> typeOverrides, AstType aliasFor, IEnumerable<Tuple<string, string>> renames, IEnumerable<string> removes, IReadOnlyList<string> addInDerivedTypes, IReadOnlyList<GeneratedEnum> generatedEnums)
 {
     TypeName = typeName;
     Namespace = @namespace;
     CSharpName = csharpName;
     ScriptName = scriptName;
     TagNames = tagNames.AsReadOnlySafe();
     Generate = generate && typeKind != TypeKind.Mixin && typeKind != TypeKind.Skip;
     Inherit = inherit;
     TypeKind = typeKind;
     IncludeConstructors = includeConstructors;
     TypeOverrides = typeOverrides.AsReadOnlySafe();
     AliasFor = aliasFor;
     Renames = new ReadOnlyDictionary<string, string>((renames ?? new Tuple<string, string>[0]).ToDictionary(x => x.Item1, x => x.Item2));
     Removes = removes.AsReadOnlySafe();
     AddInDerivedTypes = addInDerivedTypes.AsReadOnlySafe();
     GeneratedEnums = generatedEnums.AsReadOnlySafe();
 }
开发者ID:Saltarelle,项目名称:SaltarelleWeb,代码行数:18,代码来源:TypeMetadata.cs

示例14: GetTypeDefinition

 public virtual TypeDefinition GetTypeDefinition(AstType reference, bool safe = false)
 {
     var resolveResult = this.Resolver.ResolveNode(reference, this) as TypeResolveResult;
     var type = this.BridgeTypes.Get(resolveResult.Type, safe);
     return type != null ? type.TypeDefinition :  null;
 }
开发者ID:RashmiPankaj,项目名称:Bridge,代码行数:6,代码来源:Emitter.TypeHelpers.cs

示例15: TypeParamExpression

 public TypeParamExpression(string name, AstType type, IType iType, bool inherited = false)
 {
     this.Name = name;
     this.AstType = type;
     this.IType = iType;
     this.Inherited = inherited;
 }
开发者ID:RashmiPankaj,项目名称:Bridge,代码行数:7,代码来源:ArgumentsInfo.cs


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