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


C# SimpleType类代码示例

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


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

示例1: VisitMethodDeclaration

        public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
        {
            Guard.AgainstNullArgument("methodDeclaration", methodDeclaration);

            IEnumerable<ParameterDeclaration> parameters = methodDeclaration
                .GetChildrenByRole(Roles.Parameter)
                .Select(x => (ParameterDeclaration)x.Clone());

            var isVoid = false;
            var isAsync = methodDeclaration.Modifiers.HasFlag(Modifiers.Async);
            AstType returnType = methodDeclaration.GetChildByRole(Roles.Type).Clone();
            var type = returnType as PrimitiveType;
            if (type != null)
            {
                isVoid = string.Compare(
                    type.Keyword, "void", StringComparison.OrdinalIgnoreCase) == 0;
            }

            var methodType = new SimpleType(Identifier.Create(isVoid ? "Action" : "Func"));

            IEnumerable<AstType> types = parameters.Select(
                x => x.GetChildByRole(Roles.Type).Clone());

            methodType
                .TypeArguments
                .AddRange(types);

            if (!isVoid)
            {
                methodType.TypeArguments.Add(returnType);
            }
            var methodName = GetIdentifierName(methodDeclaration);

            var methodBody = methodDeclaration
                .GetChildrenByRole(Roles.Body)
                .FirstOrDefault();
            if (methodBody == null)
            {
                throw new NullReferenceException(string.Format("Method '{0}' has no method body", methodName));
            }
            methodBody = (BlockStatement)methodBody.Clone();

            var prototype = new VariableDeclarationStatement { Type = methodType };
            prototype.Variables.Add(new VariableInitializer(methodName));

            var anonymousMethod = new AnonymousMethodExpression(methodBody, parameters) { IsAsync = isAsync };
            var expression = new ExpressionStatement
            {
                Expression = new AssignmentExpression(
                    new IdentifierExpression(methodName), 
                    anonymousMethod)
            };

            _methods.Add(new MethodVisitorResult
            {
                MethodDefinition = methodDeclaration,
                MethodPrototype = prototype,
                MethodExpression = expression
            });
        }
开发者ID:selony,项目名称:scriptcs,代码行数:60,代码来源:MethodVisitor.cs

示例2: GetOriginalQueryableType

 public override SimpleType GetOriginalQueryableType()
 {
     var memberExp = GetTranslatedParameterOrMember(GetParameter("x"));
     var mappedItem = new SimpleType(MappedItemType, memberExp.Type);
     mappedItem.Includes.AddRange(Includes);
     return mappedItem;
 }
开发者ID:jeswin,项目名称:AgileFx,代码行数:7,代码来源:ManyToManyMapType.cs

示例3: Main

    public static void Main (string[] args) {
        var a = new SimpleType(0);

        Console.WriteLine("a = {0}", a.Value);
        Increment(ref a.Value);
        Console.WriteLine("a = {0}", a.Value);
    }
开发者ID:GlennSandoval,项目名称:JSIL,代码行数:7,代码来源:MemberRefParameters.cs

示例4: AddInclude

 private void AddInclude(SimpleType source, MemberExpression memberSelector, LambdaExpression collectionInclude)
 {
     var members = source.GetAllMembers();
     if (members.Count > 0 && memberSelector.GetDepth() > 1)
     {
         var innermostMember = ExpressionUtil.GetInnermostMemberExpression(memberSelector);
         foreach (var kvp in members)
         {
             if (kvp.Key == innermostMember.Member)
             {
                 AddInclude(kvp.Value, ExpressionUtil.ReplaceInnermostMemberExpressionWithParameter(memberSelector) as MemberExpression, collectionInclude);
                 return;
             }
         }
     }
     else
     {
         var parameter = ExpressionUtil.GetParameterExpression(memberSelector);
         if (collectionInclude != null)
         {
             source.Includes.Add(IncludeDirectiveUtil.GetIncludeInCollectionDirective(memberSelector, collectionInclude));
         }
         else
         {
             source.Includes.Add(IncludeDirectiveUtil.GetIncludeDirective(memberSelector));
         }
     }
 }
