本文整理汇总了C#中System.CodeDom.CodeMethodInvokeExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeMethodInvokeExpression类的具体用法?C# CodeMethodInvokeExpression怎么用?C# CodeMethodInvokeExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeMethodInvokeExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeMethodInvokeExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitImplementationCode
public void EmitImplementationCode (CodeTypeDeclaration ctd)
{
byte[] bytes = Hash;
int hash = 0;
for (int i = 0; bytes.Length - i > 3; i += 4)
hash ^= BitConverter.ToInt32 (bytes, i);
// Insane Clown Property
CodeMemberProperty icp = new CodeMemberProperty ();
icp.Name = "ImplementationCode";
icp.Attributes = MemberAttributes.Family | MemberAttributes.Override;
icp.Type = new CodeTypeReference (typeof (int));
icp.HasGet = true;
icp.HasSet = false;
// get { return base.ImplementationCode ^ [number] }
// becomes:
// get { return LameCodeDomXor (base.ImplementationCode, [number]); }
CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression ();
invoke.Method = new CodeMethodReferenceExpression (CDH.This, "LameCodeDomXor");
invoke.Parameters.Add (new CodePropertyReferenceExpression (CDH.Base, "ImplementationCode"));
invoke.Parameters.Add (new CodePrimitiveExpression (hash));
icp.GetStatements.Add (new CodeMethodReturnStatement (invoke));
ctd.Members.Add (icp);
}
示例2: EmitGetFingerprint
public void EmitGetFingerprint (CodeTypeDeclaration ctd)
{
byte[] hash = Hash;
CodeArrayCreateExpression mkdata = new CodeArrayCreateExpression (CDH.Byte, hash.Length);
for (int i = 0; i < hash.Length; i++)
// well, this for loop sucks
mkdata.Initializers.Add (new CodePrimitiveExpression (hash[i]));
CodeMemberMethod m = new CodeMemberMethod ();
m.Name = "GetFingerprint";
m.Attributes = MemberAttributes.Public | MemberAttributes.Override;
m.ReturnType = CDH.Fingerprint;
m.Parameters.Add (CDH.Param (CDH.IContext, "unused1"));
m.Parameters.Add (CDH.Param (CDH.Fingerprint, "unused2"));
CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression ();
invoke.Method = new CodeMethodReferenceExpression (Generic, "Constant");
invoke.Parameters.Add (mkdata);
m.Statements.Add (new CodeMethodReturnStatement (invoke));
ctd.Members.Add (m);
}
示例3: Visit
public void Visit(WhileStatement whileStatement)
{
using (Scope.Push(_mainType))
{
var tableArg = VisitChild(whileStatement.TableReference);
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "While_" + tableArg.MethodIdentifier;
method.Attributes = MemberAttributes.Private;
GenerateCallStatement(method.Statements, whileStatement.Line.Line);
var loop = new CodeIterationStatement();
loop.InitStatement = new CodeSnippetStatement();
loop.IncrementStatement = new CodeSnippetStatement();
loop.TestExpression = new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(tableArg.CodeExpression, "RowCount"), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(0));
method.Statements.Add(loop);
var blockArgs = VisitChild(whileStatement.Block, new CodeDomArg() { Tag = true });
loop.Statements.AddRange(blockArgs.ParentStatements);
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_mainType.Type.Members.Add(method);
_codeStack.Peek().ParentStatements.Add(methodcall);
_codeStack.Peek().CodeExpression = methodcall;
}
}
示例4: Visit
public void Visit(GetDatePrimitive primitive)
{
var expression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("PrimitiveFunctions"), "GetDate");
_codeStack.Peek().Scope = new ScopeData<Type> { Type = typeof(DateTime), CodeDomReference = new CodeTypeReference(typeof(DateTime)) };
_codeStack.Peek().CodeExpression = expression;
}
示例5: Run
public void Run()
{
var compileUnit = new CodeCompileUnit();
var myNamespace = new CodeNamespace("MyNamespace");
myNamespace.Imports.Add(new CodeNamespaceImport("System"));
var myClass = new CodeTypeDeclaration("MyClass");
var start = new CodeEntryPointMethod();
var cs1 = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("Console"),
"WriteLine", new CodePrimitiveExpression("Hello World!"));
compileUnit.Namespaces.Add(myNamespace);
myNamespace.Types.Add(myClass);
myClass.Members.Add(start);
start.Statements.Add(cs1);
var provider = new CSharpCodeProvider();
using (var sw = new StreamWriter("HelloWorld.cs", false))
{
var tw = new IndentedTextWriter(sw, " ");
provider.GenerateCodeFromCompileUnit(compileUnit, tw,
new CodeGeneratorOptions());
tw.Close();
}
}
示例6: Visit
public void Visit(PickStatement statement)
{
VerifyCssSelector(statement.Selector, new Semantic.LineInfo(statement.Line.Line, statement.Line.CharacterPosition));
_codeStack.Peek()
.ParentStatements.Add(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression("result"),
"AddColumn",
new CodePrimitiveExpression(statement.Selector)));
var expression = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("node"),
"Pick",
new CodePrimitiveExpression(statement.Selector)
);
var takeDomArg = VisitChild(statement.TakeStatement);
var takeExpression = takeDomArg.CodeExpression as CodeMethodInvokeExpression;
takeExpression.Method.TargetObject = expression;
if (statement.Match != null && statement.Match.Replace != null)
{
takeExpression = new CodeMethodInvokeExpression(takeExpression, "MatchReplace", new CodePrimitiveExpression(statement.Match.Value), new CodePrimitiveExpression(statement.Match.Replace.Value));
}
else if (statement.Match != null)
{
takeExpression = new CodeMethodInvokeExpression(takeExpression, "Match", new CodePrimitiveExpression(statement.Match.Value));
}
_codeStack.Peek().Tag = true;
_codeStack.Peek().CodeExpression = takeExpression;
_codeStack.Peek().Scope = new ScopeData<Type> { Type = typeof(string), CodeDomReference = new CodeTypeReference(typeof(string)) };
}
示例7: Serialize
public override object Serialize(IDesignerSerializationManager manager, object value)
{
object obj2 = ((CodeDomSerializer) manager.GetSerializer(typeof(ImageList).BaseType, typeof(CodeDomSerializer))).Serialize(manager, value);
ImageList list = value as ImageList;
if (list != null)
{
StringCollection keys = list.Images.Keys;
if (!(obj2 is CodeStatementCollection))
{
return obj2;
}
CodeExpression targetObject = base.GetExpression(manager, value);
if (targetObject == null)
{
return obj2;
}
CodeExpression expression2 = new CodePropertyReferenceExpression(targetObject, "Images");
if (expression2 == null)
{
return obj2;
}
for (int i = 0; i < keys.Count; i++)
{
if ((keys[i] != null) || (keys[i].Length != 0))
{
CodeMethodInvokeExpression expression3 = new CodeMethodInvokeExpression(expression2, "SetKeyName", new CodeExpression[] { new CodePrimitiveExpression(i), new CodePrimitiveExpression(keys[i]) });
((CodeStatementCollection) obj2).Add(expression3);
}
}
}
return obj2;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:ImageListCodeDomSerializer.cs
示例8: GenerateCreateRequestMethod
/// <summary>
/// Generates the <c>IRequestProvider.CreateRequest()</c> method.
/// </summary>
/// <returns><c>CodeMemberMethod</c> describing the method.</returns>
internal CodeMemberMethod GenerateCreateRequestMethod()
{
var method = new CodeMemberMethod();
method.Name = CreateRequestMethodName;
method.ImplementationTypes.Add(typeof(IRequestProvider));
method.ReturnType = new CodeTypeReference(typeof(IRequest));
method.Attributes = MemberAttributes.Public;
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "resource"));
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "method"));
//Google.Apis.Requests.Request request = this.genericService.CreateRequest(resource, method);
method.Statements.Add(CreateRequestLocalVar());
// if (string.IsNullOrEmpty(APIKey) == false)
// request = request.WithAPIKey(APIKey)
method.Statements.Add(CreateWithApiKey());
// return request.WithAuthentication(authenticator);
var statement =
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodeVariableReferenceExpression("request"), "WithAuthentication"),
new CodeVariableReferenceExpression(ServiceClassGenerator.AuthenticatorName));
var returnStatment = new CodeMethodReturnStatement(statement);
method.Statements.Add(returnStatment);
return method;
}
示例9: LocalMethodInvoke
private CodeMethodInvokeExpression LocalMethodInvoke(string name)
{
var invoke = new CodeMethodInvokeExpression();
invoke.Method.MethodName = name;
invoke.Method.TargetObject = null;
return invoke;
}
示例10: WriteCode
public override void WriteCode(ISequenceVisitor visitor, TemplateContext ctx)
{
//base.WriteCode(ctx);
var handlerMethod = ctx.CurrentDeclaration.protected_virtual_func(typeof(void), Name, Name.ToLower());
var handlerInvoke = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), Name);
foreach (CodeParameterDeclarationExpression item in ctx.CurrentMethod.Parameters)
{
handlerMethod.Parameters.Add(item);
handlerInvoke.Parameters.Add(new CodeVariableReferenceExpression(item.Name));
}
//foreach (var item in AllContextVariables)
//{
// if (item.IsSubVariable) continue;
// var type = item.SourceVariable == null ? item.Name : item.SourceVariable.RelatedTypeName;
// handlerMethod.Parameters.Add(new CodeParameterDeclarationExpression(
// type , item.AsParameter));
// handlerInvoke.Parameters.Add(new CodeVariableReferenceExpression(item.ToString()));
//}
ctx.CurrentStatements.Add(handlerInvoke);
//ctx.PushStatements(handlerMethod.Statements);
//ctx.PopStatements();
}
示例11: DownloadImpl
private CodeMemberMethod DownloadImpl(AstNode statement, string methodName, CodeTypeReference returnType, int line)
{
var statementDomArg = VisitChild(statement);
if(statementDomArg.Scope.CodeDomReference.BaseType == typeof(Table<>).Name)
{
if (statementDomArg.Tag != null)
((Action)statementDomArg.Tag)(); //remove call to OnSelect
}
else if( statementDomArg.Scope.CodeDomReference.BaseType != typeof(string).FullName)
Errors.Add(new DownloadRequireString(new Semantic.LineInfo(statement.Line.Line, statement.Line.CharacterPosition)));
CodeMemberMethod method = new CodeMemberMethod();
method.Name = "Download_" + statementDomArg.MethodIdentifier;
method.Attributes = MemberAttributes.Private;
method.ReturnType = returnType;
GenerateCallStatement(method.Statements, line);
method.Statements.Add(new CodeMethodReturnStatement(
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(new CodeTypeReferenceExpression("Http"), methodName), new CodeThisReferenceExpression(),
statementDomArg.CodeExpression, new CodePrimitiveExpression(line))));
_mainType.Type.Members.Add(method);
var methodcall = new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(null, method.Name));
_codeStack.Peek().CodeExpression = methodcall;
return method;
}
示例12: AddEntryPoint
static void AddEntryPoint()
{
CodeEntryPointMethod start = new CodeEntryPointMethod();
CodeObjectCreateExpression objectCreate =
new CodeObjectCreateExpression(
new CodeTypeReference("CodeDOMCreatedClass"),
new CodePrimitiveExpression(5.3),
new CodePrimitiveExpression(6.9));
// Add the statement:
// "CodeDOMCreatedClass testClass =
// new CodeDOMCreatedClass(5.3, 6.9);"
start.Statements.Add(new CodeVariableDeclarationStatement(
new CodeTypeReference("CodeDOMCreatedClass"), "testClass",
objectCreate));
// Creat the expression:
// "testClass.ToString()"
CodeMethodInvokeExpression toStringInvoke =
new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("testClass"), "ToString");
// Add a System.Console.WriteLine statement with the previous
// expression as a parameter.
start.Statements.Add(new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("System.Console"),
"WriteLine", toStringInvoke));
targetClass.Members.Add(start);
}
示例13: Constructor0
public void Constructor0 ()
{
CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression ();
Assert.IsNotNull (cmie.Method, "#1");
Assert.AreEqual (string.Empty, cmie.Method.MethodName, "#2");
Assert.IsNull (cmie.Method.TargetObject, "#3");
#if NET_2_0
Assert.AreEqual (0, cmie.Method.TypeArguments.Count, "#4");
#endif
Assert.IsNotNull (cmie.Parameters, "#5");
Assert.AreEqual (0, cmie.Parameters.Count, "#6");
CodeMethodReferenceExpression method = new CodeMethodReferenceExpression ();
cmie.Method = method;
Assert.IsNotNull (cmie.Method, "#7");
Assert.AreSame (method, cmie.Method, "#8");
cmie.Method = null;
Assert.IsNotNull (cmie.Method, "#9");
Assert.AreEqual (string.Empty, cmie.Method.MethodName, "#10");
Assert.IsNull (cmie.Method.TargetObject, "#11");
#if NET_2_0
Assert.AreEqual (0, cmie.Method.TypeArguments.Count, "#12");
#endif
}
示例14: Visit
public override void Visit(ViewTreeNode node)
{
if (typeStack.Count == 0) return;
var constructionArguments = new CodeExpression[]
{
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
new CodeTypeOfExpression(node.Controller.FullName),
new CodePrimitiveExpression(node.Controller.Area),
new CodePrimitiveExpression(naming.ToControllerName(node.Controller.Name)),
new CodePrimitiveExpression(node.Name)
};
CodeExpression returnExpression =
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodePropertyReferenceExpression(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
"ControllerReferenceFactory"),
"CreateViewReference"),
constructionArguments);
var propertyType = new CodeTypeReference(typeof (IControllerViewReference));
typeStack.Peek().Members.Add(source.CreateReadOnlyProperty(node.Name, propertyType, returnExpression));
base.Visit(node);
}
示例15: AddPropertyGroup
private void AddPropertyGroup(AssemblyBuilder assemblyBuilder, string groupName, string propertyNames, Hashtable properties, CodeTypeDeclaration type, CodeNamespace ns)
{
CodeMemberProperty property = new CodeMemberProperty {
Name = groupName,
Attributes = MemberAttributes.Public,
HasGet = true,
Type = new CodeTypeReference("ProfileGroup" + groupName)
};
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
Method = { TargetObject = new CodeThisReferenceExpression(), MethodName = "GetProfileGroup" }
};
expression.Parameters.Add(new CodePrimitiveExpression(property.Name));
CodeMethodReturnStatement statement = new CodeMethodReturnStatement(new CodeCastExpression(property.Type, expression));
property.GetStatements.Add(statement);
type.Members.Add(property);
CodeTypeDeclaration declaration = new CodeTypeDeclaration {
Name = "ProfileGroup" + groupName
};
declaration.BaseTypes.Add(new CodeTypeReference(typeof(ProfileGroupBase)));
foreach (string str in propertyNames.Split(new char[] { ';' }))
{
this.CreateCodeForProperty(assemblyBuilder, declaration, (ProfileNameTypeStruct) properties[str]);
}
ns.Types.Add(declaration);
}