为什么我的类库方法不出现在我引用的控制台应用程序中?

时间:2014-01-10 02:56:01

标签: c# visual-studio-2010 reference class-library

我写了一个类库。为了执行我在类库中编写的方法,我创建了一个控制台应用程序。在我的控制台应用程序中,我添加了我编写的类库作为参考。然后我将适当的using语句添加到我的控制台应用程序中。我目前无法访问此库中的方法。为什么呢?

这是我的类库,带有基本方法。它是在.NET framework 3.5中创建的。

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geometry;

namespace RelateTablesValidation
{

    [Guid("e1058544-0d84-49be-a406-b4e65707f95b")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("RelateTablesValidation.Validate")]
    [ComVisible(true)]



    public class Validate : ESRI.ArcGIS.Geodatabase.IClassExtension, ESRI.ArcGIS.Geodatabase.IObjectClassExtension, ESRI.ArcGIS.Geodatabase.IRelatedObjectClassEvents2 

    {

    public void ChangeClassExtension(IObjectClass objectClass, String extensionUID, IPropertySet extensionProperties)
            {
                ISchemaLock schemaLock = (ISchemaLock)objectClass;

                try
                {
                    // Attempt to get an exclusive schema lock.
                    schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                    // Cast the object class to the IClassSchemaEdit2 interface.
                    IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)objectClass;

                    if (!String.IsNullOrEmpty(extensionUID))
                    {
                        // Create a unique identifier (UID) object and change the extension.
                        UID extUID = new UIDClass();
                        extUID.Value = extensionUID;
                        classSchemaEdit.AlterClassExtensionCLSID(extUID, extensionProperties);
                    }
                    else
                    {
                        // Clear the class extension.
                        classSchemaEdit.AlterClassExtensionCLSID(null, null);
                    }
                }
                catch (COMException comExc)
                {
                    throw new Exception("Could not change class extension.", comExc);
                }
                finally
                {
                    schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
                }
            }
}

这是我的控制台应用。 RelateTablesValidation是类库。也是在.NET Framework 3.5中创建的

using System;
using System.Collections.Generic;
using System.Text;
using RelateTablesValidation;
using Esri.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DatasourcesGDB;

    namespace ApplyClassExtension
    {
    class Program
        {


            [STAThread()]
            static void Main(string[] args)
            {
                //system sees objects from this namespace OK
                IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory(); 


                //now when i try to call my method, it doesn't even show up in Intellisense
                ChangeClassExtension(method params would go here);

            }
        }
    }

1 个答案:

答案 0 :(得分:1)

你无法做你想做的事。

C#中的所有方法都在对象内部。你必须制作方法static并像这样调用它:

Validate.ChangeClassExtension(...);

或者不要使其静态并实例化Validate的实例:

var val = new Validate();
val.ChangeClassExtension(...);