Exemplo n.º 1
0
        public CSharpIdentifier ToInterface()
        {
            var result = new CSharpIdentifier(Namespace, "I" + Name);

            result.TypeArguments.AddRange(TypeArguments);
            return(result);
        }
Exemplo n.º 2
0
        public void GeneratesCorrectCode()
        {
            var myInterface       = new CSharpIdentifier(ns: "Namespace1", name: "MyInterface");
            var baseInterface     = new CSharpIdentifier(ns: "Namespace2", name: "BaseInterface");
            var endpointInterface = new CSharpIdentifier("TypedRest.Endpoints.Generic", "ICollectionEndpoint")
            {
                TypeArguments = { new CSharpIdentifier(ns: "Models", name: "MyModel") }
            };

            Assert(new CSharpInterface(myInterface)
            {
                Description = "My interface",
                Interfaces  = { baseInterface },
                Properties  =
                {
                    new CSharpProperty(endpointInterface, "MyProperty")
                    {
                        Description = "My property"
                    }
                }
            }, @"using Models;
using Namespace2;
using TypedRest.Endpoints.Generic;

namespace Namespace1
{
    /// <summary>
    /// My interface
    /// </summary>
    public interface MyInterface : BaseInterface
    {
        /// <summary>
        /// My property
        /// </summary>
        public ICollectionEndpoint<MyModel> MyProperty
        {
            get;
        }
    }
}");
        }
Exemplo n.º 3
0
 public CSharpInterface([NotNull] CSharpIdentifier identifier)
 {
     Identifier = identifier ?? throw new ArgumentNullException(nameof(identifier));
 }
 public CSharpClassConstruction([NotNull] CSharpIdentifier type)
 {
     Type = type ?? throw new ArgumentNullException(nameof(type));
 }
Exemplo n.º 5
0
 public CSharpProperty([NotNull] CSharpIdentifier type, [NotNull] string name)
 {
     Type = type ?? throw new ArgumentNullException(nameof(type));
     Name = name ?? throw new ArgumentNullException(nameof(name));
 }
        public void GeneratesCorrectCode()
        {
            var myClass     = new CSharpIdentifier(ns: "Namespace1", name: "MyClass");
            var myModel     = new CSharpIdentifier(ns: "Models", name: "MyModel");
            var myInterface = new CSharpIdentifier(ns: "Namespace1", name: "MyInterface")
            {
                TypeArguments = { myModel }
            };
            var otherClass = new CSharpIdentifier(ns: "Namespace1", name: "OtherClass")
            {
                TypeArguments = { myModel }
            };
            var baseClass         = new CSharpIdentifier(ns: "Namespace2", name: "BaseClass");
            var endpointInterface = new CSharpIdentifier("TypedRest.Endpoints", "IEndpoint");

            Assert(new CSharpClass(myClass)
            {
                Description = "My class",
                BaseClass   = new CSharpClassConstruction(baseClass)
                {
                    Parameters =
                    {
                        new CSharpParameter(endpointInterface,       "referrer"),
                        new CSharpParameter(CSharpIdentifier.String, "relativeUri")
                        {
                            Value = "./sample"
                        }
                    }
                },
                Interfaces = { myInterface },
                Properties =
                {
                    new CSharpProperty(myInterface, "MyProperty")
                    {
                        Description      = "My property",
                        GetterExpression = new CSharpClassConstruction(otherClass)
                        {
                            Parameters =
                            {
                                new CSharpParameter(CSharpIdentifier.String, "arg1")
                                {
                                    Value = "value"
                                }
                            }
                        }
                    }
                }
            }, @"using Models;
using Namespace2;
using TypedRest.Endpoints;

namespace Namespace1
{
    /// <summary>
    /// My class
    /// </summary>
    public class MyClass : BaseClass, MyInterface<MyModel>
    {
        public MyClass(IEndpoint referrer): base(referrer, relativeUri: ""./sample"")
        {
        }

        /// <summary>
        /// My property
        /// </summary>
        public MyInterface<MyModel> MyProperty => new OtherClass<MyModel>(arg1: ""value"");
    }
}");
        }