Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Store Type in field/variable
- public class Logger
- {
- public static Type Writer;
- public static void SetWriter(Type @new)
- {
- Writer = @new;
- }
- public static void Write(string str)
- {
- Writer.Write(str);
- }
- }
- Writer.Write(str);
- public interface IWriter
- {
- public Write(string text);
- }
- public class Logger
- {
- public static IWriter Writer;
- public static void SetWriter(IWriter newWriter)
- {
- Writer = newWriter;
- }
- public static void Write(string str)
- {
- Writer.Write(str);
- }
- }
- public class MyWriter : IWriter
- {
- public void Write(string text)
- {
- // Do something to "write" text
- }
- }
- Logger.SetWriter(new MyWriter());
- Type variableName = typeof(SomeTypeName);
- Type variableName = someObject.GetType();
- public class Logger
- {
- public Logger(TextWriter writer)
- {
- _writer = writer;
- }
- private TextWriter _writer;
- public void Write(string text)
- {
- _writer.Write(text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment