Resources in ResX files and Inheritance ? 
Author Message
 Resources in ResX files and Inheritance ?

I have a component that stores some resources in its resX file.

I work with the resources using the following code:
ResourceManager rm = new ResourceManager( GetType() ) ;

Bitmap closedfolder = (Bitmap) rm.GetObject("ResourceName") ;

When I inherit from this component, the child component produces a run-time
error when it tries to run this code. ( i.e. this code does not work when it
is the parent of a control )

I can work around this problem by moving these resources from the parent's
resX file to the child's resx file - but this seems like a bit of a kludge.
What am I missing ?

Thanks,

Dan



Sun, 31 Oct 2004 23:55:30 GMT  
 Resources in ResX files and Inheritance ?
Dan,

    I would replace the call with the following:

// Get the resource manager for the base class.
ResourceManager rm = new ResourceManager(typeof(MyBaseClass));

    This way, you are always getting the resources that are associated with
the base class type and not the derived type (which the call to GetType was
doing).

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> I have a component that stores some resources in its resX file.

> I work with the resources using the following code:
> ResourceManager rm = new ResourceManager( GetType() ) ;

> Bitmap closedfolder = (Bitmap) rm.GetObject("ResourceName") ;

> When I inherit from this component, the child component produces a
run-time
> error when it tries to run this code. ( i.e. this code does not work when
it
> is the parent of a control )

> I can work around this problem by moving these resources from the parent's
> resX file to the child's resx file - but this seems like a bit of a
kludge.
> What am I missing ?

> Thanks,

> Dan



Mon, 01 Nov 2004 00:43:19 GMT  
 Resources in ResX files and Inheritance ?
This code creating the ResourceManager is in the parent class.

In a true inhertiance model, these resources should be totally transparent
to my child class. I do not understand why I should change the way that I am
doing resource management if another class is inheriting from this class.

I get the runtime error regarding resources in the parent class - although
the class works just fine if it is not the parent of a class.

Dan



Quote:
> Dan,

>     I would replace the call with the following:

> // Get the resource manager for the base class.
> ResourceManager rm = new ResourceManager(typeof(MyBaseClass));

>     This way, you are always getting the resources that are associated
with
> the base class type and not the derived type (which the call to GetType
was
> doing).

>     Hope this helps.

> --
>                - Nicholas Paldino [.NET MVP]



> > I have a component that stores some resources in its resX file.

> > I work with the resources using the following code:
> > ResourceManager rm = new ResourceManager( GetType() ) ;

> > Bitmap closedfolder = (Bitmap) rm.GetObject("ResourceName") ;

> > When I inherit from this component, the child component produces a
> run-time
> > error when it tries to run this code. ( i.e. this code does not work
when
> it
> > is the parent of a control )

> > I can work around this problem by moving these resources from the
parent's
> > resX file to the child's resx file - but this seems like a bit of a
> kludge.
> > What am I missing ?

> > Thanks,

> > Dan



Mon, 01 Nov 2004 01:55:15 GMT  
 Resources in ResX files and Inheritance ?
Dan,

    You are right, resources should be totally transparent to your child
class.  However, you make the link between the type of the class accessing
the resource when you pass the result of the GetType to the resource
manager.  My suggestion to you is that you use typeof, passing in the name
of the parent (or base class).  This way, your derived types, when accessing
the resource manager, will always be using the type of the base class, and
therefore will always access the resource in the base class' assembly, not
in the child class' assembly.

    You don't have to change the way you are doing resource management, you
are doing just fine, but you are passing the wrong parameter to the resource
manager when trying to tell it where to look for resources that the base
type uses.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> This code creating the ResourceManager is in the parent class.

> In a true inhertiance model, these resources should be totally transparent
> to my child class. I do not understand why I should change the way that I
am
> doing resource management if another class is inheriting from this class.

> I get the runtime error regarding resources in the parent class - although
> the class works just fine if it is not the parent of a class.

> Dan


wrote

> > Dan,

