Static method question

  • Thread starter Thread starter jiangyh
  • Start date Start date
J

jiangyh

Hi, everyone.

I have a C# class like following .

public class CommGlaVariantIO : BCCBase
{

private DataSet _dataSetTblSchema = new DataSet();

public void InitAllSchema()
{
DirectoryInfo directoryInfo;

directoryInfo = new DirectoryInfo(WebConfiguration.GetSchemaFilePath);

foreach(FileInfo fileInfo in directoryInfo.GetFiles("*Schema.xsd"))
{
DataSet dsSchema = TblSchemaLib.GetTblSchema(fileInfo.FullName, true);
_dataSetTblSchema.Tables.Add(dsSchema.Tables[0].Copy());
}
}
}

I want at another class to get the _dataSetTblSchema value,who can tell me how to resolve this .

thanks!
jiangyh
 
jiangyh said:
Hi, everyone.

I have a C# class like following .

public class CommGlaVariantIO : BCCBase
{

private DataSet _dataSetTblSchema = new DataSet();

public void InitAllSchema()
{
DirectoryInfo directoryInfo;

directoryInfo = new DirectoryInfo(WebConfiguration.GetSchemaFilePath);

foreach(FileInfo fileInfo in directoryInfo.GetFiles("*Schema.xsd"))
{
DataSet dsSchema = TblSchemaLib.GetTblSchema(fileInfo.FullName, true);
_dataSetTblSchema.Tables.Add(dsSchema.Tables[0].Copy());
}
}
}

I want at another class to get the _dataSetTblSchema value,who can
tell me how to resolve this .

You need to either make _dataSetTblSchema public (which is nasty) or
expose it through a public property or method call. (Internal would
work in both cases too, assuming the other class is in the same
assembly.)
 
hi Jon Skeet [C# MVP]:

thanks you help.but I want get the _dataSetTblSchema value from another
project that they aren't in the same assembly.can u give me some souce to
resolve this.

Jon Skeet said:
jiangyh said:
Hi, everyone.

I have a C# class like following .

public class CommGlaVariantIO : BCCBase
{

private DataSet _dataSetTblSchema = new DataSet();

public void InitAllSchema()
{
DirectoryInfo directoryInfo;

directoryInfo = new DirectoryInfo(WebConfiguration.GetSchemaFilePath);

foreach(FileInfo fileInfo in directoryInfo.GetFiles("*Schema.xsd"))
{
DataSet dsSchema = TblSchemaLib.GetTblSchema(fileInfo.FullName, true);
_dataSetTblSchema.Tables.Add(dsSchema.Tables[0].Copy());
}
}
}

I want at another class to get the _dataSetTblSchema value,who can
tell me how to resolve this .

You need to either make _dataSetTblSchema public (which is nasty) or
expose it through a public property or method call. (Internal would
work in both cases too, assuming the other class is in the same
assembly.)
 
jiangyh said:
thanks you help.but I want get the _dataSetTblSchema value from another
project that they aren't in the same assembly.can u give me some souce to
resolve this.

As I said, add a public property or method. If you can't change the
class, you're stuck - you're not *meant* to be able to get at private
variables.
 
hi Jon Skeet :

I add a property and set the variant _dataSetTblSchema to public.But I want get the variant value without instance the class,when I instance the CommGlaVariantIO class, the variant _dataSetTblSchema value will lose.



public DataSet GetTblSchema
{
get{return _dataSetTblSchema;}
set{_dataSetTblSchema = value;}
}

public DataSet _dataSetTblSchema = new DataSet();
 
Jon said:
As I said, add a public property or method. If you can't change the
class, you're stuck - you're not *meant* to be able to get at private
variables.

Except through reflection :)
But we wont go there.

JB
 
How about passing a reference of the object you want deal with to
InitAllSchema?

Etienne Boucher
 
jiangyh said:
I add a property and set the variant _dataSetTblSchema to public.But
I want get the variant value without instance the class,when I
instance the CommGlaVariantIO class, the variant _dataSetTblSchema
value will lose.

If you don't have an instance there *isnt'* any value for
_dataSetTblSchema.

Either you should make sure you use the same instance at all the
appropriate places, or make the field and the method/property static.
 
thanks Jon Skeet:

I know ,my source must like following

public static string a;
public static string GetA()
{
return a;
}
 
Back
Top