本文整理汇总了C#中AnonymousTypeCreateExpression类的典型用法代码示例。如果您正苦于以下问题:C# AnonymousTypeCreateExpression类的具体用法?C# AnonymousTypeCreateExpression怎么用?C# AnonymousTypeCreateExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnonymousTypeCreateExpression类属于命名空间,在下文中一共展示了AnonymousTypeCreateExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitAnonymousTypeCreateExpression
public virtual void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(anonymousTypeCreateExpression);
}
}
示例2: BuildExpression
public string BuildExpression(Dictionary<string, Expression> selectExpressions)
{
var anonymousTypeCreateExpression = new AnonymousTypeCreateExpression();
var crrv = new ChangeRootReferenceVisitor(FromIdentifier);
foreach (var curExpr in selectExpressions.OrderBy(x => x.Key))
{
curExpr.Value.AcceptVisitor(crrv);
anonymousTypeCreateExpression.Initializers.Add(
new AssignmentExpression(new IdentifierExpression(curExpr.Key), curExpr.Value.Clone()));
}
if (FromExpression == null)
FromExpression = new IdentifierExpression();
var queryExpr = new QueryExpression
{
Clauses =
{
new QueryFromClause
{
Identifier = "doc",
Expression = FromExpression.Clone()
},
new QuerySelectClause
{
Expression = anonymousTypeCreateExpression.Clone()
}
}
};
FromIdentifier = "doc";
var printer = new StringWriter();
var printerVisitor = new CSharpOutputVisitor(printer, FormattingOptionsFactory.CreateSharpDevelop());
queryExpr.AcceptVisitor(printerVisitor);
return printer.GetStringBuilder().ToString();
}
示例3: VisitAnonymousTypeCreateExpression
public void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
StartNode(anonymousTypeCreateExpression);
WriteKeyword(AnonymousTypeCreateExpression.NewKeywordRole);
PrintInitializerElements(anonymousTypeCreateExpression.Initializers);
EndNode(anonymousTypeCreateExpression);
}
示例4: VisitAnonymousTypeCreateExpression
public virtual void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
VisitChildren (anonymousTypeCreateExpression);
}
示例5: Visit
public override object Visit(NewAnonymousType newAnonymousType)
{
var result = new AnonymousTypeCreateExpression();
var location = LocationsBag.GetLocations(newAnonymousType);
result.AddChild(new CSharpTokenNode(Convert(newAnonymousType.Location), ObjectCreateExpression.NewKeywordRole), ObjectCreateExpression.NewKeywordRole);
if (location != null)
result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LBrace), Roles.LBrace);
if (newAnonymousType.Parameters != null) {
foreach (var par in newAnonymousType.Parameters) {
if (par == null)
continue;
var parLocation = LocationsBag.GetLocations(par);
if (parLocation == null) {
if (par.Expr != null)
result.AddChild((Expression)par.Expr.Accept(this), Roles.Expression);
} else {
var namedExpression = new NamedExpression();
namedExpression.AddChild(Identifier.Create(par.Name, Convert(par.Location)), Roles.Identifier);
namedExpression.AddChild(new CSharpTokenNode(Convert(parLocation [0]), Roles.Assign), Roles.Assign);
if (par.Expr != null)
namedExpression.AddChild((Expression)par.Expr.Accept(this), Roles.Expression);
result.AddChild(namedExpression, Roles.Expression);
}
}
}
if (location != null && location.Count > 1)
result.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RBrace), Roles.RBrace);
return result;
}
示例6: AnonymousTypeCreateBlock
public AnonymousTypeCreateBlock(IEmitter emitter, AnonymousTypeCreateExpression anonymousTypeCreateExpression)
: base(emitter, anonymousTypeCreateExpression)
{
this.Emitter = emitter;
this.AnonymousTypeCreateExpression = anonymousTypeCreateExpression;
}
示例7: ConvertNewObject
Expression ConvertNewObject(InvocationExpression invocation)
{
if (invocation.Arguments.Count < 1 || invocation.Arguments.Count > 3)
return NotSupported(invocation);
Match m = newObjectCtorPattern.Match(invocation.Arguments.First());
if (!m.Success)
return NotSupported(invocation);
MethodReference ctor = m.Get<AstNode>("ctor").Single().Annotation<MethodReference>();
if (ctor == null)
return null;
AstType declaringTypeNode;
TypeReference declaringType;
if (m.Has("declaringType")) {
declaringTypeNode = m.Get<AstType>("declaringType").Single().Clone();
declaringType = declaringTypeNode.Annotation<TypeReference>();
} else {
declaringTypeNode = AstBuilder.ConvertType(ctor.DeclaringType);
declaringType = ctor.DeclaringType;
}
if (declaringTypeNode == null)
return null;
ObjectCreateExpression oce = new ObjectCreateExpression(declaringTypeNode);
if (invocation.Arguments.Count >= 2) {
IList<Expression> arguments = ConvertExpressionsArray(invocation.Arguments.ElementAtOrDefault(1));
if (arguments == null)
return null;
oce.Arguments.AddRange(arguments);
}
if (invocation.Arguments.Count >= 3 && declaringType.IsAnonymousType()) {
MethodDefinition resolvedCtor = ctor.Resolve();
if (resolvedCtor == null || resolvedCtor.Parameters.Count != oce.Arguments.Count)
return null;
AnonymousTypeCreateExpression atce = new AnonymousTypeCreateExpression();
var arguments = oce.Arguments.ToArray();
if (AstMethodBodyBuilder.CanInferAnonymousTypePropertyNamesFromArguments(arguments, resolvedCtor.Parameters)) {
oce.Arguments.MoveTo(atce.Initializers);
} else {
for (int i = 0; i < resolvedCtor.Parameters.Count; i++) {
atce.Initializers.Add(
new NamedExpression {
Name = resolvedCtor.Parameters[i].Name,
Expression = arguments[i].Detach()
});
}
}
return atce;
}
return oce;
}
示例8: Visit
public override object Visit (NewAnonymousType newAnonymousType)
{
var result = new AnonymousTypeCreateExpression ();
if (newAnonymousType.Parameters == null)
return result;
foreach (var par in newAnonymousType.Parameters) {
var location = LocationsBag.GetLocations (par);
if (location == null) {
if (par.Expr != null)
result.AddChild ((Expression)par.Expr.Accept (this), AnonymousTypeCreateExpression.Roles.Expression);
} else {
var namedExpression = new NamedExpression ();
namedExpression.AddChild (Identifier.Create (par.Name, Convert (par.Location)), AnonymousTypeCreateExpression.Roles.Identifier);
namedExpression.AddChild (new CSharpTokenNode (Convert (location[0]), 1), AnonymousTypeCreateExpression.Roles.Assign);
if (par.Expr != null)
namedExpression.AddChild ((Expression)par.Expr.Accept (this), AnonymousTypeCreateExpression.Roles.Expression);
result.AddChild (namedExpression, AnonymousTypeCreateExpression.Roles.Expression);
}
}
return result;
}
示例9: TransformByteCode
//.........这里部分代码省略.........
Arguments = { dir.Expression.Detach() }
};
} else {
return InlineAssembly(byteCode, args);
}
}
case ILCode.Refanytype:
return new UndocumentedExpression {
UndocumentedExpressionType = UndocumentedExpressionType.RefType,
Arguments = { arg1 }
}.Member("TypeHandle");
case ILCode.Refanyval:
return MakeRef(
new UndocumentedExpression {
UndocumentedExpressionType = UndocumentedExpressionType.RefValue,
Arguments = { arg1, new TypeReferenceExpression(operandAsTypeRef) }
});
case ILCode.Newobj: {
Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType;
if (declaringType is ArrayType) {
ComposedType ct = AstBuilder.ConvertType((ArrayType)declaringType) as ComposedType;
if (ct != null && ct.ArraySpecifiers.Count >= 1) {
var ace = new Ast.ArrayCreateExpression();
ct.ArraySpecifiers.First().Remove();
ct.ArraySpecifiers.MoveTo(ace.AdditionalArraySpecifiers);
ace.Type = ct;
ace.Arguments.AddRange(args);
return ace;
}
}
if (declaringType.IsAnonymousType()) {
MethodDefinition ctor = ((MethodReference)operand).Resolve();
if (methodDef != null) {
AnonymousTypeCreateExpression atce = new AnonymousTypeCreateExpression();
if (CanInferAnonymousTypePropertyNamesFromArguments(args, ctor.Parameters)) {
atce.Initializers.AddRange(args);
} else {
for (int i = 0; i < args.Count; i++) {
atce.Initializers.Add(
new NamedExpression {
Name = ctor.Parameters[i].Name,
Expression = args[i]
});
}
}
return atce;
}
}
var oce = new Ast.ObjectCreateExpression();
oce.Type = AstBuilder.ConvertType(declaringType);
oce.Arguments.AddRange(args);
return oce.WithAnnotation(operand);
}
case ILCode.No: return InlineAssembly(byteCode, args);
case ILCode.Nop: return null;
case ILCode.Pop: return arg1;
case ILCode.Readonly: return InlineAssembly(byteCode, args);
case ILCode.Ret:
if (methodDef.ReturnType.FullName != "System.Void") {
return new Ast.ReturnStatement { Expression = arg1 };
} else {
return new Ast.ReturnStatement();
}
case ILCode.Rethrow: return new Ast.ThrowStatement();
case ILCode.Sizeof: return new Ast.SizeOfExpression { Type = operandAsTypeRef };
case ILCode.Stloc: {
示例10: VisitAnonymousTypeCreateExpression
public StringBuilder VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, int data)
{
throw new SLSharpException("SL# does not understand anonymous types");
}
示例11: VisitAnonymousTypeCreateExpression
public override void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
new AnonymousTypeCreateBlock(this, anonymousTypeCreateExpression).Emit();
}
示例12: VisitAnonymousTypeCreateExpression
public virtual void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
DebugExpression(anonymousTypeCreateExpression);
StartNode(anonymousTypeCreateExpression);
WriteKeyword(AnonymousTypeCreateExpression.NewKeywordRole);
PrintInitializerElements(anonymousTypeCreateExpression.Initializers, CodeBracesRangeFlags.OtherBlockBraces);
EndNode(anonymousTypeCreateExpression);
}
示例13: VisitAnonymousTypeCreateExpression
public void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
JsonObject expression = CreateJsonExpression(anonymousTypeCreateExpression);
AddKeyword(expression, AnonymousTypeCreateExpression.NewKeywordRole);
expression.AddJsonValue("elements", GetInitializerElements(anonymousTypeCreateExpression.Initializers));
Push(expression);
}
示例14: VisitAnonymousTypeCreateExpression
public override void VisitAnonymousTypeCreateExpression (AnonymousTypeCreateExpression anonymousTypeCreateExpression)
{
base.VisitAnonymousTypeCreateExpression (anonymousTypeCreateExpression);
foreach (var init in anonymousTypeCreateExpression.Initializers.ToList ()) {
var ident = init as IdentifierExpression;
if (ident != null) {
init.ReplaceWith (new NamedExpression (ident.Identifier, ident.Clone ()));
}
}
}
示例15: VisitAnonymousTypeCreateExpression
public void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression node)
{
NotSupported(node);
}