> >     I would replace the call with the following:

> > // Get the resource manager for the base class.
> > ResourceManager rm = new ResourceManager(typeof(MyBaseClass));

> >     This way, you are always getting the resources that are associated
> with
> > the base class type and not the derived type (which the call to GetType
> was
> > doing).

> >     Hope this helps.

> > --
> >                - Nicholas Paldino [.NET MVP]



> > > I have a component that stores some resources in its resX file.

> > > I work with the resources using the following code:
> > > ResourceManager rm = new ResourceManager( GetType() ) ;

> > > Bitmap closedfolder = (Bitmap) rm.GetObject("ResourceName") ;

> > > When I inherit from this component, the child component produces a
> > run-time
> > > error when it tries to run this code. ( i.e. this code does not work
> when
> > it
> > > is the parent of a control )

> > > I can work around this problem by moving these resources from the
> parent's
> > > resX file to the child's resx file - but this seems like a bit of a
> > kludge.
> > > What am I missing ?

> > > Thanks,

> > > Dan



Mon, 01 Nov 2004 02:07:21 GMT  
 Resources in ResX files and Inheritance ?
Nick,

OK. Now I understand the issues and my code works correctly.

Thanks for your help.

Dan



Quote:
> Dan,

>     You are right, resources should be totally transparent to your child
> class.  However, you make the link between the type of the class accessing
> the resource when you pass the result of the GetType to the resource
> manager.  My suggestion to you is that you use typeof, passing in the name
> of the parent (or base class).  This way, your derived types, when
accessing
> the resource manager, will always be using the type of the base class, and
> therefore will always access the resource in the base class' assembly, not
> in the child class' assembly.

>     You don't have to change the way you are doing resource management,
you
> are doing just fine, but you are passing the wrong parameter to the
resource
> manager when trying to tell it where to look for resources that the base
> type uses.

> --
>                - Nicholas Paldino [.NET MVP]



> > This code creating the ResourceManager is in the parent class.

> > In a true inhertiance model, these resources should be totally
transparent
> > to my child class. I do not understand why I should change the way that
I
> am
> > doing resource management if another class is inheriting from this
class.

> > I get the runtime error regarding resources in the parent class -
although
> > the class works just fine if it is not the parent of a class.

> > Dan


> wrote

> > > Dan,

> > >     I would replace the call with the following:

> > > // Get the resource manager for the base class.
> > > ResourceManager rm = new ResourceManager(typeof(MyBaseClass));

> > >     This way, you are always getting the resources that are associated
> > with
> > > the base class type and not the derived type (which the call to
GetType
> > was
> > > doing).

> > >     Hope this helps.

> > > --
> > >                - Nicholas Paldino [.NET MVP]



> > > > I have a component that stores some resources in its resX file.

> > > > I work with the resources using the following code:
> > > > ResourceManager rm = new ResourceManager( GetType() ) ;

> > > > Bitmap closedfolder = (Bitmap) rm.GetObject("ResourceName") ;

> > > > When I inherit from this component, the child component produces a
> > > run-time
> > > > error when it tries to run this code. ( i.e. this code does not work
> > when
> > > it
> > > > is the parent of a control )

> > > > I can work around this problem by moving these resources from the
> > parent's
> > > > resX file to the child's resx file - but this seems like a bit of a
> > > kludge.
> > > > What am I missing ?

> > > > Thanks,

> > > > Dan



Mon, 01 Nov 2004 02:45:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Compressing a Resource Files (.resx)

2. .resource = .resx files?

3. Looping through resx resource files ?

4. Cool Resources Editor/Viewer for .NET + sourcecode (.resources/.resX)

5. Adding Bitmaps to Resources (.resx)

6. whu should i use (resx) resources?

7. resx files needed for cs - files ??

8. resx-files in vc++.net 2002

9. invalid resx file when recompiling

10. Getting Access to the resx file?

11. Adding Bitmaps to resx files.

12. How can read the colum data to file resx

 

 
Powered by phpBB® Forum Software