Spark.Mid.MidBuiltinType.GetTemplate C# (CSharp) Method

GetTemplate() public method

public GetTemplate ( string profile ) : string
profile string
return string
        public string GetTemplate(string profile)
        {
            // \todo: Right now we are crashing here for IndexBuffer
            // because the builtin tags are associated with
            // the generic decl, and not with the type-slot decl.
            //
            // In order to resolve this, we'd either need to make
            // sure that the tags of the generic decl are reflected
            // on the inner decl (via a change to that schema), or
            // ensure that the Res->Mid lowering process explicitly
            // passes down any tags as needed...

            return (from tag in _tags
                    where tag.Profile == profile
                    select tag.Template).First();
        }

Usage Example

        private ITypeHLSL EmitTypeImpl(MidBuiltinType type)
        {
            var template = type.GetTemplate("hlsl");
            if (template == null)
            {
                Diagnostics.Add(
                    Severity.Error,
                    new SourceRange(),
                    "No HLSL equivalent for type {0}", type);
                return new ErrorTypeHLSL();
            }
            if (type.Args == null)
                return new ScalarTypeHLSL(template);

            var args = (from a in type.Args
                        select EmitGenericArg(a)).Eager();

            // I hate hacks... :(
            if (template == "__Array")
            {
                var baseType = (EmitTypeHLSL)args[0];
                var count = (EmitValHLSL)args[1];

                return MakeArrayType(
                    baseType,
                    count);
            }

            return new ScalarTypeHLSL(string.Format(template, args));
        }