Esempio n. 1
0
        private string MakeCode()
        {
            var hasEvents    = this.BaseType.HasEvents();
            var methods      = this.GetGeneratedMethods(hasEvents);
            var constructors = this.GetGeneratedConstructors();
            var properties   = this.GetGeneratedProperties(hasEvents);
            var events       = this.GetGeneratedEvents();

            this.IsUnsafe |= constructors.IsUnsafe || events.IsUnsafe || methods.IsUnsafe || properties.IsUnsafe;
            this.RequiresObsoleteSuppression |= this.BaseType.GetCustomAttribute <ObsoleteAttribute>() != null ||
                                                constructors.RequiresObsoleteSuppression || events.RequiresObsoleteSuppression ||
                                                methods.RequiresObsoleteSuppression || properties.RequiresObsoleteSuppression;

            this.Namespaces.Remove(this.BaseType.Namespace);

            var(_, constraints) = this.BaseType.GetGenericArguments(this.Namespaces);

            var namespaces = string.Join(Environment.NewLine,
                                         (from @namespace in this.Namespaces
                                          select $"using {@namespace};"));

            var @class = ClassTemplates.GetClass(namespaces,
                                                 this.TypeName, this.BaseType.GetFullName(),
                                                 methods.Result, properties.Result, events.Result, constructors.Result,
                                                 this.BaseType.Namespace,
                                                 this.Options.Serialization == SerializationOption.Supported ?
                                                 "[Serializable]" : string.Empty,
                                                 this.Options.Serialization == SerializationOption.Supported ?
                                                 ConstructorTemplates.GetConstructorWithNoArguments(this.GetTypeNameWithNoGenerics()) : string.Empty,
                                                 this.GetAdditionNamespaceCode(),
                                                 this.IsUnsafe, constraints,
                                                 hasEvents ? "R.IMockWithEvents" : "R.IMock",
                                                 hasEvents ? ClassTemplates.GetRaiseImplementation() : string.Empty);

            if (this.RequiresObsoleteSuppression)
            {
                @class = ClassTemplates.GetClassWithObsoleteSuppression(@class);
            }

            return(@class);
        }
Esempio n. 2
0
        public static void GetConstructorNoArguments() =>
        Assert.That(ConstructorTemplates.GetConstructorWithNoArguments("a"), Is.EqualTo(
                        @"public a() =>
	this.handlers = new SCO.ReadOnlyDictionary<int, SCO.ReadOnlyCollection<R.HandlerInformation>>(
		new SCG.Dictionary<int, SCO.ReadOnlyCollection<R.HandlerInformation>>());"        ));