本文整理汇总了C#中ICSharpCode.NRefactory.Ast.ObjectCreateExpression类的典型用法代码示例。如果您正苦于以下问题:C# ObjectCreateExpression类的具体用法?C# ObjectCreateExpression怎么用?C# ObjectCreateExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectCreateExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了ObjectCreateExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckPointObjectCreation
void CheckPointObjectCreation(ObjectCreateExpression oce)
{
Assert.AreEqual(0, oce.Parameters.Count);
Assert.AreEqual(2, oce.ObjectInitializer.CreateExpressions.Count);
Assert.IsInstanceOf(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[0], "X"));
Assert.IsInstanceOf(typeof(PrimitiveExpression), CheckPropertyInitializationExpression(oce.ObjectInitializer.CreateExpressions[1], "Y"));
}
示例2: TrackedVisitBlockStatement
public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
{
blockStatement.Children.Clear();
TypeReference notImplmentedException = new TypeReference("System.NotImplementedException");
ObjectCreateExpression objectCreate = new ObjectCreateExpression(notImplmentedException, new List<Expression>());
blockStatement.Children.Add(new ThrowStatement(objectCreate));
return null;
}
示例3: VisitObjectCreateExpression
public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
if(objectCreateExpression.CreateType.GenericTypes.Count>0)
{
UnlockWith(objectCreateExpression);
}
return base.VisitObjectCreateExpression(objectCreateExpression, data);
}
示例4: VisitObjectCreateExpression
public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
var expr = objectCreateExpression.ObjectInitializer;
if (expr.CreateExpressions.Count > 0 && !objectCreateExpression.IsAnonymousType)
UnlockWith(objectCreateExpression.ObjectInitializer); //Handing over the ObjectInitializer will make it highlight that code region only.
return base.VisitObjectCreateExpression(objectCreateExpression, data);
}
示例5: CheckSimpleObjectCreateExpression
void CheckSimpleObjectCreateExpression(ObjectCreateExpression oce)
{
Assert.AreEqual("MyObject", oce.CreateType.Type);
Assert.AreEqual(3, oce.Parameters.Count);
for (int i = 0; i < oce.Parameters.Count; ++i) {
Assert.IsTrue(oce.Parameters[i] is PrimitiveExpression);
}
}
示例6: ContainsInternalConstructor
private bool ContainsInternalConstructor(IList constructors, ObjectCreateExpression objectCreateExpression)
{
foreach (ConstructorDeclaration constructor in constructors)
{
if (constructor.Parameters.Count == objectCreateExpression.Parameters.Count
&& (AstUtil.ContainsModifier(constructor, Modifiers.Internal) || AstUtil.ContainsModifier(constructor, Modifiers.Protected)))
return true;
}
return false;
}
示例7: CreateDebugListExpression
/// <summary>
/// Creates an expression which, when evaluated, creates a List<T> in the debugee
/// filled with contents of IEnumerable<T> from the debugee.
/// </summary>
/// <param name="iEnumerableVariable">Expression for IEnumerable variable in the debugee.</param>
/// <param name="itemType">
/// The generic argument of IEnumerable<T> that <paramref name="iEnumerableVariable"/> implements.</param>
public static Expression CreateDebugListExpression(Expression iEnumerableVariable, DebugType itemType, out DebugType listType)
{
// is using itemType.AppDomain ok?
listType = DebugType.CreateFromType(itemType.AppDomain, typeof(System.Collections.Generic.List<>), itemType);
var iEnumerableType = DebugType.CreateFromType(itemType.AppDomain, typeof(IEnumerable<>), itemType);
// explicitely cast the variable to IEnumerable<T>, where T is itemType
Expression iEnumerableVariableExplicitCast = new CastExpression { Expression = iEnumerableVariable.Clone() , Type = iEnumerableType.GetTypeReference() };
var obj = new ObjectCreateExpression() { Type = listType.GetTypeReference() };
obj.Arguments.Add(iEnumerableVariableExplicitCast);
return obj;
}
示例8: TrackedVisitObjectCreateExpression
public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
TypeDeclaration thisTypeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(objectCreateExpression, typeof(TypeDeclaration));
if (IsTestFixture(thisTypeDeclaration))
{
string fullName = GetFullName(objectCreateExpression.CreateType);
if (CodeBase.Types.Contains(fullName))
{
TypeDeclaration typeDeclaration = (TypeDeclaration) CodeBase.Types[fullName];
IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
if (ContainsInternalConstructor(constructors, objectCreateExpression))
{
Expression replacedExpression;
replacedExpression = CreateReflectionInstance(objectCreateExpression);
ReplaceCurrentNode(replacedExpression);
}
}
}
return base.TrackedVisitObjectCreateExpression(objectCreateExpression, data);
}
示例9: VisitObjectCreateExpression
public virtual object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) {
throw new global::System.NotImplementedException("ObjectCreateExpression");
}
示例10: TrackedVisitObjectCreateExpression
public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
if (data as bool? ?? false) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found object initialization: "+objectCreateExpression.ToString());
#endif
// Resolve the constructor.
// A type derived from the declaration type is also allowed.
MemberResolveResult mrr = this.Resolve(objectCreateExpression) as MemberResolveResult;
#if DEBUG
if (mrr != null) {
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: resolved constructor: "+mrr.ResolvedMember.ToString());
}
#endif
if (mrr != null &&
mrr.ResolvedMember is IMethod &&
(mrr.ResolvedMember.DeclaringType.CompareTo(this.resourceManagerMember.ReturnType.GetUnderlyingClass()) == 0 ||
mrr.ResolvedMember.DeclaringType.IsTypeInInheritanceTree(this.resourceManagerMember.ReturnType.GetUnderlyingClass()))
) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: This is the correct constructor.");
#endif
// This most probably is the resource manager initialization we are looking for.
// Find a parameter that indicates the resources being referenced.
foreach (Expression param in objectCreateExpression.Parameters) {
PrimitiveExpression p = param as PrimitiveExpression;
if (p != null) {
string pValue = p.Value as string;
if (!String.IsNullOrEmpty(pValue)) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found string parameter: '"+pValue+"'");
#endif
this.foundResourceSet = NRefactoryResourceResolver.GetResourceSetReference(this.resourceManagerMember.DeclaringType.CompilationUnit.FileName, pValue);
#if DEBUG
if (this.foundResourceSet.FileName != null) {
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found resource file: "+this.foundResourceSet.FileName);
}
#endif
break;
}
continue;
}
// Support typeof(...)
TypeOfExpression t = param as TypeOfExpression;
if (t != null && this.PositionAvailable) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: Found TypeOfExpression in constructor call: " + t.ToString());
#endif
ResolveResult rr = this.Resolve(new TypeReferenceExpression(t.TypeReference), ExpressionContext.Type);
#if DEBUG
if (rr == null) {
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: The TypeReference of the TypeOfExpression could not be resolved.");
} else {
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver: The TypeReference resolved to: " + rr.ToString());
}
#endif
if (rr != null) {
#if DEBUG
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found typeof(...) parameter, type: '"+rr.ResolvedType.ToString()+"'");
#endif
this.foundResourceSet = NRefactoryResourceResolver.GetResourceSetReference(this.resourceManagerMember.DeclaringType.CompilationUnit.FileName, rr.ResolvedType.FullyQualifiedName);
#if DEBUG
if (this.foundResourceSet.FileName != null) {
LoggingService.Debug("ResourceToolkit: BclNRefactoryResourceResolver found resource file: "+this.foundResourceSet.FileName);
}
#endif
break;
}
}
}
}
}
return base.TrackedVisitObjectCreateExpression(objectCreateExpression, data);
//.........这里部分代码省略.........
示例11: ObjectCreateExpression
void ObjectCreateExpression(
#line 1935 "VBNET.ATG"
out Expression oce) {
#line 1937 "VBNET.ATG"
TypeReference type = null;
Expression initializer = null;
List<Expression> arguments = null;
ArrayList dimensions = null;
oce = null;
bool canBeNormal; bool canBeReDim;
Expect(148);
if (StartOf(7)) {
NonArrayTypeName(
#line 1945 "VBNET.ATG"
out type, false);
if (la.kind == 25) {
lexer.NextToken();
NormalOrReDimArgumentList(
#line 1946 "VBNET.ATG"
out arguments, out canBeNormal, out canBeReDim);
Expect(26);
if (la.kind == 23 ||
#line 1947 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
if (
#line 1947 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
ArrayTypeModifiers(
#line 1948 "VBNET.ATG"
out dimensions);
CollectionInitializer(
#line 1949 "VBNET.ATG"
out initializer);
} else {
CollectionInitializer(
#line 1950 "VBNET.ATG"
out initializer);
}
}
#line 1952 "VBNET.ATG"
if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression();
}
}
#line 1956 "VBNET.ATG"
if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments);
} else {
if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments;
oce = ace;
}
if (la.kind == 218) {
#line 1970 "VBNET.ATG"
NamedArgumentExpression memberInitializer = null;
lexer.NextToken();
#line 1974 "VBNET.ATG"
CollectionInitializerExpression memberInitializers = new CollectionInitializerExpression();
memberInitializers.StartLocation = la.Location;
Expect(23);
MemberInitializer(
#line 1978 "VBNET.ATG"
out memberInitializer);
#line 1979 "VBNET.ATG"
memberInitializers.CreateExpressions.Add(memberInitializer);
while (la.kind == 12) {
lexer.NextToken();
MemberInitializer(
#line 1981 "VBNET.ATG"
out memberInitializer);
#line 1982 "VBNET.ATG"
memberInitializers.CreateExpressions.Add(memberInitializer);
}
Expect(24);
#line 1986 "VBNET.ATG"
memberInitializers.EndLocation = t.Location;
if(oce is ObjectCreateExpression)
{
((ObjectCreateExpression)oce).ObjectInitializer = memberInitializers;
}
}
}
示例12: TrackedVisitObjectCreateExpression
public override object TrackedVisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
string fullName = GetFullName(objectCreateExpression.CreateType);
if (CodeBase.References.Contains("Cons:" + fullName))
{
objectCreateExpression.Parameters.Add(new ThisReferenceExpression());
}
return base.TrackedVisitObjectCreateExpression(objectCreateExpression, data);
}
示例13: NewExpression
void NewExpression(
#line 2065 "cs.ATG"
out Expression pexpr) {
#line 2066 "cs.ATG"
pexpr = null;
List<Expression> parameters = new List<Expression>();
TypeReference type = null;
Expression expr;
Expect(89);
if (StartOf(10)) {
NonArrayType(
#line 2073 "cs.ATG"
out type);
}
if (la.kind == 16 || la.kind == 20) {
if (la.kind == 20) {
#line 2079 "cs.ATG"
ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters);
lexer.NextToken();
#line 2080 "cs.ATG"
if (type == null) Error("Cannot use an anonymous type with arguments for the constructor");
if (StartOf(25)) {
Argument(
#line 2081 "cs.ATG"
out expr);
#line 2081 "cs.ATG"
SafeAdd(oce, parameters, expr);
while (la.kind == 14) {
lexer.NextToken();
Argument(
#line 2082 "cs.ATG"
out expr);
#line 2082 "cs.ATG"
SafeAdd(oce, parameters, expr);
}
}
Expect(21);
#line 2084 "cs.ATG"
pexpr = oce;
if (la.kind == 16) {
CollectionOrObjectInitializer(
#line 2085 "cs.ATG"
out expr);
#line 2085 "cs.ATG"
oce.ObjectInitializer = (CollectionInitializerExpression)expr;
}
} else {
#line 2086 "cs.ATG"
ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters);
CollectionOrObjectInitializer(
#line 2087 "cs.ATG"
out expr);
#line 2087 "cs.ATG"
oce.ObjectInitializer = (CollectionInitializerExpression)expr;
#line 2088 "cs.ATG"
pexpr = oce;
}
} else if (la.kind == 18) {
lexer.NextToken();
#line 2093 "cs.ATG"
ArrayCreateExpression ace = new ArrayCreateExpression(type);
/* we must not change RankSpecifier on the null type reference*/
if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); }
pexpr = ace;
int dims = 0; List<int> ranks = new List<int>();
if (la.kind == 14 || la.kind == 19) {
while (la.kind == 14) {
lexer.NextToken();
#line 2100 "cs.ATG"
dims += 1;
}
Expect(19);
#line 2101 "cs.ATG"
ranks.Add(dims); dims = 0;
while (la.kind == 18) {
lexer.NextToken();
while (la.kind == 14) {
lexer.NextToken();
#line 2102 "cs.ATG"
++dims;
}
Expect(19);
#line 2102 "cs.ATG"
//.........这里部分代码省略.........
示例14: AppendGenericTypes
/// <summary>
/// Appends the types used when creating a generic surrounded by square brackets.
/// </summary>
void AppendGenericTypes(ObjectCreateExpression expression)
{
Append("[");
List<TypeReference> typeRefs = expression.CreateType.GenericTypes;
for (int i = 0; i < typeRefs.Count; ++i) {
if (i != 0) {
Append(", ");
}
TypeReference typeRef = typeRefs[i];
if (typeRef.IsArrayType) {
Append("Array[" + GetTypeName(typeRef) + "]");
} else {
Append(GetTypeName(typeRef));
}
}
Append("]");
}
示例15: ObjectCreateExpression
void ObjectCreateExpression(
#line 1860 "VBNET.ATG"
out Expression oce) {
#line 1862 "VBNET.ATG"
TypeReference type = null;
Expression initializer = null;
List<Expression> arguments = null;
ArrayList dimensions = null;
oce = null;
bool canBeNormal; bool canBeReDim;
Expect(127);
NonArrayTypeName(
#line 1869 "VBNET.ATG"
out type, false);
if (la.kind == 24) {
lexer.NextToken();
NormalOrReDimArgumentList(
#line 1870 "VBNET.ATG"
out arguments, out canBeNormal, out canBeReDim);
Expect(25);
if (la.kind == 22 ||
#line 1871 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
if (
#line 1871 "VBNET.ATG"
la.kind == Tokens.OpenParenthesis) {
ArrayTypeModifiers(
#line 1872 "VBNET.ATG"
out dimensions);
CollectionInitializer(
#line 1873 "VBNET.ATG"
out initializer);
} else {
CollectionInitializer(
#line 1874 "VBNET.ATG"
out initializer);
}
}
#line 1876 "VBNET.ATG"
if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression();
}
#line 1879 "VBNET.ATG"
if (type == null) type = new TypeReference("Object"); // fallback type on parser errors
if (initializer == null) {
oce = new ObjectCreateExpression(type, arguments);
} else {
if (dimensions == null) dimensions = new ArrayList();
dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0));
type.RankSpecifier = (int[])dimensions.ToArray(typeof(int));
ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression);
ace.Arguments = arguments;
oce = ace;
}
}