本文整理汇总了C#中System.CodeDom.CodeMethodReturnStatement类的典型用法代码示例。如果您正苦于以下问题:C# CodeMethodReturnStatement类的具体用法?C# CodeMethodReturnStatement怎么用?C# CodeMethodReturnStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeMethodReturnStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeMethodReturnStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitReturnStatement
private void EmitReturnStatement(CodeMethodReturnStatement Return)
{
Depth++;
Debug("Emitting return statement");
if (Method.ReturnType != typeof(void))
{
Type Top;
if (Return.Expression == null)
{
// Default to an empty string if this method expects a return value
Generator.Emit(OpCodes.Ldstr, "");
Top = typeof(string);
}
else Top = EmitExpression(Return.Expression);
if (Top != null)
ForceTopStack(Top, Method.ReturnType);
}
else if (Return.Expression != null)
throw new CompileException(Return, "Can not return value from void method " + Method.Name);
Generator.Emit(OpCodes.Ret);
Depth--;
}
示例2: GenerateCallStatementC2J
private CodeStatement GenerateCallStatementC2J(GMethod method, CodeExpression invokeExpression)
{
CodeStatement call;
if (method.IsConstructor || method.IsVoid)
{
call = new CodeExpressionStatement(invokeExpression);
}
else
{
if (method.ReturnType.IsPrimitive)
{
if (method.ReturnType.JVMSubst != null)
{
invokeExpression = new CodeCastExpression(method.ReturnType.CLRReference, invokeExpression);
}
call = new CodeMethodReturnStatement(invokeExpression);
}
else
{
CodeMethodInvokeExpression conversionExpression = CreateConversionExpressionJ2CParam(method.ReturnType,
invokeExpression);
call = new CodeMethodReturnStatement(conversionExpression);
}
}
return call;
}
示例3: 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);
}
示例4: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeExpression expression = new CodeExpression ();
CodeMethodReturnStatement cmrs = new CodeMethodReturnStatement (expression);
Assert.AreSame (expression, cmrs.Expression, "Expression");
cmrs.Expression = new CodeExpression ();
}
示例5: 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;
}
示例6: Compile
public override void Compile(IEnumerable<IColumInfoModel> columnInfos, Stream to = null)
{
if (string.IsNullOrEmpty(TableName))
{
TableName = TargetCsName;
}
var spAttribute = new CodeAttributeDeclaration(typeof(StoredProcedureAttribute).Name);
_base.CustomAttributes.Add(spAttribute);
if (_base.TypeParameters.Count == 0)
{
//_base.TypeParameters.Add(new CodeTypeParameter(typeof ().FullName));
}
//Create Caller
var createFactoryMethod = new CodeMemberMethod();
createFactoryMethod.Name = "Invoke" + TableName;
createFactoryMethod.ReturnType = new CodeTypeReference(typeof(QueryFactoryResult));
createFactoryMethod.CustomAttributes.Add(
new CodeAttributeDeclaration(typeof(SelectFactoryMethodAttribute).FullName));
//Create the Params
string query = "EXEC " + TableName;
var nameOfListOfParamater = "paramaters";
var listOfParams = new CodeObjectCreateExpression(typeof(List<IQueryParameter>));
var listOfParamscreator = new CodeVariableDeclarationStatement(typeof(List<IQueryParameter>), nameOfListOfParamater, listOfParams);
createFactoryMethod.Statements.Add(listOfParamscreator);
int i = 0;
foreach (var item in _base.Members)
{
if (item is CodeMemberProperty)
{
var variable = item as CodeMemberProperty;
var paramName = "param" + i++;
query += " @" + paramName + " ";
var createParams = new CodeObjectCreateExpression(typeof(QueryParameter),
new CodePrimitiveExpression(paramName),
new CodeVariableReferenceExpression(variable.Name));
var addToList =
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression(nameOfListOfParamater),
"Add", createParams);
createFactoryMethod.Statements.Add(addToList);
}
}
//Finaly create the instance
var createFactory = new CodeObjectCreateExpression(typeof(QueryFactoryResult),
new CodePrimitiveExpression(query),
new CodeMethodInvokeExpression(new CodeVariableReferenceExpression(nameOfListOfParamater), "ToArray"));
var queryFactoryVariable = new CodeMethodReturnStatement(createFactory);
createFactoryMethod.Statements.Add(queryFactoryVariable);
_base.Members.Add(createFactoryMethod);
}
示例7: AddMemberOverride
private void AddMemberOverride(string name, Type type, CodeExpression expr) {
CodeMemberProperty member = new CodeMemberProperty();
member.Name = name;
member.Attributes = MemberAttributes.Override | MemberAttributes.Family;
member.Type = new CodeTypeReference(type.FullName);
CodeMethodReturnStatement returnStmt = new CodeMethodReturnStatement(expr);
member.GetStatements.Add(returnStmt);
_sourceDataClass.Members.Add(member);
}
示例8: GeneraCodigo
private CodeCompileUnit GeneraCodigo()
{
//Unidad de Compilación (ensamblado)
var cu = new CodeCompileUnit();
cu.ReferencedAssemblies.Add("System.dll");//Ensamblados que enlaza (aunque este debería estar por defecto)
//Espacio de nombres
var n = new CodeNamespace("EjemploGeneracionCodigo1");
cu.Namespaces.Add(n);
n.Imports.Add(new CodeNamespaceImport("System"));//Espacios de nombres que utiliza este namespace para compilar
//Clase
var c = new CodeTypeDeclaration("ClaseGenerada");
n.Types.Add(c);
c.BaseTypes.Add(new CodeTypeReference(typeof(System.Timers.Timer)));//Su clase padre
c.IsPartial = true;
//Atributo de la clase
CodeMemberField mf = new CodeMemberField(typeof(string),"_atributo");
c.Members.Add(mf);
//Propiedad de la clase
CodeMemberProperty cp = new CodeMemberProperty();
c.Members.Add(cp);
cp.Attributes = MemberAttributes.Public | MemberAttributes.Final;//lo de Final para que no sea virtual (por defecto si es público es virtual)
cp.Type = new CodeTypeReference(typeof(string));
cp.Name = "atributo";
CodeFieldReferenceExpression cfre = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "_atributo");
CodeMethodReturnStatement mrs = new CodeMethodReturnStatement(cfre);
cp.GetStatements.Add(mrs);
//Metodo de la clase
CodeMemberMethod cmm = new CodeMemberMethod();
c.Members.Add(cmm);
cmm.Attributes = MemberAttributes.Public | MemberAttributes.Final;
cmm.Name = "Metodo1";
cmm.ReturnType = new CodeTypeReference(typeof(int));
CodeParameterDeclarationExpression pde = new CodeParameterDeclarationExpression(typeof(int),"enteroDeEntrada");
cmm.Parameters.Add(pde);
pde = new CodeParameterDeclarationExpression(typeof(string),"cadenaDeEntrada");
cmm.Parameters.Add(pde);
//Declaración de variable
CodeVariableDeclarationStatement vds = new CodeVariableDeclarationStatement(typeof(string),"aux",new CodePrimitiveExpression("Prueba1") );
cmm.Statements.Add(vds);
//Llamar a método arbitrario
//variable a llamar y método
CodeMethodReferenceExpression ctr = new CodeMethodReferenceExpression(new CodeVariableReferenceExpression("Console"),"WriteLine");
//Llamada en sí con sus parámetros
CodeMethodInvokeExpression invoke1 = new CodeMethodInvokeExpression( ctr, new CodeExpression[] {new CodePrimitiveExpression("Hola mundo")} );
cmm.Statements.Add(invoke1);
//Código a pelo. Ojo no se puede generar, por ejemplo, un foreach.
cmm.Statements.Add(new CodeSnippetStatement("foreach(string s in cadenas){"));
cmm.Statements.Add(new CodeSnippetStatement("Console.WriteLine(s);"));
cmm.Statements.Add(new CodeSnippetStatement("}"));
mrs = new CodeMethodReturnStatement(new CodePrimitiveExpression(42));
cmm.Statements.Add(mrs);
return cu;
}
示例9: Emit
// Generate a codedom return statement.
public static CodeStatement Emit(Return r)
{
var codeMethodReturnStatement = new CodeMethodReturnStatement();
// Attach the expression to return, if any.
if(r.ChildExpressions.Count > 0)
codeMethodReturnStatement.Expression = CodeDomEmitter.EmitCodeExpression(r.ChildExpressions[0]);
return codeMethodReturnStatement;
}
示例10: Clone
public static CodeMethodReturnStatement Clone(this CodeMethodReturnStatement statement)
{
if (statement == null) return null;
CodeMethodReturnStatement s = new CodeMethodReturnStatement();
s.EndDirectives.AddRange(statement.EndDirectives);
s.Expression = statement.Expression.Clone();
s.LinePragma = statement.LinePragma;
s.StartDirectives.AddRange(statement.StartDirectives);
s.UserData.AddRange(statement.UserData);
return s;
}
示例11: TypescriptMethodReturnStatement
public TypescriptMethodReturnStatement(
IStatementFactory statementFactory,
IExpressionFactory expressionFactory,
CodeMethodReturnStatement statement,
CodeGeneratorOptions options)
{
_statementFactory = statementFactory;
_expressionFactory = expressionFactory;
_statement = statement;
_options = options;
}
示例12: AddMemberOverride
private void AddMemberOverride(string name, Type type, CodeExpression expr)
{
CodeMemberProperty property = new CodeMemberProperty {
Name = name,
Attributes = MemberAttributes.Family | MemberAttributes.Override,
Type = new CodeTypeReference(type.FullName)
};
CodeMethodReturnStatement statement = new CodeMethodReturnStatement(expr);
property.GetStatements.Add(statement);
base._sourceDataClass.Members.Add(property);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:PageThemeCodeDomTreeGenerator.cs
示例13: AddFactoryMethod
internal void AddFactoryMethod(string typeToCreate)
{
CodeMemberMethod method = new CodeMemberMethod {
Name = GetCreateMethodNameForType(typeToCreate),
ReturnType = new CodeTypeReference(typeof(object)),
Attributes = MemberAttributes.Static
};
CodeMethodReturnStatement statement = new CodeMethodReturnStatement(new CodeObjectCreateExpression(typeToCreate, new CodeExpression[0]));
method.Statements.Add(statement);
this._factoryClass.Members.Add(method);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:ObjectFactoryCodeDomTreeGenerator.cs
示例14: CreateMember
/// <summary>
///
/// </summary>
/// <param name="member"></param>
/// <param name="inner"></param>
/// <param name="attrs"></param>
/// <returns></returns>
public CodeTypeMember CreateMember(MemberInfo member, CodeFieldReferenceExpression inner, MemberAttributes attrs)
{
Debug.Assert(member is MethodInfo);
MethodInfo method = member as MethodInfo;
CodeMemberMethod codeMethod = new CodeMemberMethod();
codeMethod.Name = method.Name;
codeMethod.ReturnType = new CodeTypeReference(method.ReturnType);
codeMethod.Attributes = attrs;
// try
CodeTryCatchFinallyStatement tryCode = new CodeTryCatchFinallyStatement();
// decleare parameters
List<CodeArgumentReferenceExpression> codeParamiteRefrs = new List<CodeArgumentReferenceExpression>();
foreach (ParameterInfo codeParameter in method.GetParameters()) {
CodeParameterDeclarationExpression codeParameterDeclare = new CodeParameterDeclarationExpression(codeParameter.ParameterType, codeParameter.Name);
codeMethod.Parameters.Add(codeParameterDeclare);
codeParamiteRefrs.Add(new CodeArgumentReferenceExpression(codeParameter.Name));
}
// invoke
CodeMethodInvokeExpression invokeMethod = new CodeMethodInvokeExpression(
inner, method.Name, codeParamiteRefrs.ToArray());
if (method.ReturnType.Name.ToLower() == "void") {
tryCode.TryStatements.Add(invokeMethod);
} else {
CodeVariableDeclarationStatement var = new CodeVariableDeclarationStatement(method.ReturnType, "returnObject", invokeMethod);
//CodeAssignStatement assign = new CodeAssignStatement(var, invokeMethod);
tryCode.TryStatements.Add(var);
CodeCommentStatement todo = new CodeCommentStatement("TODO: your code", false);
tryCode.TryStatements.Add(todo);
CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression("returnObject");
CodeMethodReturnStatement codeReturn = new CodeMethodReturnStatement(varRef);
tryCode.TryStatements.Add(codeReturn);
}
// catch
CodeTypeReference codeTypeRef = new CodeTypeReference(typeof(Exception));
CodeCatchClause catchClause = new CodeCatchClause("ex", codeTypeRef);
catchClause.Statements.Add(new CodeThrowExceptionStatement());
tryCode.CatchClauses.Add(catchClause);
codeMethod.Statements.Add(tryCode);
return codeMethod;
}
示例15: AddCodeForGetProfileForUser
private void AddCodeForGetProfileForUser(CodeTypeDeclaration type)
{
CodeMemberMethod method = new CodeMemberMethod {
Name = "GetProfile",
Attributes = MemberAttributes.Public,
ReturnType = new CodeTypeReference("ProfileCommon")
};
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "username"));
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression {
Method = { TargetObject = new CodeTypeReferenceExpression("ProfileBase"), MethodName = "Create" }
};
expression.Parameters.Add(new CodeArgumentReferenceExpression("username"));
CodeMethodReturnStatement statement = new CodeMethodReturnStatement(new CodeCastExpression(method.ReturnType, expression));
MTConfigUtil.GetProfileAppConfig();
method.Statements.Add(statement);
type.Members.Add(method);
}