Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Return of type T

$
0
0

@Mattlekim wrote:

Hi im not sure if this is possible or not but after a lot of trying and search I have not been able to get it to work
my code is bellow.

 public T To<T>()
            {
                if (typeof(T) == typeof(VertexPositionColourNormal))
                    return new VertexPositionColourNormal()
                    {
                        Position = this.Position,
                        Color = this.Color,
                        Normal = this.Normal,
                    } ;

                if (typeof(T) == typeof(VertexPositionColourNormalTexture))
                    return new VertexPositionColourNormalTexture()
                    {
                        Position = this.Position,
                        Color = this.Color,
                        Normal = this.Normal,
                        TextureCoordinate = this.TextureCoordinate,
                    };

                throw new Exception("Vertex Type Not Implemented in VertexTemp.To<T>");
            }

now I would like to be able to return a different type depending on the input type. Is it possible to do this?

Or will i have to return an object and then typecast it?

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles