Importing namespaces in a class
Importing namespaces in a class
am 23.01.2008 20:48:57 von Ralph Wiggum
I have an aspx that looks like this:
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Assembly Src="MyClass.cs" %>
....
I'm only using the imported namespace in MyClass.cs, not in the aspx itself. Is it possible to do the import in MyClass.cs, instead of the aspx? I can't figure out the syntax...
Re: Importing namespaces in a class
am 23.01.2008 21:13:44 von David Wier
It's just the basic:
Imports System.Collections.Specialized
And yes, import it only in the class - it will automatically get referenced
in the page, when you instantiate the class.
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Ralph Wiggum" wrote in message
news:_L6dnWCRYMOyBwra4p2dnAA@telenor.com...
>I have an aspx that looks like this:
>
> <%@ Import Namespace="System.Collections.Specialized" %>
> <%@ Assembly Src="MyClass.cs" %>
> ...
>
> I'm only using the imported namespace in MyClass.cs, not in the aspx
> itself. Is it possible to do the import in MyClass.cs, instead of the
> aspx? I can't figure out the syntax...
RE: Importing namespaces in a class
am 23.01.2008 21:35:04 von brucebarker
using System.Collections.Specialized;
-- bruce (sqlwork.com)
"Ralph Wiggum" wrote:
> I have an aspx that looks like this:
>
> <%@ Import Namespace="System.Collections.Specialized" %>
> <%@ Assembly Src="MyClass.cs" %>
> ....
>
> I'm only using the imported namespace in MyClass.cs, not in the aspx itself. Is it possible to do the import in MyClass.cs, instead of the aspx? I can't figure out the syntax...
>
Re: Importing namespaces in a class
am 23.01.2008 21:43:00 von Ralph Wiggum
Ok, thanks. But what if the namespace is defined in a separate file, MyOtherClass.cs and I need to use it in MyClass.cs:
<%@ Import Namespace="NamespaceInMyOtherClass" %>
<%@ Assembly Src="MyClass.cs" %>
<%@ Assembly Src="MyOtherClass.cs" %>
....
How can I tell MyClass.cs to import from MyOtherClass.cs when I remove the first line above?
David Wier wrote:
> It's just the basic:
> Imports System.Collections.Specialized
>
> And yes, import it only in the class - it will automatically get referenced
> in the page, when you instantiate the class.
>
> David Wier
> http://aspnet101.com
> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
> bloated markup
>
>
> "Ralph Wiggum" wrote in message
> news:_L6dnWCRYMOyBwra4p2dnAA@telenor.com...
>> I have an aspx that looks like this:
>>
>> <%@ Import Namespace="System.Collections.Specialized" %>
>> <%@ Assembly Src="MyClass.cs" %>
>> ...
>>
>> I'm only using the imported namespace in MyClass.cs, not in the aspx
>> itself. Is it possible to do the import in MyClass.cs, instead of the
>> aspx? I can't figure out the syntax...
>
>
Re: Importing namespaces in a class
am 23.01.2008 21:53:00 von pbromberg
MyClass should have a reference to MyOtherClass, and a using statement at the
top of its class file in order to use a namespace defined in MyOtherClass.cs
.. You don't need it at the @Page level at all.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Ralph Wiggum" wrote:
> Ok, thanks. But what if the namespace is defined in a separate file, MyOtherClass.cs and I need to use it in MyClass.cs:
>
> <%@ Import Namespace="NamespaceInMyOtherClass" %>
> <%@ Assembly Src="MyClass.cs" %>
> <%@ Assembly Src="MyOtherClass.cs" %>
> ....
>
> How can I tell MyClass.cs to import from MyOtherClass.cs when I remove the first line above?
>
>
> David Wier wrote:
> > It's just the basic:
> > Imports System.Collections.Specialized
> >
> > And yes, import it only in the class - it will automatically get referenced
> > in the page, when you instantiate the class.
> >
> > David Wier
> > http://aspnet101.com
> > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
> > bloated markup
> >
> >
> > "Ralph Wiggum" wrote in message
> > news:_L6dnWCRYMOyBwra4p2dnAA@telenor.com...
> >> I have an aspx that looks like this:
> >>
> >> <%@ Import Namespace="System.Collections.Specialized" %>
> >> <%@ Assembly Src="MyClass.cs" %>
> >> ...
> >>
> >> I'm only using the imported namespace in MyClass.cs, not in the aspx
> >> itself. Is it possible to do the import in MyClass.cs, instead of the
> >> aspx? I can't figure out the syntax...
> >
> >
>
Re: Importing namespaces in a class
am 23.01.2008 22:23:01 von Ralph Wiggum
I'm pretty sure the compiler will complain about "using NamespaceInMyOtherClass;" in the code below. How can I tell MyClass to look in the MyOtherClass.cs file?
aspx:
<%@ Assembly Src="MyClass.cs" %>
<%@ Import Namespace="MyClass" %>
<%
MyClass mc = new MyClass();
%>
MyClass.cs:
namespace MyClass{
public class MyClass{
using NamespaceInMyOtherClass; <-- Problem!
public MyClass(){
MyOtherClass moc = new MyOtherClass();
}
}
}
MyOtherClass.cs:
namespace NamespaceInMyOtherClass{
public class MyOtherClass{
}
}
Peter Bromberg [C# MVP] wrote:
> MyClass should have a reference to MyOtherClass, and a using statement at the
> top of its class file in order to use a namespace defined in MyOtherClass.cs
> . You don't need it at the @Page level at all.
> -- Peter
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> MetaFinder: http://www.blogmetafinder.com
>
>
> "Ralph Wiggum" wrote:
>
>> Ok, thanks. But what if the namespace is defined in a separate file, MyOtherClass.cs and I need to use it in MyClass.cs:
>>
>> <%@ Import Namespace="NamespaceInMyOtherClass" %>
>> <%@ Assembly Src="MyClass.cs" %>
>> <%@ Assembly Src="MyOtherClass.cs" %>
>> ....
>>
>> How can I tell MyClass.cs to import from MyOtherClass.cs when I remove the first line above?
>>
>>
>> David Wier wrote:
>>> It's just the basic:
>>> Imports System.Collections.Specialized
>>>
>>> And yes, import it only in the class - it will automatically get referenced
>>> in the page, when you instantiate the class.
>>>
>>> David Wier
>>> http://aspnet101.com
>>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
>>> bloated markup
>>>
>>>
>>> "Ralph Wiggum" wrote in message
>>> news:_L6dnWCRYMOyBwra4p2dnAA@telenor.com...
>>>> I have an aspx that looks like this:
>>>>
>>>> <%@ Import Namespace="System.Collections.Specialized" %>
>>>> <%@ Assembly Src="MyClass.cs" %>
>>>> ...
>>>>
>>>> I'm only using the imported namespace in MyClass.cs, not in the aspx
>>>> itself. Is it possible to do the import in MyClass.cs, instead of the
>>>> aspx? I can't figure out the syntax...
>>>
Re: Importing namespaces in a class
am 23.01.2008 23:20:46 von David Wier
Put that at the very top of the page, before the Class declaration
David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
"Ralph Wiggum" wrote in message
news:2uidnWsIisuhLQra4p2dnAA@telenor.com...
> I'm pretty sure the compiler will complain about "using
> NamespaceInMyOtherClass;" in the code below. How can I tell MyClass to
> look in the MyOtherClass.cs file?
>
> aspx:
> <%@ Assembly Src="MyClass.cs" %>
> <%@ Import Namespace="MyClass" %>
> <%
> MyClass mc = new MyClass();
> %>
>
> MyClass.cs:
> namespace MyClass{
> public class MyClass{
> using NamespaceInMyOtherClass; <-- Problem!
> public MyClass(){
> MyOtherClass moc = new MyOtherClass();
> }
> }
> }
>
> MyOtherClass.cs:
> namespace NamespaceInMyOtherClass{
> public class MyOtherClass{
>
> }
> }
>
>
>
> Peter Bromberg [C# MVP] wrote:
>> MyClass should have a reference to MyOtherClass, and a using statement at
>> the top of its class file in order to use a namespace defined in
>> MyOtherClass.cs . You don't need it at the @Page level at all.
>> -- Peter
>> Site: http://www.eggheadcafe.com
>> UnBlog: http://petesbloggerama.blogspot.com
>> MetaFinder: http://www.blogmetafinder.com "Ralph Wiggum" wrote:
>>
>>> Ok, thanks. But what if the namespace is defined in a separate file,
>>> MyOtherClass.cs and I need to use it in MyClass.cs:
>>>
>>> <%@ Import Namespace="NamespaceInMyOtherClass" %>
>>> <%@ Assembly Src="MyClass.cs" %>
>>> <%@ Assembly Src="MyOtherClass.cs" %>
>>> ....
>>>
>>> How can I tell MyClass.cs to import from MyOtherClass.cs when I remove
>>> the first line above?
>>>
>>> David Wier wrote:
>>>> It's just the basic:
>>>> Imports System.Collections.Specialized
>>>>
>>>> And yes, import it only in the class - it will automatically get
>>>> referenced in the page, when you instantiate the class.
>>>>
>>>> David Wier
>>>> http://aspnet101.com
>>>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
>>>> with no bloated markup
>>>>
>>>>
>>>> "Ralph Wiggum" wrote in message
>>>> news:_L6dnWCRYMOyBwra4p2dnAA@telenor.com...
>>>>> I have an aspx that looks like this:
>>>>>
>>>>> <%@ Import Namespace="System.Collections.Specialized" %>
>>>>> <%@ Assembly Src="MyClass.cs" %>
>>>>> ...
>>>>>
>>>>> I'm only using the imported namespace in MyClass.cs, not in the aspx
>>>>> itself. Is it possible to do the import in MyClass.cs, instead of the
>>>>> aspx? I can't figure out the syntax...
>>>>
Re: Importing namespaces in a class
am 23.01.2008 23:48:10 von Ralph Wiggum
I'm probably a little slow, but "that" is...?
David Wier wrote:
> Put that at the very top of the page, before the Class declaration
>
> David Wier
> http://aspnet101.com
> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
> bloated markup
>
>
> "Ralph Wiggum" wrote in message
> news:2uidnWsIisuhLQra4p2dnAA@telenor.com...
>> I'm pretty sure the compiler will complain about "using
>> NamespaceInMyOtherClass;" in the code below. How can I tell MyClass to
>> look in the MyOtherClass.cs file?
>>
>> aspx:
>> <%@ Assembly Src="MyClass.cs" %>
>> <%@ Import Namespace="MyClass" %>
>> <%
>> MyClass mc = new MyClass();
>> %>
>>
>> MyClass.cs:
>> namespace MyClass{
>> public class MyClass{
>> using NamespaceInMyOtherClass; <-- Problem!
>> public MyClass(){
>> MyOtherClass moc = new MyOtherClass();
>> }
>> }
>> }
>>
>> MyOtherClass.cs:
>> namespace NamespaceInMyOtherClass{
>> public class MyOtherClass{
>>
>> }
>> }
>>
>>
>>
>> Peter Bromberg [C# MVP] wrote:
>>> MyClass should have a reference to MyOtherClass, and a using statement at
>>> the top of its class file in order to use a namespace defined in
>>> MyOtherClass.cs . You don't need it at the @Page level at all.
>>> -- Peter
>>> Site: http://www.eggheadcafe.com
>>> UnBlog: http://petesbloggerama.blogspot.com
>>> MetaFinder: http://www.blogmetafinder.com "Ralph Wiggum" wrote:
>>>
>>>> Ok, thanks. But what if the namespace is defined in a separate file,
>>>> MyOtherClass.cs and I need to use it in MyClass.cs:
>>>>
>>>> <%@ Import Namespace="NamespaceInMyOtherClass" %>
>>>> <%@ Assembly Src="MyClass.cs" %>
>>>> <%@ Assembly Src="MyOtherClass.cs" %>
>>>> ....
>>>>
>>>> How can I tell MyClass.cs to import from MyOtherClass.cs when I remove
>>>> the first line above?
>>>>
>>>> David Wier wrote:
>>>>> It's just the basic:
>>>>> Imports System.Collections.Specialized
>>>>>
>>>>> And yes, import it only in the class - it will automatically get
>>>>> referenced in the page, when you instantiate the class.
>>>>>
>>>>> David Wier
>>>>> http://aspnet101.com
>>>>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
>>>>> with no bloated markup
>>>>>
>>>>>
>>>>> "Ralph Wiggum" wrote in message
>>>>> news:_L6dnWCRYMOyBwra4p2dnAA@telenor.com...
>>>>>> I have an aspx that looks like this:
>>>>>>
>>>>>> <%@ Import Namespace="System.Collections.Specialized" %>
>>>>>> <%@ Assembly Src="MyClass.cs" %>
>>>>>> ...
>>>>>>
>>>>>> I'm only using the imported namespace in MyClass.cs, not in the aspx
>>>>>> itself. Is it possible to do the import in MyClass.cs, instead of the
>>>>>> aspx? I can't figure out the syntax...
>
>