コード例 #1
0
        private static ITextTemplatingEngineHost HostFactory(TextTransformation transformation)
        {
            Type         transformationType = transformation.GetType();
            PropertyInfo hostProperty       = transformationType.GetProperty("Host");

            if (hostProperty == null)
            {
                throw new NotSupportedException(
                          "Unable to access the templating engine host. "
                          + "Please make sure your template includes hostspecific=\"true\" "
                          + "attribute in the <#@ template #> directive.");
            }

            return((ITextTemplatingEngineHost)hostProperty.GetValue(transformation, null));
        }
コード例 #2
0
        internal TransformationContext(TextTransformation transformation, StringBuilder generationEnvironment)
        {
            if (transformation == null)
            {
                throw new ArgumentNullException("transformation");
            }

            if (generationEnvironment == null)
            {
                throw new ArgumentNullException("generationEnvironment");
            }

            PropertyInfo hostProperty = transformation.GetType().GetProperty("Host");

            if (hostProperty == null)
            {
                throw new ArgumentException("TextTransformation does not have Host property");
            }

            this.Host = (ITextTemplatingEngineHost)hostProperty.GetValue(transformation);
            if (this.Host == null)
            {
                throw new ArgumentException("TextTransformation.Host is null.");
            }

            this.Transformation = transformation;

            // Create a special output file for the transformation output.
            this.outputFiles.Add(new OutputFile(generationEnvironment));

            this.provider = (ITransformationContextProvider)this.GetService(typeof(ITransformationContextProvider));
            if (this.provider == null)
            {
                throw new InvalidOperationException("ITransformationContextProvider service is not available.");
            }

            this.InitializeParameters();
        }