开发者ID:jeswin,项目名称:AgileFx,代码行数:28,代码来源:LoadRelated.cs

示例5: GenericWithArrayVariableDeclarationStatementTest1

		public void GenericWithArrayVariableDeclarationStatementTest1()
		{
			VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int>[] a;");
			AstType type = new SimpleType("G") {
				TypeArguments = { new PrimitiveType("int") }
			}.MakeArrayType();
			Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:8,代码来源:VariableDeclarationStatementTests.cs

示例6: SimpleFieldGenerator

        public SimpleFieldGenerator(FieldInfo fld)
            : base(fld)
        {
            _primitive = fld.DeclaringType.ParentConfig.ResolveName<SimpleType>(
                fld.DeclaringType, ((SimpleTypeRef) fld).TypeName
                );

            _generator = new SimpleTypeGenerator(_primitive);
        }
开发者ID:modulexcite,项目名称:NClassify,代码行数:9,代码来源:SimpleFieldGenerator.cs

示例7: GetActions

        static IEnumerable<CodeAction> GetActions(RefactoringContext context, SimpleType node)
        {
            var resolveResult = context.Resolve(node) as UnknownIdentifierResolveResult;
            if (resolveResult == null)
                yield break;

            yield return new CodeAction(context.TranslateString("Create delegate"), script => {
                script.CreateNewType(CreateType(context,  node));
            }, node);
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:10,代码来源:CreateDelegateAction.cs

示例8: the_same_graph_written_on_the_same_stream_is_not_detected_as_a_circular_reference

        public void the_same_graph_written_on_the_same_stream_is_not_detected_as_a_circular_reference()
        {
            var graph = new SimpleType();

            using(var writer = CreateWriter())
            {
                writer.Write(graph);
                writer.Write(graph);
            }
        }
开发者ID:simoneb,项目名称:ak-f1-timing,代码行数:10,代码来源:DecoratedObjectWriterTest.cs

示例9: ComplexGenericVariableDeclarationStatementTest

		public void ComplexGenericVariableDeclarationStatementTest()
		{
			VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("Generic<Namespace.Printable, G<Printable[]> > where = new Generic<Namespace.Printable, G<Printable[]>>();");
			AstType type = new SimpleType("Generic") {
				TypeArguments = {
					new MemberType { Target = new SimpleType("Namespace"), MemberName = "Printable" },
					new SimpleType("G") { TypeArguments = { new SimpleType("Printable").MakeArrayType() } }
				}};
			Assert.IsTrue(new VariableDeclarationStatement(type, "where", new ObjectCreateExpression { Type = type.Clone() }).IsMatch(lvd));
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:10,代码来源:VariableDeclarationStatementTests.cs

示例10: CreateType

		static DelegateDeclaration CreateType(RefactoringContext context, SimpleType simpleType)
		{
			var result = new DelegateDeclaration() {
				Name = simpleType.Identifier,
				Modifiers = ((EntityDeclaration)simpleType.Parent).Modifiers,
				ReturnType = new PrimitiveType("void"),
				Parameters = {
					new ParameterDeclaration(new PrimitiveType("object"), "sender"),
					new ParameterDeclaration(context.CreateShortType("System", "EventArgs"), "e")
				}
			};
			return result;
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:13,代码来源:CreateDelegateAction.cs

示例11: AddEntity

        public void AddEntity()
        {
            // Setup
            var file = GetXmlFile(nameof(AddEntity));
            var set = new XmlSet<SimpleType>(file);
            var simpleType = new SimpleType();

            // Execute
            set.Add(simpleType);

            // Assert
            Assert.AreSame(simpleType, set.First());
            Assert.AreEqual(1, set.Count);
        }
开发者ID:jsmunroe,项目名称:Helpers,代码行数:14,代码来源:XmlSetTest.cs

示例12: ConvertToType

			AstType ConvertToType (MemberName memberName)
			{
				AstType result;
				if (memberName.Left != null) {
					result = new MemberType () { MemberName = memberName.Name };
					result.AddChild (ConvertToType (memberName.Left), MemberType.TargetRole);
				} else {
					result = new SimpleType () { Identifier = memberName.Name };
				}
				if (memberName.TypeArguments != null && !memberName.TypeArguments.IsEmpty) {
					foreach (var arg in memberName.TypeArguments.Args) {
						result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
					}
				}
				return result;
			}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:16,代码来源:CSharpParser.cs

示例13: CreateClassFromType

		static TypeDeclaration CreateClassFromType(RefactoringContext context, SimpleType simpleType)
		{
			TypeDeclaration result;
			string className = simpleType.Identifier;

			if (simpleType.Parent is Attribute) {
				if (!className.EndsWith("Attribute"))
					className += "Attribute";
			}

			result = new TypeDeclaration() { Name = className };
			var entity = simpleType.GetParent<EntityDeclaration>();
			if (entity != null)
				result.Modifiers |= entity.Modifiers & ~Modifiers.Internal;

			return result;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:17,代码来源:CreateClassDeclarationAction.cs

示例14: graphs_which_contain_circular_references_are_not_supported

 public void graphs_which_contain_circular_references_are_not_supported()
 {
     var graph = new SimpleType();
     // Root to self.
     graph.Value = graph;
     Assert.Throws<SerializationException>(() => Write(graph));
     // Descendent to root.
     graph.Value = new SimpleType { Value = graph };
     Assert.Throws<SerializationException>(() => Write(graph));
     // Descendent to self.
     graph.Value = new SimpleType();
     graph.Value.Value = graph.Value;
     Assert.Throws<SerializationException>(() => Write(graph));
     // Descendent to parent.
     graph.Value = new SimpleType { Value = graph.Value };
     Assert.Throws<SerializationException>(() => Write(graph));
 }
开发者ID:simoneb,项目名称:ak-f1-timing,代码行数:17,代码来源:DecoratedObjectWriterTest.cs

示例15: ConvertToTypeReference

		public static AstType ConvertToTypeReference (this MonoDevelop.Projects.Dom.IReturnType returnType)
		{
			string primitiveType;
			if (TypeTable.TryGetValue (returnType.DecoratedFullName, out primitiveType))
				return new PrimitiveType (primitiveType);
			
			AstType result = null;
			if (!string.IsNullOrEmpty (returnType.Namespace))
				result = new SimpleType (returnType.Namespace);
			foreach (var part in returnType.Parts) {
				if (result == null) {
					var st = new SimpleType (part.Name);
					foreach (var type in part.GenericArguments.Select (ga => ConvertToTypeReference (ga)))
						st.AddChild (type, SimpleType.Roles.TypeArgument);
					result = st;
				} else {
					var mt = new ICSharpCode.NRefactory.CSharp.MemberType () {
						Target = result,
						MemberName = part.Name
					};
					foreach (var type in part.GenericArguments.Select (ga => ConvertToTypeReference (ga)))
						mt.AddChild (type, SimpleType.Roles.TypeArgument);
					result = mt;
				}
			}
			
			/*
			List<TypeReference> genericTypes = new List<TypeReference> ();
			foreach (MonoDevelop.Projects.Dom.IReturnType genericType in returnType.GenericArguments) {
				genericTypes.Add (ConvertToTypeReference (genericType));
			}
			TypeReference result = new AstType (returnType.FullName, genericTypes);
			result.IsKeyword = true;
			result.PointerNestingLevel = returnType.PointerNestingLevel;
			if (returnType.ArrayDimensions > 0) {
				int[] rankSpecfier = new int[returnType.ArrayDimensions];
				for (int i = 0; i < returnType.ArrayDimensions; i++) {
					rankSpecfier[i] = returnType.GetDimension (i);
				}
				result.RankSpecifier = rankSpecfier;
			}*/
			return result;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:43,代码来源:HelperMethods.cs


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