Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Product Architecture
Message
De
08/02/2009 20:29:42
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
08/02/2009 18:18:07
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
ASP.NET
Divers
Thread ID:
01379573
Message ID:
01380201
Vues:
41
>I just started my new job this week and they are throwing me into the fire right away, which is good. It's challenging learning a new company culture, a new language (C#), and new features such as this.
>
>I think you'll like C# ... I know I do. =0)
>
>~~Bonnie

I am enjoying it so far. Using "new" instead of "New" is killing me though when instantiating an object.

>
>
>>>>That will help a ton! I got about 3/4ths of the way there. This and John's suggestion should hopefully nudge me the rest of the way.
>>>
>>>Cool! Have fun! =0)
>>>
>>>~~Bonnie
>>
>>Thanks, I will. I just started my new job this week and they are throwing me into the fire right away, which is good. It's challenging learning a new company culture, a new language (C#), and new features such as this. Oh well, no rest for the wicked.
>>
>>>>
>>>>>Hi Mike,
>>>>>
>>>>>I've posted this before, but I didn't bother searching for the post. Here's a repeat:
>>>>>
>>>>>Below is a simplified version of my Reflection class (other things could be added to it, for example allowing parameters to be passed).
>>>>>
>>>>>It's easy to use too. Here's one way to use it:
>>>>>
>>>>>MyReflectionClass oReflection = new MyReflectionClass(assembly, classname);
>>>>>string message = "";
>>>>>object o = oReflection.InstantiateClass(ref message);
>>>>>if (message != "")
>>>>>	MessageBox.Show(message);
>>>>>else
>>>>>{
>>>>>	// go on with your processing
>>>>>}
>>>>>
>>>>>
>>>>>And here's the simplified class:
>>>>>
>>>>>
>>>>>public class MyReflectionClass
>>>>>{
>>>>>	#region Declarations
>>>>>	private string m_AssemblyName;
>>>>>	private string m_ClassName;
>>>>>	#endregion
>>>>>
>>>>>	#region Constructors
>>>>>	public MyReflectionClass()
>>>>>	{
>>>>>	}
>>>>>	public MyReflectionClass(string assemblyName, string className)
>>>>>	{
>>>>>		this.AssemblyName = assemblyName;
>>>>>		this.ClassName = className;
>>>>>	}
>>>>>	#endregion
>>>>>
>>>>>	#region Methods
>>>>>
>>>>>	public Assembly LoadAssembly(ref string Message)
>>>>>	{
>>>>>		Assembly oAssembly = null;
>>>>>
>>>>>		try
>>>>>		{
>>>>>			oAssembly = Assembly.LoadFrom(this.m_AssemblyName + ".DLL");
>>>>>		}
>>>>>		catch (System.IO.FileNotFoundException)
>>>>>		{
>>>>>			Message = this.m_AssemblyName + " could not be found at the specified URL!" + (char)13 + (char)13 +
>>>>>				"Check that you have correctly entered the component URL and that your network or Internet " +
>>>>>				"connection is functioning correctly.";
>>>>>			return oAssembly;
>>>>>		}
>>>>>		catch (System.BadImageFormatException)
>>>>>		{
>>>>>			Message = this.m_AssemblyName + " is invalid or damaged!" + (char)13 + (char)13 +
>>>>>				"Contact your system administrator.";
>>>>>			return oAssembly;
>>>>>		}
>>>>>		catch (System.Exception ex)
>>>>>		{
>>>>>			Message = ex.Message;
>>>>>			return oAssembly;
>>>>>		}
>>>>>
>>>>>		return oAssembly;
>>>>>	}
>>>>>
>>>>>	public object InstantiateClass(ref string Message)
>>>>>	{
>>>>>		Assembly oAssembly = null;
>>>>>		return this.InstantiateClass(ref oAssembly, ref Message);
>>>>>	}
>>>>>	public object InstantiateClass(ref Assembly oAssembly, ref string Message)
>>>>>	{
>>>>>		object oClass = null;
>>>>>		if (oAssembly == null || oAssembly.FullName.Contains(this.m_AssemblyName) == false)
>>>>>			oAssembly = this.LoadAssembly(ref Message);
>>>>>
>>>>>		try
>>>>>		{
>>>>>			// Create an instance of the desired type from the assembly
>>>>>			if (oAssembly != null)
>>>>>				oClass = oAssembly.CreateInstance(this.m_ClassName);
>>>>>		}
>>>>>		catch (Exception ex)
>>>>>		{
>>>>>			Message = ex.Message;
>>>>>			return oClass;
>>>>>		}
>>>>>
>>>>>		return oClass;
>>>>>	}
>>>>>
>>>>>	#endregion
>>>>>
>>>>>	#region Properties
>>>>>	public string AssemblyName
>>>>>	{
>>>>>		get { return this.m_AssemblyName; }
>>>>>		set
>>>>>		{
>>>>>			this.m_AssemblyName = value.Trim();
>>>>>			if (this.m_AssemblyName.ToUpper().EndsWith(".DLL", true, null))
>>>>>				this.m_AssemblyName = this.m_AssemblyName.Remove(this.m_AssemblyName.Length - 4);
>>>>>		}
>>>>>	}
>>>>>	public string ClassName
>>>>>	{
>>>>>		get { return this.m_ClassName; }
>>>>>		set 
>>>>>		{ 
>>>>>			this.m_ClassName = value.Trim(); 
>>>>>			if (this.m_ClassName.Contains(this.m_AssemblyName) == false)
>>>>>				this.m_ClassName = this.m_AssemblyName + "." + this.m_ClassName;
>>>>>		}
>>>>>	}
>>>>>	#endregion
>>>>>}
>>>>>
>>>>>
>>>>>~~Bonnie
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform