我正在尝试从此构造函数返回一个值 它从类库项目中获取一个名为client.Handlers
的命名空间的文件 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace client.Handlers
{
[Serializable]
class ServiceFile : MarshalByRefObject
{
private string _ServiceFile;
#region Constructor
//Creating a constructor with the parameter filename
public ServiceFile(string filename)
{
//Loading the network file for synchronization
//Getting Directory information
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(@"C:\Users\Rick\Documents\Visual Studio 2010\Projects\Server\client.Handlers\ClientService\");
//Getting File info
System.IO.FileInfo[] fileNames = dirInfo.GetFiles(filename + "*.xml*");
foreach (FileInfo fi in fileNames)
{
//NetWorkLoader.Items.Add(fi.Name);
_ServiceFile = fi.Name;
}
}
#endregion
public string Files
{
get
{
return _ServiceFile;
}
}
}
}
这是从构造函数
获取值的类 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace client.Handlers
{
[Serializable]
public class HandlerMethods : MarshalByRefObject
{
#region Private Members
//Calls the instance of the ServiceFile list, Define a list for the ServicFile Class
private List<ServiceFile> _servicefiles = new List<ServiceFile> { };
#endregion
/// <summary>
/// Gets the service file using the FindFileByName
/// and Validates before it returns the file to the user
/// </summary> This is the HandlerMethod.cs file
/// <param name="userName">User name to add</param>
public string GetServiceFile(string file)
{
ServiceFile File = FindFileByName(file);
string filed = "";
if (file != null)
{
filed = File.Files;
return filed;
}
return null;
}
/// <summary>
/// Returns a ServiceFile instance by the File name.
/// </summary>
/// <param name="servicefile">Name of the File to locate.</param>
/// <returns>User</returns>
private ServiceFile FindFileByName(string serviceFile)
{
if (serviceFile == String.Empty) return null;
//Adds the file to a list
return _servicefiles.FirstOrDefault(u => u.Files == serviceFile);
}
}
}
我有一个项目,它导入名称空间client.Handlers并调用HandlerMethods 从库类文件夹
返回文件 using System.IO;
using client.Handlers;
namespace Client
{
public partial class ClientTest : Form
{
public ClientTest()
{
InitializeComponent();
}
#region Private Members
private const string _errorHeader = "ERROR:";
client.Handlers.HandlerMethods _handlermethods;
string _clientName = String.Empty;
bool _connecting = false;
#endregion
/// <summary>
/// Method to call the HandlerMethod class methods to get the data from the source file
/// class files
/// </summary>
private void getxml_serviceFile()
{
string MyFileName = txtNetKey.Text;
try
{
//This keeps returning Null no errors are occurring, This suppose to return
//the file from the library class directory to copy to this project directory
lbltest.Text = _handlermethods.GetServiceFile(MyFileName);
//Do something here
// Gets the file and copys or writes it to the this projects directory
}
catch (Exception)
{
}
}
private void btnTest_Click(object sender, EventArgs e)
{
getxml_serviceFile();
}
}
}
我试图让源文件通过名称空间继承通过调用一个方法文件从库类项目返回一个文件,该文件具有从其目录中获取文件的类文件的实例我希望这样做对你们有些人的感觉因为我真的需要一些帮助没有代码是错误的它只是没有返回文件,任何帮助都会很棒.. 再次谢谢