Пример #1
0
 internal BfMember(BfCache cache, MemberReference memberRef, BfType type)
 {
     Name     = memberRef.Name;
     FullName = $"{type.FullName}.{Name}";
     _cache   = cache;
     _type    = type;
 }
Пример #2
0
        private void Append(BfType bfType)
        {
            if (bfType == null)
            {
                return;
            }

            if (Assembly.IsCoreAssembly)
            {
                TypesUsed.Add(bfType);
            }

            bfType.TypesUsing.Add(this);
        }
Пример #3
0
        private BfType CreateBfType(TypeDefinition typeDefinition, BfAssembly bfAssembly)
        {
            var    key = GetKey(typeDefinition);
            BfType createBfType;

            if (!bfAssembly.GetTypesDictionary().ContainsKey(key))
            {
                createBfType = new BfType(this, typeDefinition, bfAssembly);
                bfAssembly.GetTypesDictionary().Add(GetKey(typeDefinition), createBfType);
                Types.Add(createBfType);
                bfAssembly.Namespaces.Add(createBfType.Namespace);
            }
            else
            {
                createBfType = bfAssembly.GetTypesDictionary()[key];
            }

            return(createBfType);
        }
Пример #4
0
        internal BfEvent(BfCache cache, EventDefinition eventDef, BfType type)
            : base(cache, eventDef, type)
        {
            _eventDefinition = eventDef;

            EventType = _cache.GetBfType(_eventDefinition.EventType);

            _typesUsed.Add(EventType);
            _typesUsed.AddRange(_cache.GetTypeCollection(_eventDefinition.EventType));
            _typesUsed.Clear();

            IsInternal  = _eventDefinition.AddMethod.IsAssembly;
            IsProtected = _eventDefinition.AddMethod.IsFamily;
            IsPrivate   = _eventDefinition.AddMethod.IsPrivate;
            IsPublic    = _eventDefinition.AddMethod.IsPublic;
            IsStatic    = _eventDefinition.AddMethod.IsStatic;

            _cache.Events.Add(this);
        }
Пример #5
0
        internal BfNamespace GetNamespace(BfType bfType)
        {
            BfNamespace bfNamespace = null;

            var name = ProcessNamespace(bfType.GetTypeDefinition().FullName);

            if (!_sortedDictionary.ContainsKey(name))
            {
                bfNamespace = new BfNamespace(name);
                _sortedDictionary.Add(name, bfNamespace);
                Namespaces.Add(bfNamespace);
            }
            else
            {
                bfNamespace = _sortedDictionary[name];
            }

            bfNamespace.Types.Add(bfType);

            return(bfNamespace);
        }
Пример #6
0
        internal BfField(BfCache cache, FieldDefinition fieldDef, BfType type)
            : base(cache, fieldDef, type)
        {
            _fieldDefinition       = fieldDef;
            IsInternal             = _fieldDefinition.IsAssembly;
            IsProtected            = _fieldDefinition.IsFamily;
            IsProtectedAndInternal = _fieldDefinition.IsFamilyAndAssembly;
            IsProtectedOrInternal  = _fieldDefinition.IsFamilyOrAssembly;
            IsPrivate  = _fieldDefinition.IsPrivate;
            IsPublic   = _fieldDefinition.IsPublic;
            IsStatic   = _fieldDefinition.IsStatic;
            IsConstant = _fieldDefinition.HasConstant;

            FieldType = _cache.GetBfType(_fieldDefinition.FieldType);

            _typesUsed.Add(FieldType);
            _typesUsed.AddRange(_cache.GetTypeCollection(_fieldDefinition.FieldType));
            _typesUsed.Clear();

            UniqueName = BfCache.GetKey(_fieldDefinition.DeclaringType);
        }
