protected override void VisitMemberAccessSyntax(MemberAccessSyntax pNode) { Visit(pNode.Identifier); //Save current local definitions //Mark the current type we are on so error messages can be more descriptive var l = _locals; using (var t = Store.AddValue("__Type", pNode.Identifier.Type)) { //If field doesn't exist or something went wrong, stop checking things to reduce redundant errors if (CurrentType != SmallTypeCache.Undefined) { //For methods and arrays we need to allow existing variables, but member access should only allow the struct's fields if (NeedToCopyLocals(pNode.Value)) { _locals = _locals.Copy(); } else { _locals = new ScopeCache <LocalDefinition>(); } //Namespaces return a null type if (CurrentType != null) { _locals.AddScope(); foreach (var f in CurrentType.GetFields()) { if (!_locals.IsVariableDefinedInScope(f.Name)) { _locals.DefineVariableInScope(f.Name, LocalDefinition.Create(false, f.Type)); } } } Visit(pNode.Value); } } //Restore local definitions Namespace = null; _locals = l; }
private DumpState( ObjectTextDumper dumper, object instance, Type type, ClassDumpData classDumpData, DumpAttribute instanceDumpAttribute, DumpScript dumpScript, bool isTopLevelClass) { _dumper = dumper ?? throw new ArgumentNullException(nameof(dumper)); _isTopLevelClass = isTopLevelClass; Instance = instance ?? throw new ArgumentNullException(nameof(instance)); InstanceType = instance.GetType(); CurrentType = type ?? throw new ArgumentNullException(nameof(type)); ClassDumpData = classDumpData; InstanceDumpAttribute = instanceDumpAttribute ?? throw new ArgumentNullException(nameof(instanceDumpAttribute)); DumpScript = dumpScript; if (_isTopLevelClass) { var defaultProperty = DefaultProperty; if (!defaultProperty.IsNullOrWhiteSpace()) { var pi = CurrentType.GetProperty(defaultProperty); Enumerator = pi != null ? (new MemberInfo[] { pi }).AsEnumerable().GetEnumerator() : (new MemberInfo[] { }).AsEnumerable().GetEnumerator(); return; } } Enumerator = CurrentType.GetProperties(_dumper.PropertiesBindingFlags | BindingFlags.DeclaredOnly) .Union <MemberInfo>( CurrentType.GetFields(_dumper.FieldsBindingFlags | BindingFlags.DeclaredOnly)) .Where(mi => !mi.Name.StartsWith("<", StringComparison.Ordinal)) .OrderBy(p => p, ServiceResolver .Default .GetInstance <IMemberInfoComparer>() .SetMetadata(ClassDumpData.Metadata)) .GetEnumerator(); }