Esempio n. 1
0
        ref TypeBatch CreateNewTypeBatch(int typeId, TypeProcessor typeProcessor, int initialCapacity, BufferPool pool)
        {
            var newIndex = TypeBatches.Count;

            TypeBatches.EnsureCapacity(TypeBatches.Count + 1, pool.SpecializeFor <TypeBatch>());
            TypeIndexToTypeBatchIndex[typeId] = newIndex;
            ref var typeBatch = ref TypeBatches.AllocateUnsafely();
Esempio n. 2
0
        private void CreateInstance(Type type, Type[] genericTypes, string genericTypeName, Type[] argsType, params object[] args)
        {
            object        instance;
            string        compareResult = "";
            TypeProcessor processor     = new TypeProcessor(type, genericTypes, argsType);

            if (args != null)
            {
                foreach (var item in args)
                {
                    compareResult += item.ToString();
                }
            }

            instance = processor.CreateInstance(args);
            if (instance == null || instance.GetType().Name != type.Name)
            {
                Assert.Fail();
            }
            else
            {
                string reslut = (string)processor.GetProperty(instance, "T") +
                                (((int)processor.GetProperty(instance, "U")).ToString() == "0" ? "" : ((int)processor.GetProperty(instance, "U")).ToString());
                if (reslut != compareResult ||
                    (string)processor.GetProperty(instance, "GenericTypeName") != genericTypeName)
                {
                    Assert.Fail();
                }
            }
        }
Esempio n. 3
0
        public void FieldValueTest()
        {
            Type          o;
            object        fromObj;
            TypeProcessor processor = new TypeProcessor(typeof(TestType));

            fromObj = processor.CreateInstance();
            processor.SetField(fromObj, "A", new TestType());
            processor.SetField(fromObj, "B", new TestType());
            processor.SetField(fromObj, "C", new TestType());
            processor.SetField(fromObj, "D", new TestType());
            processor.SetField(fromObj, "E", new TestType());
            processor.SetField(fromObj, "F", new TestType());
            processor.SetField(fromObj, "G", new TestType());
            processor.SetField(fromObj, "H", new TestType());
            processor.SetField(fromObj, "I", "I");
            processor.SetField(fromObj, "J", 99);
            processor.SetField(fromObj, "K", true);


            for (int i = 0; i < 10; i++)
            {
                var ToObj = processor.CreateInstance();
                foreach (FieldInfo item in fromObj.GetType().GetFields())
                {
                    processor.SetField(ToObj, item.Name, processor.GetField(fromObj, item.Name));
                    if (!processor.GetField(fromObj, item.Name).Equals(processor.GetField(ToObj, item.Name)))
                    {
                        Assert.Fail();
                    }
                }
            }
        }
Esempio n. 4
0
        public void OnEnable()
        {
            didEnable = true;
            LightList <ProcessedType> typeData = TypeProcessor.GetTemplateTypes();

            List <Type> validTypes = new List <Type>();

            for (int i = 0; i < typeData.size; i++)
            {
                if (typeData[i].rawType.Assembly.FullName.StartsWith("UIForia"))
                {
                    continue;
                }

                validTypes.Add(typeData[i].rawType);
            }

            types = new Type[validTypes.Count];
            names = new string[types.Length];
            for (int i = 0; i < types.Length; i++)
            {
                types[i] = validTypes[i];
                names[i] = validTypes[i].FullName;
            }
        }
Esempio n. 5
0
        public void DefineSlotNameTwice()
        {
            ProcessedType processedType = TypeProcessor.GetProcessedType(typeof(XMLTemplateParsing_DefineSlotNameTwice));
            TemplateCache cache         = new TemplateCache(Setup("App"));

            Assert.DoesNotThrow(() => { cache.GetParsedTemplate(processedType); });
        }
Esempio n. 6
0
    public override void Execute()
    {
        FindCoreReferences();

        var namespacesToSkip = GetNamespacesToSkip().ToList();

        foreach (var type in ModuleDefinition
                 .GetTypes()
                 .Where(x =>
                        x.IsClass() &&
                        !x.IsGeneratedCode() &&
                        !x.CustomAttributes.ContainsSkipWeaving() &&
                        !namespacesToSkip.Contains(x.Namespace)))
        {
            var disposeMethods = type.Methods
                                 .Where(x => !x.IsStatic && (x.Name == "Dispose" || x.Name == "System.IDisposable.Dispose"))
                                 .ToList();
            if (disposeMethods.Count == 0)
            {
                continue;
            }

            if (disposeMethods.Count > 1)
            {
                var message = $"Type `{type.FullName}` contains more than one `Dispose` method. Either remove one or add a `[Janitor.SkipWeaving]` attribute to the type.";
                LogError(message);
            }

            var disposeMethod = disposeMethods.First();

            if (!disposeMethod.IsEmptyOrNotImplemented())
            {
                var message = $"Type `{type.FullName}` contains a `Dispose` method with code. Either remove the code or add a `[Janitor.SkipWeaving]` attribute to the type.";
                LogError(message);
            }

            if (type.BaseType.Name != "Object")
            {
                var message = $"Type `{type.FullName}` has a base class which is not currently supported. Either remove the base class or add a `[Janitor.SkipWeaving]` attribute to the type.";
                LogError(message);
            }

            var methodProcessor = new TypeProcessor
            {
                DisposeMethod = disposeMethod,
                ModuleWeaver  = this,
                TargetType    = type,
            };
            methodProcessor.Process();
        }

        foreach (var typeDefinition in ModuleDefinition.GetTypes())
        {
            typeDefinition.CustomAttributes.RemoveSkipWeaving();
            foreach (var field in typeDefinition.Fields)
            {
                field.CustomAttributes.RemoveSkipWeaving();
            }
        }
    }
Esempio n. 7
0
        public void PropertyValueTest()
        {
            Type          o;
            object        fromObj;
            TypeProcessor processor = new TypeProcessor(typeof(TestType));

            fromObj = processor.CreateInstance();
            processor.SetProperty(fromObj, "L", new TestType());
            processor.SetProperty(fromObj, "M", new TestType());
            processor.SetProperty(fromObj, "N", new TestType());
            processor.SetProperty(fromObj, "O", new TestType());
            processor.SetProperty(fromObj, "P", new TestType());
            processor.SetProperty(fromObj, "Q", new TestType());
            processor.SetProperty(fromObj, "R", new TestType());
            processor.SetProperty(fromObj, "S", new TestType());
            processor.SetProperty(fromObj, "T", "I");
            processor.SetProperty(fromObj, "U", 99);
            processor.SetProperty(fromObj, "V", true);
            processor.SetProperty(fromObj, "GenericTypeName", "A");


            for (int i = 0; i < 10; i++)
            {
                var ToObj = processor.CreateInstance();
                foreach (PropertyInfo item in fromObj.GetType().GetProperties())
                {
                    processor.SetProperty(ToObj, item.Name, processor.GetProperty(fromObj, item.Name));
                    if (!processor.GetProperty(fromObj, item.Name).Equals(processor.GetProperty(ToObj, item.Name)))
                    {
                        Assert.Fail();
                    }
                }
            }
        }
Esempio n. 8
0
        internal static void Run()
        {
            TypeProcessor.AddPgTypeDefinitionFunction();
            Console.WriteLine("MixERP Documentation Generator.");

            DBRunner.Run();
            AssetRunner.Run();
        }
Esempio n. 9
0
        public void ParseNamespace()
        {
            ProcessedType    processedType = TypeProcessor.GetProcessedType(typeof(XMLTemplateParsing_Namespace));
            TemplateCache    cache         = new TemplateCache(Setup("App"));
            TemplateRootNode templateRoot  = cache.GetParsedTemplate(processedType);

            Assert.AreEqual(typeof(UIDivElement), templateRoot.children[0].processedType.rawType);
        }
    public void ContainsNotification()
    {
        var propertyDefinition = DefinitionFinder.FindProperty(() => new NonVirtual().WithNotifactionProperty);

        var message = TypeProcessor.AlreadyContainsNotification(propertyDefinition, "OnPropertyChanged");

        Assert.IsTrue(message);
    }
Esempio n. 11
0
        internal unsafe TypeBatch *CreateNewTypeBatch(int typeId, TypeProcessor typeProcessor, int initialCapacity, BufferPool pool)
        {
            Debug.Assert(typeProcessor != null, "Can't create a type batch for a nonexistent type processor. Did you forget to call Solver.Register<T> for the constraint type?");
            var newIndex = TypeBatches.Count;

            TypeBatches.EnsureCapacity(TypeBatches.Count + 1, pool);
            TypeIndexToTypeBatchIndex[typeId] = newIndex;
            ref var typeBatch = ref TypeBatches.AllocateUnsafely();
Esempio n. 12
0
        private string ReplaceGenericVar(string rawString, ExpressionSyntax expression)
        {
            var name = expression.As <MemberAccessExpressionSyntax>().Name.As <GenericNameSyntax>();

            var genericVar = TypeProcessor.ConvertType(name.TypeArgumentList.Arguments.Single());

            return(rawString.Replace("{genericType}", genericVar));
        }
Esempio n. 13
0
    public void Parse_NewExpressionNoArguments()
    {
        ASTNode           root           = ExpressionParser.Parse("new Vector3()");
        NewExpressionNode expressionNode = AssertInstanceOfAndReturn <NewExpressionNode>(root);

        Assert.AreEqual(typeof(Vector3), TypeProcessor.ResolveType(expressionNode.typeLookup, new string[] { "UnityEngine" }));
        Assert.AreEqual(0, expressionNode.parameters.Count);
    }
Esempio n. 14
0
        private static void Compile()
        {
            Loader loader = new Loader();

            foreach (String thriftFile in thriftFiles)
            {
                loader.addThriftFile(thriftFile);
            }

            foreach (String dir in searchPath)
            {
                loader.addIncludePath(dir);
            }

            Schema schema;

            try {
                schema = loader.Load();
            } catch (LoadFailedException e) {
                foreach (string report in e.ErrorReporter.formattedReports())
                {
                    Console.Out.WriteLine(report);
                }

                Environment.Exit(1);
                return;
            }

            ThriftyCodeGenerator gen = new ThriftyCodeGenerator(schema, fieldNamingPolicy);

            if (listTypeName != null)
            {
                gen = gen.withListType(listTypeName);
            }

            if (setTypeName != null)
            {
                gen = gen.withSetType(setTypeName);
            }

            if (mapTypeName != null)
            {
                gen = gen.withMapType(mapTypeName);
            }

            TypeProcessorService svc       = TypeProcessorService.getInstance();
            TypeProcessor        processor = svc.get();

            if (processor != null)
            {
                gen = gen.usingTypeProcessor(processor);
            }

            gen.emitAndroidAnnotations(emitNullabilityAnnotations);
            gen.emitParcelable(emitParcelable);

            gen.generate(outputDirectory);
        }
Esempio n. 15
0
 // Создаем конструктор
 public Computer(string Maker, TypeProcessor Processor, int ram, TypeDrive Drive)
 {
     this.Maker     = Maker;
     this.Processor = Processor;
     this.ram       = ram;
     this.Drive     = Drive;
     ID++;
     Id_comp = ID;
 }
Esempio n. 16
0
        public MethodTranslation(XElement data)
        {
            TranslationManager.InitProperties(this, data);

            Arguments           = data.Elements("Argument").Select(o => TranslationManager.InitProperties(new ArgumentModifier(), o)).ToList();
            MatchTypeParameters = data.Elements("MatchTypeParameter").Select(o => TranslationManager.InitProperties(new MatchTypeParameter(), o)).ToList();
            AddTypeParameters   = data.Elements("AddTypeParameter").Select(o => TranslationManager.InitProperties(new AddTypeParameter(), o)).ToList();

            if (data.Element("ReplaceWith") != null)
            {
                DoComplexReplaceWith = (writer, expression) =>
                {
                    foreach (var element in data.Element("ReplaceWith").Elements())
                    {
                        switch (element.Name.LocalName)
                        {
                        case "String":
                            writer.Write(ReplaceSpecialIndicators(element.Value, expression));
                            break;

                        case "Expression":
                            Core.Write(writer, expression.Expression);
                            break;

                        case "TypeParameter":
                            var typePrmIndex = int.Parse(element.Attribute("Index").Value);
                            var convert      = element.Attribute("Convert") == null ? true : bool.Parse(element.Attribute("Convert").Value);

                            var type = expression.Name.As <GenericNameSyntax>().TypeArgumentList.Arguments[typePrmIndex];

                            if (convert)
                            {
                                writer.Write(TypeProcessor.ConvertType(type));
                            }
                            else
                            {
                                var typeSymbol = TypeProcessor.GetTypeSymbol(type);
                                writer.Write(typeSymbol.ContainingNamespace.ToString());
                                writer.Write(".");
                                writer.Write(typeSymbol.Name);
                            }
                            break;

                        case "Argument":
                            int argIndex = int.Parse(element.Attribute("Index").Value);
                            var invoke   = expression.Parent.As <InvocationExpressionSyntax>();
                            Core.Write(writer, invoke.ArgumentList.Arguments.ElementAt(argIndex).Expression);
                            break;

                        default:
                            throw new Exception("Unexpected element name " + element.Name);
                        }
                    }
                };
            }
        }
Esempio n. 17
0
        public void ParseNamespace_NotThere()
        {
            ParseException exception = Assert.Throws <ParseException>(() => {
                ProcessedType processedType = TypeProcessor.GetProcessedType(typeof(XMLTemplateParsing_Namespace_Unknown));
                TemplateCache cache         = new TemplateCache(Setup("App"));
                cache.GetParsedTemplate(processedType);
            });

            Assert.IsTrue(exception.Message.Contains(ParseException.UnresolvedTagName("Data/XMLTemplateParsing/XMLTemplateParsing_Namespaces.xml", new TemplateLineInfo(11, 10), "NotHere:Div").Message));
        }
Esempio n. 18
0
        private static void BuildDocumentation(string content, List <string> matches)
        {
            ICollection <PgType> types = TypeProcessor.GetTypes(Program.SchemaPattern);

            content = content.Replace("[DBName]", Program.Database.ToUpperInvariant());

            content = Parsers.TypeParser.Parse(content, matches, types);

            FileHelper.WriteFile(content, OutputPath);
        }
Esempio n. 19
0
        public void Process(XElement elementToProcess)
        {
            //Get ref
            var elementRefAttribute = elementToProcess.Attribute("ref");

            if (elementRefAttribute != null)
            {
                return;
            }

            //Get name
            var elemNameAttribute = elementToProcess.Attribute("name");
            var elementName       = elemNameAttribute.Value;

            //Get type
            var elementTypeName = GetElementType(elementToProcess);

            if (elementTypeName != null)
            {
                var processedElement = new Element(elementName, elementTypeName);
                _validator.AddElement(processedElement);
                return;
                //TODO: may be return
            }

            var innerElements = elementToProcess.Elements();

            var typeElementsCount = innerElements.Count(e => e.Name.LocalName.Contains("Type"));

            if (typeElementsCount == 0)
            {
                throw new Exception($"Не указан вложенный элемент simpleType или complexType для элемента {elementToProcess}");
            }

            if (typeElementsCount > 1)
            {
                throw new Exception($"Указано более одного вложенного типа simpleType или complexType для элемента {elementToProcess}");
            }

            var typeElement = innerElements.SingleOrDefault(e => e.Name.LocalName.Contains("Type"));

            if (typeElement == null)
            {
                throw new Exception("Указан вложенный элемент типа, при заданном атребибуте 'type'");
            }


            var typeProcessor = TypeProcessor.GetProcessor(typeElement, _validator);

            var type = typeProcessor.Process($"{elementName}Type", typeElement);

            _validator.AddType(type);
            _validator.AddElement(new Element(elementName, type.Name));
        }
Esempio n. 20
0
    public void Parse_LambdaTypedParameter_2()
    {
        ASTNode root = ExpressionParser.Parse("(string value, System.Collections.Generic.List<int> listValue) => value");
        LambdaExpressionNode node = AssertInstanceOfAndReturn <LambdaExpressionNode>(root);

        Assert.AreEqual(2, node.signature.Count);
        Assert.AreEqual("string", node.signature[0].type.Value.typeName);
        Assert.AreEqual("value", node.signature[0].identifier);
        Assert.AreEqual(typeof(List <int>), TypeProcessor.ResolveType(node.signature[1].type.Value));
        Assert.AreEqual("listValue", node.signature[1].identifier);
    }
Esempio n. 21
0
        private static void Main(string[] args)
        {
            //var p = new Program();
            //p.Release();

            var pro = new TypeProcessor();

            pro.Processing(null, typeof(ABC));
            var a = TypeProcessor.TryGetAttribute(typeof(ABC), out var attribute);
            var b = TypeProcessor.TryGetActivator(typeof(ABC), out var validator);
        }
Esempio n. 22
0
    public void ResolveArrayType()
    {
        TypeLookup lookup = new TypeLookup();

        lookup.typeName      = "String";
        lookup.namespaceName = "System";
        lookup.isArray       = true;
        Type t = TypeProcessor.ResolveType(lookup);

        Assert.AreEqual(typeof(string[]), t);
    }
        public void LoadDescriptor_ConfirmAndReorganizeUnordered_ResultIsOrdered()
        {
            String expected =
                "Offset: \"0\", Header: \"<null>\", Origin: \"Property2\"" +
                "Offset: \"1\", Header: \"<null>\", Origin: \"Property1\"" +
                "Offset: \"2\", Header: \"<null>\", Origin: \"Property4\"" +
                "Offset: \"3\", Header: \"<null>\", Origin: \"Property3\"";

            TypeDescriptor instance = TypeProcessor.LoadDescriptor <TestClassUnordered>();

            Assert.AreEqual(expected, String.Join("", instance.Settings));
        }
Esempio n. 24
0
        public void DefineSlot()
        {
            TemplateCache    cache            = new TemplateCache(Setup("App"));
            TemplateRootNode templateRootRoot = cache.GetParsedTemplate(TypeProcessor.GetProcessedType(typeof(XMLTemplateParsing_DefineSlot)));

            Assert.AreEqual(1, templateRootRoot.ChildCount);

            ContainerNode child = AssertAndReturn <ContainerNode>("Div", templateRootRoot[0]);
            SlotNode      node  = AssertAndReturn <SlotNode>(child[0]);

            Assert.AreEqual("my-slot", node.slotName);
        }
Esempio n. 25
0
        public void CollapseTextNode_Simple()
        {
            TemplateCache    cache            = new TemplateCache(Setup("App"));
            TemplateRootNode templateRootRoot = cache.GetParsedTemplate(TypeProcessor.GetProcessedType(typeof(XMLTemplateParsing_CollapseTextNode_Simple)));

            Assert.AreEqual(1, templateRootRoot.ChildCount);

            ContainerNode child = AssertAndReturn <ContainerNode>(templateRootRoot[0]);
            TextNode      text  = AssertAndReturn <TextNode>(child[0]);

            Assert.AreEqual("Hello Templates", text.textExpressionList[0].text);
        }
Esempio n. 26
0
    public void Parse_NewExpression_NamespaceWithGeneric()
    {
        ASTNode           root           = ExpressionParser.Parse("new System.Tuple<float, float, float>(1, 2, 3)");
        NewExpressionNode expressionNode = AssertInstanceOfAndReturn <NewExpressionNode>(root);

        Assert.AreEqual(typeof(Tuple <float, float, float>), TypeProcessor.ResolveType(expressionNode.typeLookup));
        Assert.AreEqual(3, expressionNode.parameters.Count);
        LiteralNode param0 = AssertInstanceOfAndReturn <LiteralNode>(expressionNode.parameters[0]);
        LiteralNode param1 = AssertInstanceOfAndReturn <LiteralNode>(expressionNode.parameters[1]);
        LiteralNode param2 = AssertInstanceOfAndReturn <LiteralNode>(expressionNode.parameters[2]);

        Assert.AreEqual("1", param0.rawValue);
        Assert.AreEqual("2", param1.rawValue);
        Assert.AreEqual("3", param2.rawValue);
    }
Esempio n. 27
0
    public void Parse_NewExpression()
    {
        ASTNode           root           = ExpressionParser.Parse("new Vector3(1, 2, 3)");
        NewExpressionNode expressionNode = AssertInstanceOfAndReturn <NewExpressionNode>(root);

        Assert.AreEqual(typeof(Vector3), TypeProcessor.ResolveType(expressionNode.typeLookup, new string[] { "UnityEngine" }));
        Assert.AreEqual(3, expressionNode.parameters.Count);
        LiteralNode param0 = AssertInstanceOfAndReturn <LiteralNode>(expressionNode.parameters[0]);
        LiteralNode param1 = AssertInstanceOfAndReturn <LiteralNode>(expressionNode.parameters[1]);
        LiteralNode param2 = AssertInstanceOfAndReturn <LiteralNode>(expressionNode.parameters[2]);

        Assert.AreEqual("1", param0.rawValue);
        Assert.AreEqual("2", param1.rawValue);
        Assert.AreEqual("3", param2.rawValue);
    }
Esempio n. 28
0
    public void Execute(List <TypeDefinition> classes)
    {
        foreach (var type in classes)
        {
            var baseType = implementsInterfaceFinder.HierarchyImplementsIFreezable(type);
            if (baseType == null)
            {
                continue;
            }
            var checkMethod = freezeCheckerInjector.Execute(baseType);

            var typeProcessor = new TypeProcessor(logInfo, checkMethod, type);
            typeProcessor.Execute();
        }
    }
Esempio n. 29
0
    public void Execute(List<TypeDefinition> classes)
    {
        foreach (var type in classes)
        {
            var baseType = implementsInterfaceFinder.HierarchyImplementsIFreezable(type);
            if (baseType == null)
            {
                continue;
            }
            var checkMethod = freezeCheckerInjector.Execute(baseType);

            var typeProcessor = new TypeProcessor(logInfo, checkMethod, type);
            typeProcessor.Execute();
        }
    }
Esempio n. 30
0
    public void ResolveWithNamespaceNoOrigin()
    {
        Type t = TypeProcessor.ResolveType("Color", new List <string>()
        {
            "UnityEngine"
        });

        Assert.AreEqual(typeof(Color), t);

        Type t1 = TypeProcessor.ResolveType("SortedList", new List <string>()
        {
            "System.Collections"
        });

        Assert.AreEqual(typeof(System.Collections.SortedList), t1);
    }
Esempio n. 31
0
        public void ExpandedTemplate()
        {
            ProcessedType    processedType    = TypeProcessor.GetProcessedType(typeof(XMLTemplateParsing_ExpandTemplate));
            TemplateCache    cache            = new TemplateCache(Setup("App"));
            TemplateRootNode templateRootRoot = cache.GetParsedTemplate(processedType);

            Assert.AreEqual(3, templateRootRoot.ChildCount);

            AssertAndReturn <TextNode>(templateRootRoot[0]);

            ExpandedTemplateNode expandedTemplate = AssertAndReturn <ExpandedTemplateNode>(templateRootRoot[1]);

            Assert.AreEqual(typeof(XMLTemplateParsing_ExpandedTemplateChild), expandedTemplate.processedType.rawType);

            AssertAndReturn <TextNode>(templateRootRoot[2]);
        }
Esempio n. 32
0
    public void Execute()
    {
        FindCoreReferences();

        foreach (var type in ModuleDefinition
            .GetTypes()
            .Where(x =>
                x.IsClass() &&
                !x.IsAbstract &&
                !x.CustomAttributes.ContainsSkipWeaving()))
        {
            var disposeMethods = type.Methods
                                     .Where(x => !x.IsStatic && x.Name == "Dispose")
                                     .ToList();
            if (disposeMethods.Count == 0)
            {
                continue;
            }
            if (disposeMethods.Count > 1)
            {
                var message = string.Format("Type `{0}` contains more than one `Dispose` method. Either remove one or add a `[Janitor.SkipWeaving]` attribute to the type.", type.FullName);
                throw new WeavingException(message);
            }
            var disposeMethod = disposeMethods.First();

            if (disposeMethod.Body.Instructions.Count(x=>x.OpCode !=  OpCodes.Nop) > 1)
            {
                var message = string.Format("Type `{0}` contains a `Dispose` method with code. Either remove the code or add a `[Janitor.SkipWeaving]` attribute to the type.", type.FullName);
                throw new WeavingException(message);
            }
            if (type.BaseType.Name != "Object")
            {
                var message = string.Format("Type `{0}` has a base class which is not currently supported. Either remove the base class or add a `[Janitor.SkipWeaving]` attribute to the type.", type.FullName);
                throw new WeavingException(message);
            }

            var methodProcessor = new TypeProcessor
                                  {
                                      DisposeMethod = disposeMethod,
                                      ModuleWeaver = this,
                                      TargetType = type,
                                      LogInfo = LogInfo
                                  };
            methodProcessor.Process();
        }
        CleanReferences();
    }
Esempio n. 33
0
    public void Execute()
    {
        LoggerFactory.LogInfo = LogInfo;
        LoggerFactory.LogWarn = LogWarning;
        LoggerFactory.LogError = LogError;

        FindCoreReferences();

        foreach (var type in ModuleDefinition
            .GetTypes()
            .Where(x =>
                x.IsClass() &&
                !x.IsAbstract &&
                !x.IsGeneratedCode() &&
                !x.CustomAttributes.ContainsSkipWeaving()))
        {
            var disposeMethods = type.Methods
                                     .Where(x => !x.IsStatic && (x.Name == "Dispose" || x.Name == "System.IDisposable.Dispose"))
                                     .ToList();
            if (disposeMethods.Count == 0)
            {
                continue;
            }
            if (disposeMethods.Count > 1)
            {
                var message = string.Format("Type `{0}` contains more than one `Dispose` method. Either remove one or add a `[Janitor.SkipWeaving]` attribute to the type.", type.FullName);
                LogError(message);
            }
            var disposeMethod = disposeMethods.First();

            if (!disposeMethod.IsEmptyOrNotImplemented())
            {
                var message = string.Format("Type `{0}` contains a `Dispose` method with code. Either remove the code or add a `[Janitor.SkipWeaving]` attribute to the type.", type.FullName);
                LogError(message);
            }
            if (type.BaseType.Name != "Object")
            {
                var message = string.Format("Type `{0}` has a base class which is not currently supported. Either remove the base class or add a `[Janitor.SkipWeaving]` attribute to the type.", type.FullName);
                LogError(message);
            }

            var methodProcessor = new TypeProcessor
                                  {
                                      DisposeMethod = disposeMethod,
                                      ModuleWeaver = this,
                                      TargetType = type,
                                  };
            methodProcessor.Process();
        }
        CleanReferences();
    }
Esempio n. 34
0
 public AssemblyProcessor(TypeProcessor typeProcessor, MakeMockable makeMockable)
 {
     this.typeProcessor = typeProcessor;
     this.makeMockable = makeMockable;
 }