Пример #7
0
        internal BfMethod(BfCache cache, MethodDefinition methodDef, BfType type)
            : base(cache, methodDef, type)
        {
            _methodDefinition = methodDef;
            _methodName       = GetSignature(_methodDefinition);

            if (!type.IsInCoreAssembly)
            {
                return;
            }

            ReturnType = cache.GetBfType(methodDef.ReturnType);

            _typesUsed.AddRange(_cache.GetTypeCollection(methodDef.ReturnType));
            _typesUsed.Add(ReturnType);
            _typesUsed.AddRange(_cache.GetTypeCollection(_methodDefinition));

            if (methodDef.Body != null)
            {
                foreach (var variableDefinition in methodDef.Body.Variables)
                {
                    _typesUsed.AddRange(_cache.GetTypeCollection(variableDefinition.VariableType));
                    _typesUsed.Add(_cache.GetBfType(variableDefinition.VariableType));
                }
            }

            foreach (var parameterDefinition in methodDef.Parameters)
            {
                _typesUsed.AddRange(_cache.GetTypeCollection(parameterDefinition.ParameterType));
                _typesUsed.Add(_cache.GetBfType(parameterDefinition.ParameterType));

                ParameterTypes.AddRange(_cache.GetTypeCollection(parameterDefinition.ParameterType));
                ParameterTypes.Add(_cache.GetBfType(parameterDefinition.ParameterType));
            }

            ParameterTypes.Clear();
        }
Пример #8
0
        internal BfType GetBfType(TypeReference typeReference)
        {
            BfType bfType = null;

            if (typeReference == null)
            {
                bfType = null;
            }
            else
            {
                typeReference = GetTypeReference(typeReference);

                if (typeReference is GenericParameter)
                {
                    var bfAssembly = _dictionary.Values.Where(assembly =>
                    {
                        if (assembly.Name == "mscorlib")
                        {
                            return(string.Compare(assembly.Version, "2.0.0.0", StringComparison.Ordinal) > -1);
                        }
                        return(false);
                    }).FirstOrDefault() ?? _dictionary.Values.FirstOrDefault(assembly => assembly.IsCoreAssembly);

                    // ReSharper disable once PossibleNullReferenceException
                    bfType = !bfAssembly.GetTypesDictionary().ContainsKey(typeReference.FullName)
                        ? CreateBfType(new TypeDefinition(typeReference.Name, typeReference.Namespace, TypeAttributes.Abstract, null), bfAssembly)
                        : bfAssembly.GetTypesDictionary()[typeReference.FullName];
                }
                else
                {
                    try
                    {
                        BfAssembly bfAssembly = null;

                        var scope = typeReference.Scope as AssemblyNameReference;

                        if (scope != null && _dictionary.ContainsKey(scope.FullName))
                        {
                            bfAssembly = _dictionary[scope.FullName];
                        }
                        else if (typeReference.Scope is ModuleDefinition && _dictionary.ContainsKey(((ModuleDefinition)typeReference.Scope).Assembly.Name.FullName))
                        {
                            bfAssembly = _dictionary[((ModuleDefinition)typeReference.Scope).Assembly.Name.FullName];
                        }
                        else if (typeReference.Scope is ModuleReference && _dictionary.ContainsKey(((ModuleReference)typeReference.Scope).Name))
                        {
                            bfAssembly = _assembliesDictionary[((ModuleReference)typeReference.Scope).Name];
                        }

                        BfType type = null;

                        if (bfAssembly != null)
                        {
                            bfAssembly.GetTypesDictionary().TryGetValue(GetKey(typeReference), out type);

                            if (type == null)
                            {
                                var typeDefinition = bfAssembly.GetAssemblyDefinition().Modules.SelectMany(m => m.Types).FirstOrDefault(p => typeReference.FullName == p.FullName);

                                if (typeDefinition != null)
                                {
                                    type = CreateBfType(typeDefinition, bfAssembly);
                                }
                            }
                        }

                        if (type != null)
                        {
                            bfType = type;
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                    }
                }
            }

            return(bfType);
        }
Пример #9
0
 private static void Delegates(BfType bfType)
 {
     bfType.IsDelegate = true;
     bfType.DerivedTypes.ForEach(Delegates);
 }