下面是 Vendor.cs文件的内容开始在开始处声明
private AcmeReaderLayer reader1;
// AcmeReaderLayer 是一个类文件函数里的一段代码:byte[] aa = new byte[36];
ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
if (null != applyPropertyProfileCommand.PropertyProfile)
{
foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
{
bool error = false;
try
{
aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
在这错误: “ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
}
catch (Exception e)
{
throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
}
}setAppProperty函数声明如下:
internal byte[] setAppProperty(AcmeReaderLayer reader1, string propertyName, string propertyValue)
{
this.reader1 = reader1;
byte[] para = { 0x01, 0x02 };
switch (propertyName)
{
case "ID":
return para;
break;
case "NAME":
reader.name = propertyValue; //TODO: Currently unsupported.
return para;
break;
}
}
private AcmeReaderLayer reader1;
// AcmeReaderLayer 是一个类文件函数里的一段代码:byte[] aa = new byte[36];
ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
if (null != applyPropertyProfileCommand.PropertyProfile)
{
foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
{
bool error = false;
try
{
aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
在这错误: “ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
}
catch (Exception e)
{
throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
}
}setAppProperty函数声明如下:
internal byte[] setAppProperty(AcmeReaderLayer reader1, string propertyName, string propertyValue)
{
this.reader1 = reader1;
byte[] para = { 0x01, 0x02 };
switch (propertyName)
{
case "ID":
return para;
break;
case "NAME":
reader.name = propertyValue; //TODO: Currently unsupported.
return para;
break;
}
}
您指的init 是什么意思?问题中的 代码都是 在一个 cs文件里, AcmeReaderLayer 是一个类文件名
因此我在 这个vendor.cs文件里
首先声明 private AcmeReaderLayer reader1;
而在调用时aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);报的错误:“ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
大家都帮想个法子,问过MS 那哥们了,目前还没答案,他说等他回复呢 正个项目快好了, 这个问题解决了,基本就ok了 等BizTalk 发布,就能用了
在这错误: “ Error 3 An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string)' “
=================
这段函数代码在什么样的一个函数里
An object reference is required for the nonstatic field
你这段函数是static的???
而在调用时aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
你的这段代码是不是static的??类似:
pulbic static void test()
{
...
aa= setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
...
}
aa=vendor.setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
//An object reference is required for the nonstatic field
//你这段函数是static的???
internal static byte[] GetCommandBytes(Command command)
{
if (command is ApplyPropertyProfileCommand)
{byte[] aa = new byte[36];
ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
if (null != applyPropertyProfileCommand.PropertyProfile)
{
foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
{
bool error = false;
try
{
aa= setAppProperty((AcmeReaderLayer)reader1, property.Key.PropertyName, (string)property.Value);
}
catch (Exception e)
{
throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
}
}
return RfCmd.RfSetFactoryParameter(aa);
}
}
return null;
}处理的函数是这样的
//aa=vendor.setAppProperty((AcmeReaderLayer)reader1, (string)//property.Key.PropertyName, (string)property.Value);还是这个错误:
Error 3 An object reference is required for the nonstatic field, method, or property 'Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.reader1' C:\Documents and Settings\Administrator\Desktop\AcmeReaderProvider\VendorHelper.cs 106 62
=======================
reader1 也要有个实例,类似this.reader1
or
yourclass yc = new yourclass
yc.reader1
因为静态方法没有this实例,无法确定reader1属于哪个具体对象
//or
//yourclass yc = new yourclass
//yc.reader1
//因为静态方法没有this实例,无法确定reader1属于哪个具体对象就是说开始在开始处声明
private AcmeReaderLayer reader1; 这个声明没有用?AcmeReaderLayer reader1 = new AcmeReaderLayer() ;
C# 关键字 | 修饰符
使用 static 修饰符声明属于类型本身而不是属于特定对象的静态成员。static 修饰符可用于字段、方法、属性、运算符、事件和构造函数,但不能用于索引器、析构函数或类型。备注
常数或者类型声明隐式地是静态成员。
不能通过实例引用静态成员。然而,可以通过类型名称引用它。例如,请考虑以下类:
public class MyBaseC
{
public struct MyStruct {
public static int x = 100;
}
}
若要引用静态成员 x,请使用完全限定名(除非可从相同范围访问): MyBaseC.MyStruct.x
尽管类的实例包含该类所有实例字段的单独副本,但每个静态字段只有一个副本。
不可以使用 this 引用静态方法或属性访问器。
注意 static 关键字在使用上比在 C++ 中有更多限制。若要与 C++ 关键字进行比较,请参见 C++ Language Reference 中的 static。
为了说明实例成员,请看一个表示公司雇员的类。假设该类包含一种对雇员计数的方法和一个存储雇员数的字段。该方法和字段都不属于任何实例雇员,而是属于公司类。因此,应该将它们声明为此类的静态成员。有关构造函数的更多信息,请参见 10.10 实例构造函数。示例
该示例读取新雇员的名称和 ID,逐个增加雇员计数器并显示新雇员的有关信息以及新的雇员数。为简单起见,该程序从键盘读取当前的雇员数。在实际的应用中,应从文件读取此信息。// cs_static_keyword.cs
// Static members
using System;
public class Employee
{
public string id;
public string name; public Employee ()
{
} public Employee (string name, string id)
{
this.name = name;
this.id = id;
} public static int employeeCounter; public static int AddEmployee()
{
return ++employeeCounter;
}
}class MainClass: Employee
{
public static void Main()
{
Console.Write("Enter the employee's name: ");
string name = Console.ReadLine();
Console.Write("Enter the employee's ID: ");
string id = Console.ReadLine();
// Create the employee object:
Employee e = new Employee (name, id);
Console.Write("Enter the current number of employees: ");
string n = Console.ReadLine();
Employee.employeeCounter = Int32.Parse(n);
Employee.AddEmployee();
// Display the new information:
Console.WriteLine("Name: {0}", e.name);
Console.WriteLine("ID: {0}", e.id);
Console.WriteLine("New Number of Employees: {0}",
Employee.employeeCounter);
}
}
输入
Tara Strahan
AF643G
15
示例输出
Enter the employee's name: Tara Strahan
Enter the employee's ID: AF643G
Enter the current number of employees: 15
Name: Tara Strahan
ID: AF643G
New Number of Employees: 16
请参见
C# 关键字 | 修饰符--------------------------------------------------------------------------------向 Microsoft 发送有关此主题的反馈© Microsoft Corporation。保留所有权利。
我也是临时做C#的,做MCU DSP 多是刚用C#就做 MS 的BizTalk 中间件,很多基本的东西是不怎么过关啊前面大家给了不少帮助,特别是liujia0421 兄弟现在基本完成了,如果这个问题解决了,再去MS 和他们联调,测试 就ok了望大家能指点一下,很诚恳的向大家学习 谢谢
在AcmeReaderLayer.cs的文件里
internal Response GetResponse(Command command)
{
lock (this)
{
byte[] cmd = VendorHelper.GetCommandBytes(command);
//这里有报错了
//An object reference is required for the nonstatic field, method, or property
if (cmd == null)
{
return null;
}
}
}
byte[] cmd = VendorHelper.GetCommandBytes(command);
//这里有报错了
//An object reference is required for the nonstatic field, method, or property 你这里的VendorHelper是类的名称吧,由于你前面将GetCommandBytes(command)改成成员函数了..所以这里就不能直接"类名.方法名"..try..
VendorHelper vendor=new VendorHelper();
vendor.GetCommandBytes(command);
{
if (command is ApplyPropertyProfileCommand)
{byte[] aa = new byte[36];
ApplyPropertyProfileCommand applyPropertyProfileCommand = (ApplyPropertyProfileCommand)command;
if (null != applyPropertyProfileCommand.PropertyProfile)
{
foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)
{
bool error = false;
try
{
aa= setAppProperty((AcmeReaderLayer)reader1, property.Key.PropertyName, (string)property.Value);
//走不到这里,目前还不知道原因
}
catch (Exception e)
{
throw new ConnectionFailedException("SetProperty to reader failed", e, "", null);
}
}
return RfCmd.RfSetFactoryParameter(aa);
}
}
return null;
}
谢谢两位的关注
if (null != applyPropertyProfileCommand.PropertyProfile)
判断时,applyPropertyProfileCommand.PropertyProfile为空造成的...
if (null != applyPropertyProfileCommand.PropertyProfile)
{
foreach (KeyValuePair<PropertyKey, object> property in applyPropertyProfileCommand.PropertyProfile)//走到这里也
{
bool error = false;
try
{这里就进不来
aa= setAppProperty((AcmeReaderLayer)reader1, property.Key.PropertyName, (string)property.Value);
说白了,对他们的框架也不熟悉
就应该说明 这里不为空啊
看看基础的东西把
当然了,不是说MS 的人不够聪明
总之,有很多方面,是我们不能理解的。
不明白您的 这个说的是什么意思????能具体解析下么? 谢谢你说的对,做完后,也不会搞.net的,不过我还是会再看看的,如果有时间的话
只是因为临时安排的,若招人的话,熟悉我们的产品也不是很容易的事
起码时间上来不及。
送给我们的设备的望能解释下 谢谢