GPPointFileInfo\GPFunctionFactory.cs
Creating a non-trival custom GP tool - inputs, outputs, and responding to environment settings
GPPointFileInfo\GPFunctionFactory.cs
// Copyright 2008 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.
// 

using System;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.Geodatabase;

namespace GPPointFileInfo
{
    [Guid("1EFD53C7-2A24-4207-8AEA-D23B4C2D4B21"), ComVisible(true)]

    public class GPFunctionFactory : IGPFunctionFactory
    {
        private string _name = "Developer Samples";
        private string _alias = "Developer Samples";

        #region "Component Category Registration"
        [ComRegisterFunction()]
        static void Reg(string regKey)
        {
            GPFunctionFactories.Register(regKey);
        }

        [ComUnregisterFunction()]
        static void Unreg(string regKey)
        {
            GPFunctionFactories.Unregister(regKey);
        }
        #endregion

        #region IGPFunctionFactory Members

        public string Name
        {
            get
            {
                return _name;
            }
        }

        public string Alias
        {
            get
            {
                return _alias;
            }
        }

        public UID CLSID
        {
            get
            {
                UID clsid = new UIDClass() as UID;

                clsid.Value = this.GetType().GUID.ToString("B");

                return clsid;
            }
        }

        public IGPFunction GetFunction(string name)
        {
            IGPFunction gpFunction;

            switch (name)
            {
                case ("PointFileInfo"):
                    
                    gpFunction = new GPPointFileInfoFunction();
                    
                    break;

                default:

                    throw new GPException(GPExceptionSeverity.Fatal, "Invalid Point File Info Function Factory. Unable To Get Function. Unhandled Case." + ObjectToString.GetNewline() + "name: " + ObjectToString.GetToString(name));
            }

            return gpFunction;
        }

        public IGPName GetFunctionName(string name)
        {
            IGPName gpName;

            switch (name)
            {
                case ("PointFileInfo"):

                    gpName = CreateGPFunctionNames(0) as IGPName;

                    break;

                default:

                    throw new GPException(GPExceptionSeverity.Fatal, "Invalid Point File Info Function Factory. Unable To Get Function Name. Unhandled Case." + ObjectToString.GetNewline() + "name: " + ObjectToString.GetToString(name));
            }

            return gpName;
        }

        public IEnumGPName GetFunctionNames()
        {
            IEnumGPName enumGPName = new EnumGPNameClass();

            IArray array = enumGPName as IArray;

            array.Add(CreateGPFunctionNames(0));

            return enumGPName;
        }

        private IGPFunctionName CreateGPFunctionNames(long index)
        {
            IGPFunctionName gpFunctionName;

            switch (index)
            {
                case (0):
                    
                    gpFunctionName = GetPointFileInfoGPFunctionName();
                    
                    break;

                default:

                    throw new GPException(GPExceptionSeverity.Fatal, "Invalid Point File Info Function Factory. Unable To Create GP Function Names. Unhandled Case." + ObjectToString.GetNewline() + "index: " + ObjectToString.GetToString(index));
            }

            return gpFunctionName;
        }

        private IGPFunctionName GetPointFileInfoGPFunctionName()
        {
            IGPFunctionName gpFunctionName = new GPFunctionNameClass();

            IGPName gpName = gpFunctionName as IGPName;

            gpName.Category = "Terrain";
            gpName.Description = "This tool generates a 2D or 3D output feature class containing statistical information about input XYZ, LAS, or GENERATE data to be used in the Terrain build process.";
            gpName.DisplayName = "Point File Information";
            gpName.Name = "PointFileInfo";
            gpName.Factory = this as IGPFunctionFactory;

            return gpFunctionName;
        }

        public IEnumGPEnvironment GetFunctionEnvironments()
        {
            return null;
        }

        #endregion
    }
}