Пример #1
0
        public FieldInfo Field(IFieldDeclaration fieldDefinition, TypeInfo type)
        {
            if (_fieldCorrespondence.ContainsKey(fieldDefinition))
            {
                return _fieldCorrespondence[fieldDefinition];
            }

            var fieldInfo = new FieldInfo
            {
                Text = fieldDefinition.ToString(),
                Name = fieldDefinition.Name,
                FullName = fieldDefinition.Name,
                IsInternal = fieldDefinition.Visibility == FieldVisibility.Assembly,
                IsPrivate = fieldDefinition.Visibility == FieldVisibility.Private,
                IsPublic = fieldDefinition.Visibility == FieldVisibility.Public,
                IsProtected = fieldDefinition.Visibility == FieldVisibility.Family,
                IsProtectedAndInternal = fieldDefinition.Visibility == FieldVisibility.FamilyAndAssembly,
                IsProtectedOrInternal = fieldDefinition.Visibility == FieldVisibility.FamilyOrAssembly,
                IsStatic = fieldDefinition.Static,
                IsLiteral = fieldDefinition.Literal,
                IsInitOnly = fieldDefinition.ReadOnly,
                IsSpecialName = fieldDefinition.SpecialName,
                MemberReference = fieldDefinition,
                DeclaringType = type
            };
            _fieldCorrespondence.Add(fieldDefinition, fieldInfo);

            fieldInfo.Text = fieldInfo.Text.Substring(fieldInfo.Text.LastIndexOf('.') + 1);
            fieldInfo.Name = fieldInfo.Name.Substring(fieldInfo.Name.LastIndexOf('.') + 1);

            fieldInfo.Icon = Images.Images.GetFieldIcon(fieldInfo);

            return fieldInfo;
        }
        private IEnumerable<FieldInfo> FixDeclaringTypes(FieldInfo[] fields, TypeInfo[] types)
        {
            var fixedFields = new List<FieldInfo>();
            var typeFullNames = types.Select(t => t.FullName).ToArray();
            foreach (var field in fields)
            {
                if (types.Contains(field.DeclaringType))
                {
                    fixedFields.Add(field);
                    continue;
                }
                if (typeFullNames.Contains(field.DeclaringType.FullName))
                {
                    var type = types.Single(t => t.FullName == field.DeclaringType.FullName);
                    var realField = type.Fields.Single(m => m.Name == field.Name);

                    fixedFields.Add(realField);
                }
            }
            return fixedFields;
        }
        private MemberViewModel GetViewModelForField(FieldInfo fieldInfo)
        {
            MemberViewModel vm;
            if (_viewModelsDictionary.ContainsKey(fieldInfo))
            {
                var typeViewModel = GetViewModelForType(fieldInfo.DeclaringType);
                vm = _viewModelsDictionary[fieldInfo];
                vm.Background = typeViewModel.Background;
                vm.Foreground = typeViewModel.Foreground;
                return vm;
            }

            var eventInfo = Helper.GetEventForBackingField(fieldInfo.MemberReference);
            if (eventInfo != null)
            {
                var typeViewModel = GetViewModelForType(eventInfo.DeclaringType);
                if (_viewModelsDictionary.ContainsKey(eventInfo))
                {
                    vm = _viewModelsDictionary[eventInfo];
                    vm.Background = typeViewModel.Background;
                    vm.Foreground = typeViewModel.Foreground;
                    return vm;
                }
                var evm = new EventViewModel(eventInfo)
                {
                    Background = typeViewModel.Background,
                    Foreground = typeViewModel.Foreground,
                    ToolTip = typeViewModel.Name
                };
                _viewModelsDictionary.Add(eventInfo, evm);
                return evm;
            }

            var tvm = GetViewModelForType(fieldInfo.DeclaringType);
            var fvm = new FieldViewModel(fieldInfo)
            {
                Background = tvm.Background,
                Foreground = tvm.Foreground,
                ToolTip = tvm.Name
            };
            _viewModelsDictionary.Add(fieldInfo, fvm);
            return fvm;
        }
 public FieldViewModel(FieldInfo fieldInfo)
     : base(fieldInfo)
 {
     _fieldInfo = fieldInfo;
 }