本文整理汇总了C#中CodeDomProvider.Supports方法的典型用法代码示例。如果您正苦于以下问题:C# CodeDomProvider.Supports方法的具体用法?C# CodeDomProvider.Supports怎么用?C# CodeDomProvider.Supports使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeDomProvider
的用法示例。
在下文中一共展示了CodeDomProvider.Supports方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildTree
public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu) {
#if WHIDBEY
// GENERATES (C#):
// namespace TestNamespace {
// using System;
// using System.Collections.Generic;
//
//
// public class MyDictionary<K, V> : Dictionary<K, V>
// where K : System.IComparable, IComparable<K>, new ()
// where V : IList<string> {
//
// public virtual int Calculate<S, T>(int value1, int value2)
// where S : new()
// {
// return (value1 * value2);
// }
// }
//
// public class Test {
//
// public virtual int MyMethod() {
// int dReturn;
// MyDictionary<int, List<string>> dict = new MyDictionary<int, List<string>>();
// dReturn = dict.Calculate<int, int>(2.5, 11);
// return dReturn;
// }
// }
// }
if (!provider.Supports(GeneratorSupport.GenericTypeReference | GeneratorSupport.GenericTypeDeclaration)) {
return;
}
CodeNamespace ns = new CodeNamespace("TestNamespace");
ns.Imports.Add(new CodeNamespaceImport("System"));
ns.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
cu.Namespaces.Add (ns);
// Declare a generic class
CodeTypeDeclaration class1 = new CodeTypeDeclaration();
class1.Name = "MyDictionary";
class1.BaseTypes.Add( new CodeTypeReference("Dictionary",
new CodeTypeReference[] { new CodeTypeReference("K"), new CodeTypeReference("V"),}));
CodeTypeParameter kType = new CodeTypeParameter("K");
kType.HasConstructorConstraint= true;
kType.Constraints.Add( new CodeTypeReference(typeof(IComparable)));
kType.CustomAttributes.Add(new CodeAttributeDeclaration(
"System.ComponentModel.DescriptionAttribute", new CodeAttributeArgument(new CodePrimitiveExpression("KeyType"))));
CodeTypeReference iComparableT = new CodeTypeReference("IComparable");
iComparableT.TypeArguments.Add(new CodeTypeReference(kType));
kType.Constraints.Add(iComparableT);
CodeTypeParameter vType = new CodeTypeParameter("V");
vType.Constraints.Add(new CodeTypeReference("IList[System.String]"));
class1.TypeParameters.Add(kType);
class1.TypeParameters.Add(vType);
ns.Types.Add(class1);
// declare a generic method
CodeMemberMethod method = new CodeMemberMethod();
CodeTypeParameter sType = new CodeTypeParameter("S");
sType.HasConstructorConstraint = true;
CodeTypeParameter tType = new CodeTypeParameter("T");
sType.HasConstructorConstraint = true;
method.Name = "Calculate";
method.TypeParameters.Add(sType);
method.TypeParameters.Add(tType);
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "value1"));
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(int), "value2"));
method.ReturnType = new CodeTypeReference(typeof(int));
method.Statements.Add(new CodeMethodReturnStatement(new CodeBinaryOperatorExpression(new
CodeVariableReferenceExpression("value1"), CodeBinaryOperatorType.Multiply, new
CodeVariableReferenceExpression("value2"))));
method.Attributes = MemberAttributes.Public;
class1.Members.Add(method);
CodeTypeDeclaration class2 = new CodeTypeDeclaration();
class2.Name = "Test";
AddScenario ("CheckMyMethod");
CodeMemberMethod method2 = new CodeMemberMethod();
method2.Name = "MyMethod";
method2.Attributes = MemberAttributes.Public;
method2.ReturnType = new CodeTypeReference(typeof(int));
method2.Statements.Add( new CodeVariableDeclarationStatement(typeof(int), "dReturn"));
CodeTypeReference myClass = new CodeTypeReference( "MyDictionary",
//.........这里部分代码省略.........
示例2: BuildTree
//.........这里部分代码省略.........
cu.Namespaces.Add (ns);
CodeTypeDeclaration cd = new CodeTypeDeclaration ("Class1");
ns.Types.Add (cd);
cd.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Outer Type Region"));
cd.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));
cd.Comments.Add (new CodeCommentStatement ("Outer Type Comment"));
CodeMemberField field1 = new CodeMemberField (typeof (String), "field1");
CodeMemberField field2 = new CodeMemberField (typeof (String), "field2");
field1.Comments.Add (new CodeCommentStatement ("Field 1 Comment"));
field2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Field Region"));
field2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));
CodeMemberEvent evt1 = new CodeMemberEvent ();
evt1.Name = "Event1";
evt1.Type = new CodeTypeReference (typeof (System.EventHandler));
evt1.Attributes = (evt1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
CodeMemberEvent evt2 = new CodeMemberEvent ();
evt2.Name = "Event2";
evt2.Type = new CodeTypeReference (typeof (System.EventHandler));
evt2.Attributes = (evt2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
evt2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Event Region"));
evt2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));
CodeMemberMethod method1 = new CodeMemberMethod ();
method1.Name = "Method1";
method1.Attributes = (method1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
if (provider.Supports (GeneratorSupport.DeclareEvents)) {
method1.Statements.Add (
new CodeDelegateInvokeExpression (
new CodeEventReferenceExpression (new CodeThisReferenceExpression (), "Event1"),
new CodeExpression[] {
new CodeThisReferenceExpression(),
new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
}));
}
CodeMemberMethod method2 = new CodeMemberMethod ();
method2.Name = "Method2";
method2.Attributes = (method2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
if (provider.Supports (GeneratorSupport.DeclareEvents)) {
method2.Statements.Add (
new CodeDelegateInvokeExpression (
new CodeEventReferenceExpression (new CodeThisReferenceExpression (), "Event2"),
new CodeExpression[] {
new CodeThisReferenceExpression(),
new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
}));
}
method2.LinePragma = new CodeLinePragma ("MethodLinePragma.txt", 500);
method2.Comments.Add (new CodeCommentStatement ("Method 2 Comment"));
method2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Method Region"));
method2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));
CodeMemberProperty property1 = new CodeMemberProperty ();
property1.Name = "Property1";
property1.Type = new CodeTypeReference (typeof (string));
示例3: VerifyAssembly
public override void VerifyAssembly (CodeDomProvider provider, Assembly asm) {
#if WHIDBEY
if (provider.Supports(GeneratorSupport.GenericTypeReference | GeneratorSupport.GenericTypeDeclaration)) {
object genObject;
Type genType;
AddScenario ("InstantiateTest");
if (!FindAndInstantiate ("TestNamespace.Test", asm, out genObject, out genType))
return;
VerifyScenario ("InstantiateTest");
// verify scenario with 'new' attribute
if (VerifyMethod(genType, genObject, "MyMethod", null, 275)) {
VerifyScenario ("CheckMyMethod");
}
}
#endif
}