本文整理汇总了C#中System.CodeDom.CodeMethodReturnStatement类的典型用法代码示例。如果您正苦于以下问题:C# CodeMethodReturnStatement类的具体用法?C# CodeMethodReturnStatement怎么用?C# CodeMethodReturnStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeMethodReturnStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeMethodReturnStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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--;
}
开发者ID:Tyelpion,项目名称:IronAHK,代码行数:27,代码来源:EmitFlow.cs
示例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;
}
开发者ID:Mazrick,项目名称:jni4net,代码行数:26,代码来源:CLRGenerator.C2J.cs
示例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);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:ProfileBuildProvider.cs
示例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 ();
}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeMethodReturnStatementCas.cs
示例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;
}
开发者ID:jithuin,项目名称:infogeezer,代码行数:33,代码来源:CreateRequestMethodServiceDecorator.cs
示例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);
}
开发者ID:JPVenson,项目名称:DataAccess,代码行数:57,代码来源:ProcedureCompiler.cs
示例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);
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:9,代码来源:PageThemeCodeDomTreeGenerator.cs
示例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;
}
开发者ID:IvanCruzFraguela,项目名称:EjemploGeneracionCodigo,代码行数:56,代码来源:MainForm.cs
示例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;
}
开发者ID:maleficus1234,项目名称:Pie,代码行数:11,代码来源:ReturnEmitter.cs
示例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;
}
开发者ID:svejdo1,项目名称:CodeDomExtensions,代码行数:11,代码来源:CodeMethodReturnStatementExtensions.cs
示例11: TypescriptMethodReturnStatement
public TypescriptMethodReturnStatement(
IStatementFactory statementFactory,
IExpressionFactory expressionFactory,
CodeMethodReturnStatement statement,
CodeGeneratorOptions options)
{
_statementFactory = statementFactory;
_expressionFactory = expressionFactory;
_statement = statement;
_options = options;
}
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:11,代码来源:TypescriptMethodReturnStatement.cs
示例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;
}
开发者ID:yangwen27,项目名称:moonlit,代码行数:56,代码来源:MemberMethodInfoFactory.cs
示例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);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:ProfileBuildProvider.cs
示例16: CreateProperty
public CodeMemberProperty CreateProperty(Type type, string propertyName)
{
var codeMemberProperty = new CodeMemberProperty
{
Name = propertyName,
HasGet = true,
HasSet = true,
Attributes = MemberAttributes.Public,
Type = new CodeTypeReference(type)
};
var fieldName = propertyName.MakeFirstCharLowerCase();
var codeFieldReferenceExpression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldName);
var returnStatement = new CodeMethodReturnStatement(codeFieldReferenceExpression);
codeMemberProperty.GetStatements.Add(returnStatement);
var assignStatement = new CodeAssignStatement(codeFieldReferenceExpression, new CodePropertySetValueReferenceExpression());
codeMemberProperty.SetStatements.Add(assignStatement);
return codeMemberProperty;
}
开发者ID:DelLitt,项目名称:opmscoral,代码行数:18,代码来源:CodeGenerationHelper.cs
示例17: GenerateMethodReturnStatement
protected override void GenerateMethodReturnStatement(CodeMethodReturnStatement e)
{
Output.WriteLine("[CodeMethodReturnStatement: {0}]", e.ToString());
}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:4,代码来源:CodeDOMVerboseOutputGenerator.cs
示例18: CreateAndAddGetViewAtMethod
/// <summary>
/// Generate Code to put the views in the generated code.
/// </summary>
/// <param name="typeDeclaration"></param>
/// <param name="generatedViews"></param>
/// <returns></returns>
private static void CreateAndAddGetViewAtMethod(CodeTypeDeclaration typeDeclaration, Dictionary<EntitySetBase, string> generatedViews)
{
//Add the views to a method
CodeMemberMethod getViewAtMethod = new CodeMemberMethod();
getViewAtMethod.Name = EntityViewGenerationConstants.GetViewAtMethodName;
getViewAtMethod.ReturnType = new CodeTypeReference(typeof(KeyValuePair<,>).MakeGenericType(new Type[] { typeof(string), typeof(string) }));
CodeParameterDeclarationExpression parameter = new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "index");
getViewAtMethod.Parameters.Add(parameter);
getViewAtMethod.Comments.Add(new CodeCommentStatement(EntityViewGenerationConstants.SummaryStartElement, true /*docComment*/));
getViewAtMethod.Comments.Add(new CodeCommentStatement(Strings.GetViewAtMethodComments, true /*docComment*/));
getViewAtMethod.Comments.Add(new CodeCommentStatement(EntityViewGenerationConstants.SummaryEndElement, true /*docComment*/));
getViewAtMethod.Attributes = MemberAttributes.Family | MemberAttributes.Override;
typeDeclaration.Members.Add(getViewAtMethod);
int index = 0;
CodeVariableReferenceExpression indexParameterReference = new CodeVariableReferenceExpression(getViewAtMethod.Parameters[0].Name);
foreach (KeyValuePair<EntitySetBase, string> generatedViewPair in generatedViews)
{
// the CodeDom does not support the following scenarios
// 1. switch statement
// 2. if(){} else if(){}
// The original design here was to have the following code,
// if() { else { if(){} } }
// but this had some drawbacks as described in TFS workitem 590996
// Given the not supported scenarios in CodeDom, we choose only use if statement in this case
// if(index == 0)
CodeConditionStatement currentIf = new CodeConditionStatement(new CodeBinaryOperatorExpression(
indexParameterReference, CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(index)));
getViewAtMethod.Statements.Add(currentIf);
EntitySetBase entitySet = generatedViewPair.Key;
string extentFullName = GetExtentFullName(entitySet);
CodeMemberMethod viewMethod = CreateViewReturnMethod(extentFullName, index, generatedViewPair.Value);
typeDeclaration.Members.Add(viewMethod);
// return GetNorthwindContext_Customers();
CodeMethodReturnStatement returnViewMethodCall = new CodeMethodReturnStatement(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(null, viewMethod.Name)));
currentIf.TrueStatements.Add(returnViewMethodCall);
index++;
}
// if an invalid index is asked for throw
getViewAtMethod.Statements.Add(new CodeThrowExceptionStatement(
new CodeObjectCreateExpression(new CodeTypeReference(typeof(IndexOutOfRangeException)))));
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:58,代码来源:EntityViewGenerator.cs
示例19: Return
public CodeMethodReturnStatement Return(CodeExpression expr)
{
CodeMethodReturnStatement st = new CodeMethodReturnStatement(expr);
csc.Add(st);
return st;
}
开发者ID:almazik,项目名称:ILSpy,代码行数:6,代码来源:EasyCodeDom.cs
示例20: AddMembersTo
//.........这里部分代码省略.........
var specifiedDocs = new[] { new DocumentationModel { Language = "en", Text = string.Format("Gets or sets a value indicating whether the {0} property is specified.", Name) },
new DocumentationModel { Language = "de", Text = string.Format("Ruft einen Wert ab, der angibt, ob die {0}-Eigenschaft spezifiziert ist, oder legt diesen fest.", Name) } };
specifiedMember.Comments.AddRange(DocumentationModel.GetComments(specifiedDocs).ToArray());
typeDeclaration.Members.Add(specifiedMember);
if (Configuration.GenerateNullables)
{
// public X? Name
// {
// get { return NameSpecified ? NameValue : null; }
// set
// {
// NameValue = value.GetValueOrDefault();
// NameSpecified = value.HasValue;
// }
// }
var nullableType = new CodeTypeReference(typeof(Nullable<>));
nullableType.TypeArguments.Add(typeReference);
var nullableMember = new CodeMemberProperty
{
Type = nullableType,
Name = Name,
HasSet = true,
HasGet = true,
Attributes = MemberAttributes.Public | MemberAttributes.Final,
};
nullableMember.CustomAttributes.Add(ignoreAttribute);
nullableMember.Comments.AddRange(member.Comments);
var specifiedExpression = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), specifiedName + "Specified");
var valueExpression = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), Name + "Value");
var conditionStatement = new CodeConditionStatement(specifiedExpression,
new CodeStatement[] { new CodeMethodReturnStatement(valueExpression) },
new CodeStatement[] { new CodeMethodReturnStatement(new CodePrimitiveExpression(null)) });
nullableMember.GetStatements.Add(conditionStatement);
var getValueOrDefaultExpression = new CodeMethodInvokeExpression(new CodePropertySetValueReferenceExpression(), "GetValueOrDefault");
var setValueStatement = new CodeAssignStatement(valueExpression, getValueOrDefaultExpression);
var hasValueExpression = new CodePropertyReferenceExpression(new CodePropertySetValueReferenceExpression(), "HasValue");
var setSpecifiedStatement = new CodeAssignStatement(specifiedExpression, hasValueExpression);
var statements = new List<CodeStatement>();
if (withDataBinding)
{
var ifNotEquals = new CodeConditionStatement(
new CodeBinaryOperatorExpression(
new CodeMethodInvokeExpression(valueExpression, "Equals", getValueOrDefaultExpression),
CodeBinaryOperatorType.ValueEquality,
new CodePrimitiveExpression(false)
),
setValueStatement,
setSpecifiedStatement,
new CodeExpressionStatement(new CodeMethodInvokeExpression(null, "OnPropertyChanged",
new CodePrimitiveExpression(Name)))
);
statements.Add(ifNotEquals);
}
else
{
statements.Add(setValueStatement);
statements.Add(setSpecifiedStatement);
}
nullableMember.SetStatements.AddRange(statements.ToArray());
开发者ID:aytacozkan,项目名称:XmlSchemaClassGenerator,代码行数:66,代码来源:TypeModel.cs
注:本文中的System.CodeDom.CodeMethodReturnStatement类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论