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

C# CodeDom.CodeTypeParameter类代码示例

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

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



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

示例1: GenerateFromXmlMethod

        public CodeMemberMethod GenerateFromXmlMethod()
        {
            CodeMemberMethod fromXmlMethod = new CodeMemberMethod();

            fromXmlMethod.Name = FromXmlMethodName;
            fromXmlMethod.Attributes = MemberAttributes.Final | MemberAttributes.Public|MemberAttributes.Static;

            CodeTypeParameter tTypeParameter = new CodeTypeParameter("T");
            //tType.HasConstructorConstraint = true;

            fromXmlMethod.TypeParameters.Add(tTypeParameter);
            fromXmlMethod.ReturnType = new CodeTypeReference("T");;
            //fromXmlMethod.Statements.Add();
            fromXmlMethod.Parameters.Add(new CodeParameterDeclarationExpression(
                new CodeTypeReference("String"), "xml"));
            fromXmlMethod.Comments.Add(new CodeCommentStatement("Call it using this code: YourStrongTypedEntity entity = FromXml<YourStrongTypedEntity>(YourMsgString);"));
            fromXmlMethod.Statements.Add(new CodeSnippetStatement(@"        T returnedXmlClass = default(T);

            using (TextReader reader = new StringReader(xml))
            {
            returnedXmlClass = (T)new XmlSerializer(typeof(T)).Deserialize(reader);
            }
            return returnedXmlClass ; "));

            return fromXmlMethod;
        }
开发者ID:swoog,项目名称:EaiConverter,代码行数:26,代码来源:TibcoXslUtilBuilder.cs


示例2: AddRange

 public void AddRange(CodeTypeParameter[] value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:8,代码来源:codetypeparametercollection.cs


示例3: Generic

 public static CodeMemberMethod Generic(this CodeMemberMethod method, string paramName,
     bool hasConstructor, params CodeTypeReference[] constraints)
 {
     var p = new CodeTypeParameter(paramName) {HasConstructorConstraint = hasConstructor};
     p.Constraints.AddRange(constraints);
     method.TypeParameters.Add(p);
     return method;
 }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:8,代码来源:Method.cs


示例4: ToCodeDom

 public CodeTypeParameter ToCodeDom()
 {
     CodeTypeParameter typeParameter = new CodeTypeParameter(this.Name);
     typeParameter.CustomAttributes.AddRange(this.CustomAttributes.ToCodeDom());
     foreach (ITypeDeclaration constraint in this.Constraints)
         typeParameter.Constraints.Add(constraint.TypeReference);
     return typeParameter;
 }
开发者ID:spib,项目名称:nhcontrib,代码行数:8,代码来源:TypeParameterDeclaration.cs


示例5: Constructor1_NullItem

		public void Constructor1_NullItem ()
		{
			CodeTypeParameter[] typeParams = new CodeTypeParameter[] { 
				new CodeTypeParameter (), null };

			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
				typeParams);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:8,代码来源:CodeTypeParameterCollectionTest.cs


示例6: Generic

 public static CodeTypeDeclaration Generic(this CodeTypeDeclaration @class, string paramName,
     params Type[] constraints)
 {
     var p = new CodeTypeParameter(paramName);
     p.Constraints.AddRange(constraints.Select((t) => new CodeTypeReference(t)).ToArray());
     @class.TypeParameters.Add(p);
     return @class;
 }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:8,代码来源:TypeDeclaration.cs


示例7: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeTypeParameter ctp = new CodeTypeParameter ("mono");
			Assert.AreEqual (0, ctp.Constraints.Count, "Constraints");
			Assert.AreEqual (0, ctp.CustomAttributes.Count, "CustomAttributes");
			Assert.IsFalse (ctp.HasConstructorConstraint, "HasConstructorConstraint");
			ctp.HasConstructorConstraint = true;
			Assert.AreEqual ("mono", ctp.Name);
			ctp.Name = String.Empty;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:10,代码来源:CodeTypeParameterCas.cs


示例8: AddRange

		public void AddRange (CodeTypeParameter[] value)
		{
			if (value == null) {
				throw new ArgumentNullException ("value");
			}

			for (int i = 0; i < value.Length; i++) {
				Add (value[i]);
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:10,代码来源:CodeTypeParameterCollection.cs


示例9: Evaluate

        public string Evaluate(CodeTypeParameter codeTypeParameter)
        {
            var typeParameterConstraint = string.Empty;
            if (codeTypeParameter.Constraints.Count > 0)
            {
                var constraint = codeTypeParameter.Constraints.OfType<CodeTypeReference>().First();
                var type = _typescriptTypeMapper.GetTypeOutput(constraint);
                typeParameterConstraint = $" extends {type}";
            }

            return $"{codeTypeParameter.Name}{typeParameterConstraint}";
        }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:12,代码来源:TypescriptTypeParameter.cs


示例10: Constructor1

		public void Constructor1 ()
		{
			CodeTypeParameter tp1 = new CodeTypeParameter ();
			CodeTypeParameter tp2 = new CodeTypeParameter ();

			CodeTypeParameter[] typeParams = new CodeTypeParameter[] { tp1, tp2 };
			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (
				typeParams);

			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
			Assert.AreEqual (1, coll.IndexOf (tp2), "#3");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:13,代码来源:CodeTypeParameterCollectionTest.cs


示例11: Constructor2

		public void Constructor2 ()
		{
			CodeTypeParameter tp1 = new CodeTypeParameter ();
			CodeTypeParameter tp2 = new CodeTypeParameter ();

			CodeTypeParameterCollection c = new CodeTypeParameterCollection ();
			c.Add (tp1);
			c.Add (tp2);

			CodeTypeParameterCollection coll = new CodeTypeParameterCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (tp1), "#2");
			Assert.AreEqual (1, coll.IndexOf (tp2), "#3");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:14,代码来源:CodeTypeParameterCollectionTest.cs


示例12: Constructor1

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

			CodeTypeParameter ctp = new CodeTypeParameter (parameterName);

			Assert.IsNotNull (ctp.Constraints, "#1");
			Assert.AreEqual (0, ctp.Constraints.Count, "#2");
			Assert.IsNotNull (ctp.CustomAttributes, "#3");
			Assert.AreEqual (0, ctp.CustomAttributes.Count, "#4");
			Assert.IsFalse (ctp.HasConstructorConstraint, "#5");
			Assert.IsNotNull (ctp.Name, "#6");
			Assert.AreSame (parameterName, ctp.Name, "#7");

			ctp.Name = null;
			Assert.IsNotNull (ctp.Name, "#8");
			Assert.AreEqual (string.Empty, ctp.Name, "#9");

			ctp = new CodeTypeParameter ((string) null);
			Assert.IsNotNull (ctp.Name, "#10");
			Assert.AreEqual (string.Empty, ctp.Name, "#11");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:21,代码来源:CodeTypeParameterTest.cs


示例13: GetFindAllByNameExMethods

        public CodeMemberMethod[] GetFindAllByNameExMethods()
        {
            string methodName = "FindAllByNameEx";

            SAPAutomationHelper.Current.SetSAPApiAssembly();
            Assembly asm = SAPAutomationHelper.Current.SAPGuiApiAssembly;

            var interfaces = asm.GetTypes().Where(t => t.IsInterface && t.Name.StartsWith("Gui") && t.GetInterfaces()[0].GetMethod(methodName) != null).ToArray();

            CodeMemberMethod[] methods = new CodeMemberMethod[interfaces.Count()];

            for (int i = 0; i < interfaces.Count(); i++)
            {

                methods[i] = new CodeMemberMethod();
                methods[i].Name = methodName;
                methods[i].Attributes = MemberAttributes.Public | MemberAttributes.Static;
                CodeParameterDeclarationExpression para1 = new CodeParameterDeclarationExpression(new CodeTypeReference("this " + interfaces[i].Name), interfaces[i].Name.Substring(3));
                methods[i].Parameters.Add(para1);
                CodeParameterDeclarationExpression para2 = new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "Name");
                methods[i].Parameters.Add(para2);
                CodeParameterDeclarationExpression para3 = new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "TypeId");
                methods[i].Parameters.Add(para3);
                methods[i].ReturnType = new CodeTypeReference("IEnumerable<T>");
                CodeTypeParameter param = new CodeTypeParameter("T");
                param.Constraints.Add(" class");
                methods[i].TypeParameters.Add(param);

                methods[i].Statements.Add(new CodeMethodReturnStatement(
                        new CodeMethodInvokeExpression(
                            new CodeMethodReferenceExpression(null, "findAllByNameExTemplate", new CodeTypeReference("T")),
                            new CodeVariableReferenceExpression("Name"),
                            new CodeVariableReferenceExpression("TypeId"),
                            new CodeArgumentReferenceExpression(interfaces[i].Name.Substring(3) + "." + methodName)

                    )));
            }
            return methods;
        }
开发者ID:xneo123,项目名称:SAPGuiAutomationLib,代码行数:39,代码来源:CodeGenerateHelper.cs


示例14: Constructor0

		public void Constructor0 ()
		{
			CodeTypeParameter ctp = new CodeTypeParameter ();

			Assert.IsNotNull (ctp.Constraints, "#1");
			Assert.AreEqual (0, ctp.Constraints.Count, "#2");
			Assert.IsNotNull (ctp.CustomAttributes, "#3");
			Assert.AreEqual (0, ctp.CustomAttributes.Count, "#4");
			Assert.IsFalse (ctp.HasConstructorConstraint, "#5");
			Assert.IsNotNull (ctp.Name, "#6");
			Assert.AreEqual (string.Empty, ctp.Name, "#7");

			ctp.Name = null;
			Assert.IsNotNull (ctp.Name, "#8");
			Assert.AreEqual (string.Empty, ctp.Name, "#9");

			string name = "mono";
			ctp.Name = name;
			Assert.AreSame (name, ctp.Name, "#10");

			ctp.HasConstructorConstraint = true;
			Assert.IsTrue (ctp.HasConstructorConstraint, "#11");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:CodeTypeParameterTest.cs


示例15: GenericTypeParameters

        public static CodeTypeParameterCollection GenericTypeParameters(Type t)
        {
            if (!t.IsGenericType) return null; 

            var p = new CodeTypeParameterCollection();
            foreach (var genericParameter in t.GetGenericTypeDefinition().GetGenericArguments())
            {
                var param = new CodeTypeParameter(genericParameter.Name);
                if ((genericParameter.GenericParameterAttributes &
                     GenericParameterAttributes.ReferenceTypeConstraint) != GenericParameterAttributes.None)
                {
                    param.Constraints.Add(" class");
                }
                if ((genericParameter.GenericParameterAttributes &
                     GenericParameterAttributes.NotNullableValueTypeConstraint) != GenericParameterAttributes.None)
                {
                    param.Constraints.Add(" struct");
                }
                var constraints = genericParameter.GetGenericParameterConstraints();
                foreach (var constraintType in constraints)
                {
                    param.Constraints.Add(
                        new CodeTypeReference(TypeUtils.GetParameterizedTemplateName(constraintType, false,
                            x => true)));
                }
                if ((genericParameter.GenericParameterAttributes &
                     GenericParameterAttributes.DefaultConstructorConstraint) != GenericParameterAttributes.None)
                {
                    param.HasConstructorConstraint = true;
                }
                p.Add(param);
            }
            return p;
        }
开发者ID:uehara,项目名称:orleans,代码行数:34,代码来源:TypeUtils.cs


示例16: OutputTypeParameterConstraints

 private void OutputTypeParameterConstraints(CodeTypeParameter typeParameter)
 {
     CodeTypeReferenceCollection constraints = typeParameter.Constraints;
     int count = constraints.Count;
     if (typeParameter.HasConstructorConstraint)
     {
         count++;
     }
     if (count != 0)
     {
         base.Output.Write(" As ");
         if (count > 1)
         {
             base.Output.Write(" {");
         }
         bool flag = true;
         foreach (CodeTypeReference reference in constraints)
         {
             if (flag)
             {
                 flag = false;
             }
             else
             {
                 base.Output.Write(", ");
             }
             base.Output.Write(this.GetTypeOutput(reference));
         }
         if (typeParameter.HasConstructorConstraint)
         {
             if (!flag)
             {
                 base.Output.Write(", ");
             }
             base.Output.Write("New");
         }
         if (count > 1)
         {
             base.Output.Write('}');
         }
     }
 }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:42,代码来源:VBCodeGenerator.cs


示例17: OutputTypeParameterConstraints

		void OutputTypeParameterConstraints (CodeTypeParameter parameter)
		{
			int constraint_count = parameter.Constraints.Count +
				(parameter.HasConstructorConstraint ? 1 : 0);

			if (constraint_count == 0)
				return;

			Output.Write (" As ");

			if (constraint_count > 1)
				Output.Write (" {");

			for (int i = 0; i < parameter.Constraints.Count; i++) {
				if (i > 0)
					Output.Write (", ");
				OutputType (parameter.Constraints [i]);
			}

			if (parameter.HasConstructorConstraint) {
				if (constraint_count > 1)
					Output.Write (", ");
				Output.Write ("New");
			}

			if (constraint_count > 1)
				Output.Write ("}");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:28,代码来源:VBCodeGenerator.cs


示例18: PopulateGenericParameters

        private static void PopulateGenericParameters(IGenericParameterProvider publicType, CodeTypeParameterCollection parameters)
        {
            foreach (var parameter in publicType.GenericParameters)
            {
                if (parameter.HasCustomAttributes)
                    throw new NotImplementedException("Attributes on type parameters is not supported. And weird");

                // A little hacky. Means we get "in" and "out" prefixed on any constraints, but it's either that
                // or add it as a custom attribute, which looks even weirder
                var name = parameter.Name;
                if (parameter.IsCovariant)
                    name = "out " + name;
                if (parameter.IsContravariant)
                    name = "in " + name;

                var typeParameter = new CodeTypeParameter(name)
                {
                    HasConstructorConstraint =
                        parameter.HasDefaultConstructorConstraint && !parameter.HasNotNullableValueTypeConstraint
                };
                if (parameter.HasNotNullableValueTypeConstraint)
                    typeParameter.Constraints.Add(" struct"); // Extra space is a hack!
                if (parameter.HasReferenceTypeConstraint)
                    typeParameter.Constraints.Add(" class");
                foreach (var constraint in parameter.Constraints.Where(t => t.FullName != "System.ValueType"))
                {
                    typeParameter.Constraints.Add(CreateCodeTypeReference(constraint.GetElementType()));
                }
                parameters.Add(typeParameter);
            }
        }
开发者ID:Particular,项目名称:ServiceControl.Plugin.Nsb6.CustomChecks,代码行数:31,代码来源:PublicApiGenerator.cs


示例19: ConvertRequestToGeneric

 static void ConvertRequestToGeneric(SdkMessagePair messagePair, CodeTypeDeclaration requestClass, CodeMemberProperty requestField)
 {
     var parameter = new CodeTypeParameter(requestField.Type.BaseType)
         {
             HasConstructorConstraint = true
         };
     parameter.Constraints.Add(new CodeTypeReference(EntityClassBaseType));
     requestClass.TypeParameters.Add(parameter);
     requestClass.Members.Add(Constructor(new CodeExpression[] {New(requestField.Type, new CodeExpression[0])}));
     var constructor = Constructor(Param(requestField.Type, "target"), new CodeStatement[] {AssignProp(requestField.Name, VarRef("target"))});
     constructor.Statements.Add(AssignProp(RequestNamePropertyName, new CodePrimitiveExpression(messagePair.Request.Name)));
     requestClass.Members.Add(constructor);
 }
开发者ID:snugglesftw,项目名称:Crm,代码行数:13,代码来源:CodeGenerationService.cs


示例20: VisitCodeTypeParameter

		void VisitCodeTypeParameter(CodeTypeParameter parameter)
		{
			WriteLine("VisitCodeTypeParameter: " + parameter.Name);
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:4,代码来源:CodeDomVisitor.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# CodeDom.CodeTypeParameterCollection类代码示例发布时间:2022-05-26
下一篇:
C# CodeDom.CodeTypeOfExpression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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