本文整理汇总了C#中DomReturnType.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# DomReturnType.Clone方法的具体用法?C# DomReturnType.Clone怎么用?C# DomReturnType.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomReturnType
的用法示例。
在下文中一共展示了DomReturnType.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCode
protected override IEnumerable<string> GenerateCode (INRefactoryASTProvider astProvider, string indent, List<IBaseMember> includedMembers)
{
// Genereate Equals
MethodDeclaration methodDeclaration = new MethodDeclaration ();
methodDeclaration.Name = "Equals";
methodDeclaration.ReturnType = DomReturnType.Bool.ConvertToTypeReference ();
methodDeclaration.Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Public | ICSharpCode.NRefactory.CSharp.Modifiers.Override;
methodDeclaration.Body = new BlockStatement ();
methodDeclaration.Parameters.Add (new ParameterDeclaration (DomReturnType.Object.ConvertToTypeReference (), "obj"));
IdentifierExpression paramId = new IdentifierExpression ("obj");
IfElseStatement ifStatement = new IfElseStatement ();
ifStatement.Condition = new BinaryOperatorExpression (paramId, BinaryOperatorType.Equality, new PrimitiveExpression (null));
ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (false));
methodDeclaration.Body.Statements.Add (ifStatement);
ifStatement = new IfElseStatement ();
List<Expression> arguments = new List<Expression> ();
arguments.Add (new ThisReferenceExpression ());
arguments.Add (paramId.Clone ());
ifStatement.Condition = new InvocationExpression (new IdentifierExpression ("ReferenceEquals"), arguments);
ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (true));
methodDeclaration.Body.Statements.Add (ifStatement);
ifStatement = new IfElseStatement ();
ifStatement.Condition = new BinaryOperatorExpression (new InvocationExpression (new MemberReferenceExpression (paramId.Clone (), "GetType")), BinaryOperatorType.InEquality, new TypeOfExpression (new SimpleType (Options.EnclosingType.Name)));
ifStatement.TrueStatement = new ReturnStatement (new PrimitiveExpression (false));
methodDeclaration.Body.Statements.Add (ifStatement);
AstType varType = new DomReturnType (Options.EnclosingType).ConvertToTypeReference ();
var varDecl = new VariableDeclarationStatement (varType, "other", new CastExpression (varType.Clone (), paramId.Clone ()));
methodDeclaration.Body.Statements.Add (varDecl);
IdentifierExpression otherId = new IdentifierExpression ("other");
Expression binOp = null;
foreach (IMember member in includedMembers) {
Expression right = new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.Equality, new MemberReferenceExpression (otherId, member.Name));
if (binOp == null) {
binOp = right;
} else {
binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ConditionalAnd, right);
}
}
methodDeclaration.Body.Statements.Add (new ReturnStatement (binOp));
yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent);
methodDeclaration = new MethodDeclaration ();
methodDeclaration.Name = "GetHashCode";
methodDeclaration.ReturnType = DomReturnType.Int32.ConvertToTypeReference ();
methodDeclaration.Modifiers = ICSharpCode.NRefactory.CSharp.Modifiers.Public | ICSharpCode.NRefactory.CSharp.Modifiers.Override;
methodDeclaration.Body = new BlockStatement ();
binOp = null;
foreach (IMember member in includedMembers) {
Expression right;
right = new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression (member.Name), "GetHashCode"));
IType type = Options.Dom.SearchType (Options.Document.ParsedDocument.CompilationUnit, member is IType ? ((IType)member) : member.DeclaringType, member.Location, member.ReturnType);
if (type != null && type.ClassType != MonoDevelop.Projects.Dom.ClassType.Struct&& type.ClassType != MonoDevelop.Projects.Dom.ClassType.Enum)
right = new ParenthesizedExpression (new ConditionalExpression (new BinaryOperatorExpression (new IdentifierExpression (member.Name), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), right, new PrimitiveExpression (0)));
if (binOp == null) {
binOp = right;
} else {
binOp = new BinaryOperatorExpression (binOp, BinaryOperatorType.ExclusiveOr, right);
}
}
BlockStatement uncheckedBlock = new BlockStatement ();
uncheckedBlock.Statements.Add (new ReturnStatement (binOp));
methodDeclaration.Body.Statements.Add (new UncheckedStatement (uncheckedBlock));
yield return astProvider.OutputNode (this.Options.Dom, methodDeclaration, indent);
}