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


C# AstType.Clone方法代码示例

本文整理汇总了C#中AstType.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# AstType.Clone方法的具体用法?C# AstType.Clone怎么用?C# AstType.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AstType的用法示例。


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

示例1: TryPatchTemplateToObjectType

        /// <summary>
        /// Converts template types to Object type (useful for inline methods and template specialization types)
        /// </summary>
        /// <param name="type"></param>
        /// <param name="newType"></param>
        /// <returns>Returns if the type is actually changed or not</returns>
        public static bool TryPatchTemplateToObjectType(AstType type, out AstType newType)
        {
            newType = (AstType)type.Clone();
            string name = "";
            if (type is SimpleType)
            {
                SimpleType st = type as SimpleType;
                name = st.Identifier;
                if (Cache.GetTemplateTypes().Contains(name))
                {
                    newType = new SimpleType("Object");
                    return true;
                }
                else
                {
                    if (st.TypeArguments.Any())
                    {
                        List<AstType> args = new List<AstType>();
                        bool converted = false;
                        foreach (AstType t in st.TypeArguments)
                        {
                            AstType discard;
                            if (TryPatchTemplateToObjectType(t, out discard))
                            {
                                converted = true;
                                args.Add(new SimpleType("Object"));
                            }
                            else
                                args.Add((AstType)t.Clone());
                        }

                        SimpleType nType = (SimpleType)st.Clone();
                        nType.TypeArguments.Clear();
                        nType.TypeArguments.AddRange(args.ToArray());
                        newType = nType;
                        return converted;
                    }
                }
            }
            if (type is PtrType)
            {
                if ((type as PtrType).Target is SimpleType)
                {
                    SimpleType pst = (type as PtrType).Target as SimpleType;
                    AstType tmp;
                    bool converted = TryPatchTemplateToObjectType(pst, out tmp);
                    newType = new PtrType(tmp);
                    return converted;
                }
            }

            return false;
        }
开发者ID:AlexAlbala,项目名称:Alter-Native,代码行数:59,代码来源:Resolver.cs

示例2: MergeTypes

		static AstType MergeTypes (AstType x, AstType y)
		{
			if (TypesEqual (x, y)) {
				return x.Clone ();
			}

			return new PrimitiveType ("object");
		}
开发者ID:RReverser,项目名称:Netjs,代码行数:8,代码来源:CsToTs.cs

示例3: 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

示例4: GetNotNullTypeCheck

		static Expression GetNotNullTypeCheck (string id, AstType type)
		{
			return new IsExpression {
				Expression = new IdentifierExpression (id),
				Type = type.Clone (),
			};
		}
开发者ID:RReverser,项目名称:Netjs,代码行数:7,代码来源:CsToTs.cs


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