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


C# CodeDom.CodeSnippetExpression类代码示例

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


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

示例1: CodeAssignStatementTest

		public void CodeAssignStatementTest ()
		{
			CodeSnippetExpression cse1 = new CodeSnippetExpression("A");
			CodeSnippetExpression cse2 = new CodeSnippetExpression("B");

			CodeAssignStatement assignStatement = new CodeAssignStatement (cse1, cse2);
			statement = assignStatement;

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"A = B;{0}", NewLine), Generate (), "#1");

			assignStatement.Left = null;
			try {
				Generate ();
				Assert.Fail ("#2");
			} catch (ArgumentNullException) {
			}

			assignStatement.Left = cse1;
			Generate ();

			assignStatement.Right = null;
			try {
				Generate ();
				Assert.Fail ("#3");
			} catch (ArgumentNullException) {
			}

			assignStatement.Right = cse2;
			Generate ();
		}
开发者ID:zxlin25,项目名称:mono,代码行数:31,代码来源:CodeGeneratorFromStatementTest.cs

示例2: Constructor1

		public void Constructor1 ()
		{
			string value = "mono";

			CodeSnippetExpression cse = new CodeSnippetExpression (value);
			Assert.IsNotNull (cse.Value, "#1");
			Assert.AreSame (value, cse.Value, "#2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeSnippetExpressionTest.cs

示例3: TypescriptSnippetExpression

 public TypescriptSnippetExpression(
     CodeSnippetExpression codeExpression, 
     CodeGeneratorOptions options)
 {
     _codeExpression = codeExpression;
     _options = options;
     System.Diagnostics.Debug.WriteLine("TypescriptSnippetExpression Created");
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:8,代码来源:TypescriptSnippetExpression.cs

示例4: Constructor0

		public void Constructor0 ()
		{
			CodeSnippetExpression cse = new CodeSnippetExpression ();
			Assert.IsNotNull (cse.Value, "#1");
			Assert.AreEqual (string.Empty, cse.Value, "#2");

			string value = "mono";
			cse.Value = value;
			Assert.IsNotNull (cse.Value, "#3");
			Assert.AreSame (value, cse.Value, "#4");

			cse.Value = null;
			Assert.IsNotNull (cse.Value, "#5");
			Assert.AreEqual (string.Empty, cse.Value, "#6");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:15,代码来源:CodeSnippetExpressionTest.cs

示例5: LoadEnumElement

 private static void LoadEnumElement(XmlElement element, CodeTypeDeclaration codeType,
     out CodeMemberProperty codeProperty)
 {
     codeProperty = new CodeMemberProperty();
     string name = element.GetAttribute("name");
     CodeTypeDeclaration codeEnum = new CodeTypeDeclaration(ToPublicName(name) + "Enum");
     codeEnum.IsEnum = true;
     codeEnum.Members.Add(new CodeSnippetTypeMember(element.InnerText));
     codeType.Members.Add(codeEnum);
     CodeExpression defaultValue = null;
     if(element.HasAttribute("default"))
         defaultValue = new CodeSnippetExpression(
         JoinNames(codeEnum.Name, element.GetAttribute("default")));
     GenerateProperty(codeType, codeEnum.Name, name, out codeProperty, defaultValue);
 }
开发者ID:jaggedsoft,项目名称:aesirtk,代码行数:15,代码来源:Program.cs

示例6: CreateAndInitializeCollectionField

        /// <summary>
        /// Creates a reference to a collection based member field and initializes it with a new instance of the
        /// specified parameter type and adds a collection item to it.
        /// Sample values are used as the initializing expression.
        /// </summary>
        /// <param name="memberCollectionField">Name of the referenced collection field.</param>
        /// <param name="collectionInitializers">Defines the types of the new object list.</param>
        /// <returns>
        /// An assignment statement for the specified collection member field.
        /// </returns>
        /// <remarks>
        /// With a custom Type, this method produces a statement with a initializer like:
        /// <code>this.paths = new[] { pathsItem };</code>.
        /// where the item is defined like:
        /// <code>this.pathsItem = new PathItemType();</code>.
        /// myType of type System.Type:
        /// <code>this.pathsItem = "An Item";</code>.
        /// </remarks>
        public static CodeAssignStatement CreateAndInitializeCollectionField(
            //Type type,
            string memberCollectionField,
            params string[] collectionInitializers)
        {
            /*if (type == typeof(object))
            {

            }*/
            var fieldRef1 = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), memberCollectionField);
            //CodeExpression assignExpr = CreateExpressionByType(type, memberCollectionField);
            var para = collectionInitializers.Aggregate((x, y) => x += "," + y);
            CodeExpression assignExpr = new CodeSnippetExpression("new[] { " + para + " }");

            return new CodeAssignStatement(fieldRef1, assignExpr);
        }
开发者ID:Jedzia,项目名称:NStub,代码行数:34,代码来源:CodeMethodComposer.cs

示例7: AddArgument

        public static void AddArgument(this CodeAttributeDeclaration attribute, string name, string value)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            CodeExpression expression;
            // Use convention that if string starts with $ its a const
            if (value.StartsWith(SnippetIndicator.ToString()))
            {
                expression = new CodeSnippetExpression(value.TrimStart(SnippetIndicator));
            }
            else
            {
                expression = new CodePrimitiveExpression(value);
            }
            attribute.AddArgument(name, expression);
        }
开发者ID:nordseth,项目名称:ComposerMigration,代码行数:17,代码来源:CodeDomExtensions.cs

示例8: CreateMappingStatements

        public static CodeStatement[] CreateMappingStatements(ClassMappingDescriptor descriptor, CodeGeneratorContext context)
        {
            Dictionary<string, List<MemberMappingDescriptor>> aggregateGroups = new Dictionary<string, List<MemberMappingDescriptor>>();
            List<CodeStatement> statements = new List<CodeStatement>(20);
            foreach (MemberMappingDescriptor member in descriptor.MemberDescriptors)
            {
                if (member.IsAggregateExpression)
                {
                    // group all agregates by expression to avoid multiple traversals over same path
                    //string path = GetPath(member.Expression);
                    string path = GetPath(descriptor, member);
                    if(!aggregateGroups.ContainsKey(path))
                        aggregateGroups[path] = new List<MemberMappingDescriptor>(1);
                    aggregateGroups[path].Add(member);
                }
                else
                {
                    CodeStatement[] st = CreateNonAggregateMappingStatements(descriptor, member, context);
                    if(member.HasNullValue)
                    {
                        CodeStatement[] falseStatements = st;
                        CodeStatement[] trueStatements = new CodeStatement[1];
                        trueStatements[0] = new CodeAssignStatement(
                            new CodeVariableReferenceExpression("target." + member.Member),
                            new CodeSnippetExpression(member.NullValue.ToString()));

                        string checkExpression = GetNullablePartsCheckExpression(member);
                        CodeExpression ifExpression = new CodeSnippetExpression(checkExpression);

                        st = new CodeStatement[1];
                        st[0] = new CodeConditionStatement(ifExpression, trueStatements, falseStatements);
                    }
                    statements.AddRange(st);
                }
            }

            foreach (List<MemberMappingDescriptor> group in aggregateGroups.Values)
            {
                    CodeStatement[] st = CreateAggregateMappingStatements(descriptor, group, context);
                    statements.AddRange(st);
            }

            return statements.ToArray();
        }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:44,代码来源:FunctionMappingGenerator.cs

示例9: CreateEntryPoint

        //Create main method
        private void CreateEntryPoint(List<string> statements)
        {
            //Create an object and assign the name as "Main"
            CodeEntryPointMethod mymain = new CodeEntryPointMethod();
            mymain.Name = "Main";
            //Mark the access modifier for the main method as Public and //static
            mymain.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            //Change string to statements
            if(statements != null){

                foreach (string item in statements) {
                    if (item != null) {
                        CodeSnippetExpression exp1 = new CodeSnippetExpression(@item);
                        CodeExpressionStatement ces1 = new CodeExpressionStatement(exp1);
                        mymain.Statements.Add(ces1);
                    }
                }
            }
            myclass.Members.Add(mymain);
        }
开发者ID:Ngauet,项目名称:automatedframework,代码行数:21,代码来源:CCodeGenerator.cs

示例10: CreateWithApiKey

        /// <summary>
        /// if (string.IsNullOrEmpty(APIKey) == false)
        ///    request = request.WithAPIKey(APIKey)
        /// </summary>
        /// <returns></returns>
        internal CodeConditionStatement CreateWithApiKey()
        {
            // !string.IsNullOrEmpty(Key)
            var condition =
                new CodeSnippetExpression("!string.IsNullOrEmpty(" + ApiKeyServiceDecorator.PropertyName + ")");

            // if (...) {
            var block = new CodeConditionStatement(condition);

            // request = request.WithKey(APIKey)
            var getProperty = new CodePropertyReferenceExpression(
                new CodeThisReferenceExpression(), ApiKeyServiceDecorator.PropertyName);
            var request = new CodeMethodInvokeExpression(
                new CodeVariableReferenceExpression("request"), "WithKey", getProperty);

            var trueCase = new CodeAssignStatement(new CodeVariableReferenceExpression("request"), request);

            // }
            block.TrueStatements.Add(trueCase);

            return block;
        }
开发者ID:nick0816,项目名称:LoggenCSG,代码行数:27,代码来源:CreateRequestMethodServiceDecorator.cs

示例11: Constructor1

		public void Constructor1 ()
		{
			CodeSnippetExpression expression = new CodeSnippetExpression("exp");

			CodeEventReferenceExpression cere = new CodeEventReferenceExpression (
				expression, "mono");
			Assert.AreEqual ("mono", cere.EventName, "#1");
			Assert.IsNotNull (cere.TargetObject, "#2");
			Assert.AreSame (expression, cere.TargetObject, "#3");

			cere.EventName = null;
			Assert.IsNotNull (cere.EventName, "#4");
			Assert.AreEqual (string.Empty, cere.EventName, "#5");

			cere.TargetObject = null;
			Assert.IsNull (cere.TargetObject, "#6");

			cere = new CodeEventReferenceExpression ((CodeExpression) null,
				(string) null);
			Assert.IsNotNull (cere.EventName, "#7");
			Assert.AreEqual (string.Empty, cere.EventName, "#8");
			Assert.IsNull (cere.TargetObject, "#9");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:CodeEventReferenceExpressionTest.cs

示例12: CreateEntryPoint

        public void CreateEntryPoint(ref CodeTypeDeclaration customClass)
        {
            //Create an object and assign the name as “Main”
            CodeEntryPointMethod main = new CodeEntryPointMethod();
            main.Name = "Main";

            //Mark the access modifier for the main method as Public and //static
            main.Attributes = MemberAttributes.Public | MemberAttributes.Static;

            //Provide defenition to the main method.
            //Create an object of the “Cmyclass” and invoke the method
            //by passing the required parameters.
            CodeSnippetExpression exp = new CodeSnippetExpression(CallingMethod(customClass));

            //Create expression statements for the snippets
            CodeExpressionStatement ces = new CodeExpressionStatement(exp);

            //Add the expression statements to the main method.
            main.Statements.Add(ces);

            //Add the main method to the class
            customClass.Members.Add(main);
        }
开发者ID:govinda777,项目名称:WorkflowPoc,代码行数:23,代码来源:FactoryCode.cs

示例13: GenerateConstructor

 private void GenerateConstructor(CodeTypeDeclaration taskClass)
 {
     CodeConstructor constructor = new CodeConstructor {
         Attributes = MemberAttributes.Public
     };
     CodeTypeReference createType = new CodeTypeReference("System.Resources.ResourceManager");
     CodeSnippetExpression expression = new CodeSnippetExpression(this.SurroundWithQuotes(this.taskParser.ResourceNamespace));
     CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression("System.Reflection.Assembly");
     CodeMethodReferenceExpression method = new CodeMethodReferenceExpression(targetObject, "GetExecutingAssembly");
     CodeMethodInvokeExpression expression4 = new CodeMethodInvokeExpression(method, new CodeExpression[0]);
     CodeObjectCreateExpression expression5 = new CodeObjectCreateExpression(createType, new CodeExpression[] { expression, expression4 });
     CodeTypeReference reference2 = new CodeTypeReference(new CodeTypeReference("System.String"), 1);
     List<CodeExpression> list = new List<CodeExpression>();
     foreach (string str in this.taskParser.SwitchOrderList)
     {
         list.Add(new CodeSnippetExpression(this.SurroundWithQuotes(str)));
     }
     CodeArrayCreateExpression expression6 = new CodeArrayCreateExpression(reference2, list.ToArray());
     constructor.BaseConstructorArgs.Add(expression6);
     constructor.BaseConstructorArgs.Add(expression5);
     taskClass.Members.Add(constructor);
     if (this.GenerateComments)
     {
         constructor.Comments.Add(new CodeCommentStatement(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("StartSummary", new object[0]), true));
         string text = Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("ConstructorDescription", new object[0]);
         constructor.Comments.Add(new CodeCommentStatement(text, true));
         constructor.Comments.Add(new CodeCommentStatement(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("EndSummary", new object[0]), true));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:TaskGenerator.cs

示例14: GenerateSnippetExpression

		protected override void GenerateSnippetExpression (CodeSnippetExpression e)
		{
		}
开发者ID:Profit0004,项目名称:mono,代码行数:3,代码来源:CodeGeneratorCas.cs

示例15: GenerateSnippetExpression

		protected override void GenerateSnippetExpression (CodeSnippetExpression expression)
		{
			Output.Write (expression.Value);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:4,代码来源:VBCodeGenerator.cs


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