public void IsId_With_Correct_Name() { //Arrange var member = new FieldMember(null); //Act var result = new AutomappingConfiguration().IsId(member); //Assert Assert.IsTrue(result); }
public void ShouldMap_Member_CanWrite() { //Arrange var member = new FieldMember(null); //Act var result = new AutomappingConfiguration().ShouldMap(member); //Assert Assert.IsTrue(result); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void CompileClosureClass() { m_ClosureClass = new NestedClassType( containingClass: m_OwnerClass, classFullName: m_HostMethod.Name + "<Closure>", baseType: typeof(object), closureDefinition: this); m_ClosureClassConstructor = m_ClosureClass.TypeBuilder.DefineDefaultConstructor( MethodAttributes.Public | MethodAttributes.ReuseSlot | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.HideBySig); var closureWriter = new ImplementationClassWriter <object>(m_ClosureClass); if (m_Parent != null) { m_ParentField = closureWriter.DefineField( name: "Parent", isStatic: false, isPublic: true, fieldType: m_Parent.ClosureClass.TypeBuilder); } foreach (var capture in m_Captures.Where(c => c.HoistingClosure == this)) { capture.DefineHoistedField(closureWriter); } foreach (var anonymousMethodOperand in m_AnonymousMethodsToHoist) { anonymousMethodOperand.CreateAnonymousMethod(m_ClosureClass, closure: this, isStatic: false, isPublic: true); anonymousMethodOperand.AnonymousMethod.AcceptVisitor(new ClosureHoistedMethodRewritingVisitor(anonymousMethodOperand.AnonymousMethod, this)); } m_ClosureClass.Compile(); }
private static IEnumerable <IReflectiveField> EnumerateFields(Type type) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); foreach (var field in fields) { if (!field.IsInitOnly) { var fieldAccessor = new FieldMember(field); yield return(fieldAccessor); } } PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); foreach (var property in properties) { if (property.CanRead && property.GetMethod.IsPublic && property.CanWrite && property.SetMethod.IsPublic) { var propertyAccessor = new PropertyMember(property); yield return(propertyAccessor); } } }
public FieldMember FIELD(TypeMember type, string name, Action body = null) { var context = GetContextOrThrow(); var modifiers = context.PopStateOrThrow <MemberModifierState>(); var declaringTypeRef = context.TryLookupState <MemberRef <TypeMember> >(); var member = new FieldMember( name, declaringTypeRef, MemberStatus.Generator, modifiers.Visibility, modifiers.Modifier, ImmutableList <AttributeDescription> .Empty, type.GetRef(), modifiers.IsReadonly, initializer: null); using (context.PushState(member.GetRef())) { body?.Invoke(); } return(member); }
private IMember CreateMember(IEnumerable <MemberInfo> members, bool write) { IMember previousMember = null; foreach (var current in members) { IMember currentMember; switch (current) { case FieldInfo currentField: currentMember = new FieldMember(previousMember, currentField); break; case PropertyInfo currentProperty: currentMember = new PropertyMember(previousMember, currentProperty); break; case MethodInfo currentMethod: if (write) { currentMember = new MethodMember(previousMember, null, currentMethod); } else { currentMember = new MethodMember(previousMember, currentMethod, null); } break; default: throw new Exception("Unkown member type"); } previousMember = currentMember; } return(previousMember); }
public void RegisterResolver( NameString fieldName, MemberInfo member, Type sourceType, Type resolverType) { if (member == null) { throw new ArgumentNullException(nameof(member)); } if (sourceType == null) { throw new ArgumentNullException(nameof(sourceType)); } fieldName.EnsureNotEmpty(nameof(fieldName)); var fieldMember = new FieldMember(InternalName, fieldName, member); Resolvers[fieldMember.ToFieldReference()] = resolverType == null ? new RegisteredResolver(sourceType, fieldMember) : new RegisteredResolver(resolverType, sourceType, fieldMember); }
public ResolverDescriptor( Type resolverType, Type sourceType, FieldMember field) { ResolverType = resolverType ?? throw new ArgumentNullException(nameof(resolverType)); SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType)); Field = field ?? throw new ArgumentNullException(nameof(field)); if (field.Member is MethodInfo m) { Arguments = FieldResolverDiscoverer .DiscoverArguments(m, sourceType); IsAsync = typeof(Task).IsAssignableFrom(m.ReturnType); IsMethod = true; } else { Arguments = Array.Empty <ArgumentDescriptor>(); } }
public FieldViewModel(FieldMember member, TreeViewItemViewModel parent) : base(member, parent) { }
public virtual void VisitField(FieldMember field) { VisitAbstractMember(field); }
public void CanVisitAppliedAttributes() { //-- arrange var classAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A1") }; var fieldAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A2") }; var constructorAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A3") }; var constructorParamAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A3B") }; var methodAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A4") }; var methodParamAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A4B") }; var methodRetValAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A4C") }; var propertyAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A5") }; var propertyGetterAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A5") }; var propertySetterAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A5") }; var eventAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A6") }; var eventAdderAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A6B") }; var eventRemoverAttribute1 = new AttributeDescription() { AttributeType = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "A6C") }; var class1 = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "Class1"); class1.Attributes.Add(classAttribute1); #region Build class type members var field1 = new FieldMember(class1, MemberVisibility.Private, MemberModifier.None, typeof(int), "_field1"); field1.Attributes.Add(fieldAttribute1); var constructor1 = new ConstructorMember(MemberVisibility.Public, MemberModifier.None, "Class1", new MethodSignature( new[] { new MethodParameter("n", 1, typeof(int), MethodParameterModifier.None, constructorParamAttribute1) }, returnValue: null, isAsync: false )); constructor1.Attributes.Add(constructorAttribute1); var method1 = new MethodMember(MemberVisibility.Public, MemberModifier.None, "M1", new MethodSignature( new[] { new MethodParameter("n", 1, typeof(int), MethodParameterModifier.None, methodParamAttribute1) }, returnValue: new MethodParameter(null, -1, typeof(string), MethodParameterModifier.None, methodRetValAttribute1), isAsync: false )); method1.Attributes.Add(methodAttribute1); var property1 = new PropertyMember(class1, MemberVisibility.Public, MemberModifier.None, typeof(int), "P1"); property1.Getter = new MethodMember(property1.Visibility, "get_" + property1.Name); property1.Setter = new MethodMember(property1.Visibility, "set_" + property1.Name); property1.Attributes.Add(propertyAttribute1); property1.Getter.Attributes.Add(propertyGetterAttribute1); property1.Setter.Attributes.Add(propertySetterAttribute1); var event1 = new EventMember(MemberVisibility.Public, MemberModifier.None, typeof(Action), "E1"); event1.Adder = new MethodMember(event1.Visibility, "add_" + event1.Name); event1.Remover = new MethodMember(event1.Visibility, "remove_" + event1.Name); event1.Attributes.Add(eventAttribute1); event1.Adder.Attributes.Add(eventAdderAttribute1); event1.Remover.Attributes.Add(eventRemoverAttribute1); #endregion class1.Members.AddRange(new AbstractMember[] { field1, constructor1, method1, property1, event1 }); var visitLog = new List <Visit>(); var visitor = new TestMemberVisitor(visitLog); //-- act class1.AcceptVisitor(visitor); //-- assert visitLog.Should().ContainInOrder( new Visit(nameof(MemberVisitor.VisitAttribute), classAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), fieldAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), constructorAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), constructorParamAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), methodAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), methodParamAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), methodRetValAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), propertyAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), propertyGetterAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), propertySetterAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), eventAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), eventAdderAttribute1), new Visit(nameof(MemberVisitor.VisitAttribute), eventRemoverAttribute1) ); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- internal FieldDecorationBuilder(FieldMember ownerField) { m_OwnerField = ownerField; }
public IPropertyBag <TContainer> CreatePropertyBag <TContainer>() { if (!RuntimeTypeInfoCache <TContainer> .IsContainerType || RuntimeTypeInfoCache <TContainer> .IsObjectType) { throw new InvalidOperationException("Invalid container type."); } if (typeof(TContainer).IsArray) { return((IPropertyBag <TContainer>)m_CreateListPropertyBagMethod.MakeGenericMethod(typeof(TContainer), typeof(TContainer).GetElementType()).Invoke(this, new object[0])); } if (typeof(TContainer).IsGenericType && (typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(List <>)) || typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(IList <>)))) { return((IPropertyBag <TContainer>)m_CreateListPropertyBagMethod.MakeGenericMethod(typeof(TContainer), typeof(TContainer).GetGenericArguments().First()).Invoke(this, new object[0])); } if (typeof(TContainer).IsGenericType && (typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(HashSet <>)) || typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(ISet <>)))) { return((IPropertyBag <TContainer>)m_CreateSetPropertyBagMethod.MakeGenericMethod(typeof(TContainer), typeof(TContainer).GetGenericArguments().First()).Invoke(this, new object[0])); } if (typeof(TContainer).IsGenericType && (typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(Dictionary <,>)) || typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(IDictionary <,>)))) { var types = typeof(TContainer).GetGenericArguments().ToArray(); return((IPropertyBag <TContainer>)m_CreateDictionaryPropertyBagMethod.MakeGenericMethod(typeof(TContainer), types[0], types[1]).Invoke(this, new object[0])); } if (typeof(TContainer).IsGenericType && typeof(TContainer).GetGenericTypeDefinition().IsAssignableFrom(typeof(KeyValuePair <,>))) { var types = typeof(TContainer).GetGenericArguments().ToArray(); return((IPropertyBag <TContainer>)m_CreateKeyValuePairPropertyBagMethod.MakeGenericMethod(types[0], types[1]).Invoke(this, new object[0])); } var propertyBag = new ReflectedPropertyBag <TContainer>(); foreach (var member in GetPropertyMembers(typeof(TContainer))) { IMemberInfo info; switch (member) { case FieldInfo field: info = new FieldMember(field); break; case PropertyInfo property: info = new PropertyMember(property); break; default: throw new InvalidOperationException(); } m_CreatePropertyMethod.MakeGenericMethod(typeof(TContainer), info.ValueType).Invoke(this, new object[] { info, propertyBag }); } return(propertyBag); }
public FieldTypeDependency(FieldMember field) { _originMember = field; }
public ResolverDescriptor( Type sourceType, FieldMember field) : this(field?.Member.ReflectedType, sourceType, field) { }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected virtual void OnField(FieldMember member, Func <FieldDecorationBuilder> decorate) { }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void ImplementSingletonMethod( TypeMember productType, TypeMember activationContract, MethodSignature constructorSignature, TypeMember artifactType) { var syncRootField = new FieldMember(artifactType, MemberVisibility.Private, MemberModifier.None, typeof(object), "_singletonInstanceSyncRoot") { IsReadOnly = true, Initializer = new NewObjectExpression { Type = typeof(object) } }; var singletonField = new FieldMember(artifactType, MemberVisibility.Private, MemberModifier.None, activationContract, "_singletonInstance"); var singletonMethod = new MethodMember( MemberVisibility.Public, MemberModifier.None, nameof(IConstructor <object> .GetOrCreateSingleton), new MethodSignature { ReturnValue = new MethodParameter { Type = activationContract } }); NewObjectExpression newObjectExpression; singletonMethod.Signature.Parameters.AddRange(constructorSignature.Parameters); singletonMethod.Body = new BlockStatement( new IfStatement { Condition = new BinaryExpression { Left = new MemberExpression { Target = new ThisExpression(), Member = singletonField }, Operator = BinaryOperator.Equal, Right = new ConstantExpression { Value = null } }, ThenBlock = new BlockStatement( new LockStatement { SyncRoot = new MemberExpression { Target = new ThisExpression(), Member = syncRootField }, Body = new BlockStatement( new IfStatement { Condition = new BinaryExpression { Left = new MemberExpression { Target = new ThisExpression(), Member = singletonField }, Operator = BinaryOperator.Equal, Right = new ConstantExpression { Value = null } }, ThenBlock = new BlockStatement( new ExpressionStatement { Expression = new AssignmentExpression { Left = new MemberExpression { Target = new ThisExpression(), Member = singletonField }, Right = newObjectExpression = new NewObjectExpression { Type = productType, ConstructorCall = new MethodCallExpression() } } } ) } ) } ) }, new ReturnStatement { Expression = new MemberExpression { Target = new ThisExpression(), Member = singletonField } } ); newObjectExpression.ConstructorCall.Arguments.AddRange( constructorSignature.Parameters.Select(p => new Argument { Expression = new ParameterExpression { Parameter = p } })); artifactType.Members.Add(singletonField); artifactType.Members.Add(syncRootField); artifactType.Members.Add(singletonMethod); }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override void OnField(FieldMember member, Func <FieldDecorationBuilder> decorate) { decorate().Attribute <AttributeTests.TestAttributeOne>(a => a.Named(x => x.StringValue, member.Name.TrimPrefix("m_"))); }
public SourceResolverDescriptor( FieldMember field, ArgumentDescriptor argument) : this(field?.Member.ReflectedType, field, new[] { argument }) { }
public SourceResolverDescriptor(FieldMember field) : this(field?.Member.ReflectedType, field) { }
public void SetUp(List <string> args) { if (verbose) { Console.WriteLine("import path:"); foreach (string directory in pathResolver.Directories) { Console.WriteLine(" " + directory); } } AppDomain domain = Thread.GetDomain(); rootModule = new Module(null, null); foreach (Assembly assembly in domain.GetAssemblies()) { AssemblyLoaded(assembly); } domain.AssemblyLoad += OnDomainAssemblyLoad; rootModule.SetName("null", null); rootModule.SetName("true", true); rootModule.SetName("false", false); rootModule.SetName("args", args); DefaultWhitespace.SetUp(rootModule, grammar); LineComment.SetUp(rootModule, grammar); BlockComment.SetUp(rootModule, grammar); Whitespace.SetUp(rootModule, grammar); Name.SetUp(rootModule, grammar); Name.SetUp(rootModule, grammar); Number.SetUp(rootModule, grammar); Base.String.SetUp(rootModule, grammar); Expression.SetUp(rootModule, grammar); ValueExpression.SetUp(rootModule, grammar); NameExpression.SetUp(rootModule, grammar); ParenExpression.SetUp(rootModule, grammar); MemberExpression.SetUp(rootModule, grammar); CallExpression.SetUp(rootModule, grammar); CallInParentScopeExpression.SetUp(rootModule, grammar); NewExpression.SetUp(rootModule, grammar); TypeExpression.SetUp(rootModule, grammar); IsExpression.SetUp(rootModule, grammar); AsExpression.SetUp(rootModule, grammar); UnaryExpression.SetUp(rootModule, grammar); NotExpression.SetUp(rootModule, grammar); MultiplicativeExpression.SetUp(rootModule, grammar); MultiplyExpression.SetUp(rootModule, grammar); DivideExpression.SetUp(rootModule, grammar); AdditiveExpression.SetUp(rootModule, grammar); AddExpression.SetUp(rootModule, grammar); SubtractExpression.SetUp(rootModule, grammar); ComparisonExpression.SetUp(rootModule, grammar); LessExpression.SetUp(rootModule, grammar); LessOrEqualExpression.SetUp(rootModule, grammar); EqualityExpression.SetUp(rootModule, grammar); InequalityExpression.SetUp(rootModule, grammar); GreaterExpression.SetUp(rootModule, grammar); GreaterOrEqualExpression.SetUp(rootModule, grammar); JunctionExpression.SetUp(rootModule, grammar); AndExpression.SetUp(rootModule, grammar); AssignmentExpression.SetUp(rootModule, grammar); AssignExpression.SetUp(rootModule, grammar); /* * NameExpression = ValueExpression * ParenExpression = ValueExpression * * CallExpression < ValueExpression * CallInParentScopeExpression = CallExpression * MemberExpression = CallExpression * * NewExpression < CallExpression * TypeExpression < NewExpression * UnaryExpression < TypeExpression * MultiplicativeExpression < UnaryExpression * AdditiveExpression < MultiplicativeExpression * ComparisonExpression < AdditiveExpression * JunctionExpression < ComparisonExpression * AssignmentExpression < JunctionExpression */ Precedence.SetPrecedence(NameExpression.pattern.Precedence, ValueExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(ParenExpression.pattern.Precedence, ValueExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(CallExpression.pattern.Precedence, ValueExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(CallInParentScopeExpression.pattern.Precedence, CallExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(MemberExpression.pattern.Precedence, CallExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(NewExpression.pattern.Precedence, CallExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(TypeExpression.pattern.Precedence, NewExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(UnaryExpression.pattern.Precedence, TypeExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(MultiplicativeExpression.pattern.Precedence, UnaryExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AdditiveExpression.pattern.Precedence, MultiplicativeExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(ComparisonExpression.pattern.Precedence, AdditiveExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(JunctionExpression.pattern.Precedence, ComparisonExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AssignmentExpression.pattern.Precedence, JunctionExpression.pattern.Precedence, Relation.Lower); Grammar.PatternChanged(ValueExpression.pattern, NameExpression.pattern, ParenExpression.pattern, MemberExpression.pattern, CallExpression.pattern, NewExpression.pattern, TypeExpression.pattern, UnaryExpression.pattern, MultiplicativeExpression.pattern, AdditiveExpression.pattern, ComparisonExpression.pattern, JunctionExpression.pattern, AssignmentExpression.pattern); PatternExpression.SetUp(rootModule, grammar); ReferencePatternExpression.SetUp(rootModule, grammar); AnyPatternExpression.SetUp(rootModule, grammar); TextPatternExpression.SetUp(rootModule, grammar); Option.SetUp(rootModule, grammar); BlockPatternExpression.SetUp(rootModule, grammar); ParenPatternExpression.SetUp(rootModule, grammar); TokenPatternExpression.SetUp(rootModule, grammar); RangePatternExpression.SetUp(rootModule, grammar); RepeatPatternExpression.SetUp(rootModule, grammar); AndPatternExpression.SetUp(rootModule, grammar); NotPatternExpression.SetUp(rootModule, grammar); LabelPatternExpression.SetUp(rootModule, grammar); SequencePatternExpression.SetUp(rootModule, grammar); AltPatternExpression.SetUp(rootModule, grammar); /* * EndPatternExpression = ReferencePatternExpression * AnyPatternExpression = ReferencePatternExpression * TextPatternExpression = ReferencePatternExpression * BlockPatternExpression = ReferencePatternExpression * ParenPatternExpression = ReferencePatternExpression * TokenPatternExpression = ReferencePatternExpression * * RangePatternExpression < ReferencePatternExpression * * AndPatternExpression < RangePatternExpression * NotPatternExpression = AndPatternExpression * RepeatPatternExpression = AndPatternExpression * * LabelPatternExpression < AndPatternExpression * SequencePatternExpression < LabelPatternExpression * AltPatternExpression < SequencePatternExpression */ Precedence.SetPrecedence(AnyPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(TextPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(BlockPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(ParenPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(TokenPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(RangePatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AndPatternExpression.pattern.Precedence, RangePatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(NotPatternExpression.pattern.Precedence, AndPatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(RepeatPatternExpression.pattern.Precedence, AndPatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(LabelPatternExpression.pattern.Precedence, AndPatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(SequencePatternExpression.pattern.Precedence, LabelPatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AltPatternExpression.pattern.Precedence, SequencePatternExpression.pattern.Precedence, Relation.Lower); Grammar.PatternChanged(ReferencePatternExpression.pattern, AnyPatternExpression.pattern, TextPatternExpression.pattern, BlockPatternExpression.pattern, ParenPatternExpression.pattern, TokenPatternExpression.pattern, RangePatternExpression.pattern, RepeatPatternExpression.pattern, AndPatternExpression.pattern, NotPatternExpression.pattern, LabelPatternExpression.pattern, SequencePatternExpression.pattern, AltPatternExpression.pattern); Statement.SetUp(rootModule, grammar); ExpressionStatement.SetUp(rootModule, grammar); CompoundStatement.SetUp(rootModule, grammar); PrintStatement.SetUp(rootModule, grammar); IfStatement.SetUp(rootModule, grammar); WhileStatement.SetUp(rootModule, grammar); ReturnStatement.SetUp(rootModule, grammar); ThrowStatement.SetUp(rootModule, grammar); TryStatement.SetUp(rootModule, grammar); ModuleStatement.SetUp(rootModule, grammar); FunctionStatement.SetUp(rootModule, grammar); Member.SetUp(rootModule, grammar); PatternMember.SetUp(rootModule, grammar); FieldMember.SetUp(rootModule, grammar); ConstructorMember.SetUp(rootModule, grammar); MethodMember.SetUp(rootModule, grammar); ClassStatement.SetUp(rootModule, grammar); SetPrecedenceStatement.SetUp(rootModule, grammar); UsingStatement.SetUp(rootModule, grammar); ImportStatement.SetUp(rootModule, grammar); TopLevelStatement.SetUp(rootModule, grammar); Program.SetUp(rootModule, grammar); Grammar.PatternChanged(Member.pattern, Statement.pattern); grammar.RootPattern = Program.pattern; hasBeenSetUp = true; }
public void CanVisitTypeMembers() { //-- arrange var class1 = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "Class1"); var field1 = new FieldMember(class1, MemberVisibility.Private, MemberModifier.None, typeof(int), "_field1"); var field2 = new FieldMember(class1, MemberVisibility.Private, MemberModifier.None, typeof(int), "_field2"); var constructor1 = new ConstructorMember(MemberVisibility.Public, MemberModifier.None, "Class1", new MethodSignature()); var constructor2 = new ConstructorMember(MemberVisibility.Public, MemberModifier.Static, "Class1", new MethodSignature()); var method1 = new MethodMember(MemberVisibility.Public, MemberModifier.None, "M1", new MethodSignature()); var method2 = new MethodMember(MemberVisibility.Public, MemberModifier.None, "M2", new MethodSignature()); var property1 = new PropertyMember(class1, MemberVisibility.Public, MemberModifier.None, typeof(int), "P1"); var property2 = new PropertyMember(class1, MemberVisibility.Public, MemberModifier.None, typeof(int), "P2"); var event1 = new EventMember(MemberVisibility.Public, MemberModifier.None, typeof(Action), "E1"); var event2 = new EventMember(MemberVisibility.Public, MemberModifier.None, typeof(Action), "E2"); class1.Members.AddRange(new AbstractMember[] { field1, field2, constructor1, constructor2, method1, method2, property1, property2, event1, event2 }); property2.Getter = new MethodMember(property2.Visibility, "get_" + property2.Name); property2.Setter = new MethodMember(property2.Visibility, "set_" + property2.Name); event2.Adder = new MethodMember(property2.Visibility, "add_" + event2.Name); event2.Remover = new MethodMember(property2.Visibility, "remove_" + event2.Name); var visitLog = new List <Visit>(); var visitor = new TestMemberVisitor(visitLog); //-- act class1.AcceptVisitor(visitor); //-- assert visitLog.Should().Equal( new Visit(nameof(MemberVisitor.VisitAbstractMember), class1), new Visit(nameof(MemberVisitor.VisitTypeMember), class1), new Visit(nameof(MemberVisitor.VisitClassType), class1), new Visit(nameof(MemberVisitor.VisitAbstractMember), field1), new Visit(nameof(MemberVisitor.VisitField), field1), new Visit(nameof(MemberVisitor.VisitAbstractMember), field2), new Visit(nameof(MemberVisitor.VisitField), field2), new Visit(nameof(MemberVisitor.VisitAbstractMember), constructor1), new Visit(nameof(MemberVisitor.VisitMethodBase), constructor1), new Visit(nameof(MemberVisitor.VisitConstructor), constructor1), new Visit(nameof(MemberVisitor.VisitAbstractMember), constructor2), new Visit(nameof(MemberVisitor.VisitMethodBase), constructor2), new Visit(nameof(MemberVisitor.VisitConstructor), constructor2), new Visit(nameof(MemberVisitor.VisitAbstractMember), method1), new Visit(nameof(MemberVisitor.VisitMethodBase), method1), new Visit(nameof(MemberVisitor.VisitMethod), method1), new Visit(nameof(MemberVisitor.VisitAbstractMember), method2), new Visit(nameof(MemberVisitor.VisitMethodBase), method2), new Visit(nameof(MemberVisitor.VisitMethod), method2), new Visit(nameof(MemberVisitor.VisitAbstractMember), property1), new Visit(nameof(MemberVisitor.VisitProperty), property1), new Visit(nameof(MemberVisitor.VisitAbstractMember), property2), new Visit(nameof(MemberVisitor.VisitProperty), property2), new Visit(nameof(MemberVisitor.VisitAbstractMember), property2.Getter), new Visit(nameof(MemberVisitor.VisitMethodBase), property2.Getter), new Visit(nameof(MemberVisitor.VisitMethod), property2.Getter), new Visit(nameof(MemberVisitor.VisitAbstractMember), property2.Setter), new Visit(nameof(MemberVisitor.VisitMethodBase), property2.Setter), new Visit(nameof(MemberVisitor.VisitMethod), property2.Setter), new Visit(nameof(MemberVisitor.VisitAbstractMember), event1), new Visit(nameof(MemberVisitor.VisitEvent), event1), new Visit(nameof(MemberVisitor.VisitAbstractMember), event2), new Visit(nameof(MemberVisitor.VisitEvent), event2), new Visit(nameof(MemberVisitor.VisitAbstractMember), event2.Adder), new Visit(nameof(MemberVisitor.VisitMethodBase), event2.Adder), new Visit(nameof(MemberVisitor.VisitMethod), event2.Adder), new Visit(nameof(MemberVisitor.VisitAbstractMember), event2.Remover), new Visit(nameof(MemberVisitor.VisitMethodBase), event2.Remover), new Visit(nameof(MemberVisitor.VisitMethod), event2.Remover) ); }
public static void AUTOMATIC(FieldMember field) { }
public FieldReader(CodeModelBuilder modelBuilder, IFieldSymbol symbol) { _modelBuilder = modelBuilder; _symbol = symbol; _member = null; }
public FieldTypeDependency(FieldMember field) : base(field, field) { }
public override void VisitField(FieldMember field) { base.VisitField(field); AddReferencedType(field.Type); }
public void FIELD(IdentifierName name, out FieldMember @ref, Action body = null) => @ref = new FieldGenerator(GetContextOrThrow(), fieldType: (TypeMember)null, name, body).GenerateMember();
// ReSharper disable once SuggestBaseTypeForParameter public AccessFieldDependency(IMember originMember, FieldMember accessedField) { OriginMember = originMember; TargetMember = accessedField; }
public void FIELD <TType>(IdentifierName name, out FieldMember @ref, Action body = null) => @ref = new FieldGenerator(GetContextOrThrow(), typeof(TType), name, body).GenerateMember();
//----------------------------------------------------------------------------------------------------------------------------------------------------- public FieldWriter(FieldMember ownerField) { m_OwnerField = ownerField; ownerField.AddWriter(this); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public override void VisitField(FieldMember field) { base.VisitField(field); _visitLog.Add(new Visit(nameof(VisitField), field)); }