public ITypeContainer CreateNewContainer(object ContainedObject) { if (ContainedObject == null) { return(null); } Type type = ContainedObject.GetType(); ITypeContainer obj = null; #if false var so = SerializeObject(ContainedObject); obj = CreateABinaryContainerGeneric( type, so); #else obj = CreateABinaryContainerGeneric( type, SerializeObject(ContainedObject)); #endif return(obj); }
public Discoverer(ITypeContainer typeContainer, Logger logger) { ArgumentChecker.NotNull(typeContainer, () => typeContainer); _typeContainer = typeContainer; _logger = logger; }
public CreateBuilderSkeleton(ITypeContainer typeContainer, INameResolver resolver, IErrorReport errorReport) { this.typeContainer = typeContainer; this.resolver = resolver; this.errorReport = errorReport; }
// ------------------------------------------------------------------------------- /// <summary> /// Creates a container for this object, if any, and returns the container instance and type. /// </summary> /// <param name="obj"></param> /// <param name="typeManager"></param> /// <param name="containerTypeManager">TypeManager of the container.</param> /// <returns></returns> internal object CreateAContainerIfNecessary( object obj, L3TypeManager typeManager, out L3TypeManager containerTypeManager) { ITypeContainer container = typeManager.l2TypeManager.Container; if (container == null) { containerTypeManager = null; return(null); } var obj2 = container.CreateNewContainer(obj); if (obj2 == null) { typeManager.l2TypeManager.Container = null; // The transcoder of this type is invalid. We do not use this container anymore. containerTypeManager = null; return(obj); } containerTypeManager = l3typeManagerCollection.GetTypeManager(obj2.GetType(), this, true, false); return(obj2); }
public CreateBuilderSkeleton(ITypeContainer typeContainer, INameResolver resolver, IErrorReport errorReport) { this.typeContainer = typeContainer; this.resolver = resolver; this.errorReport = errorReport; }
public ITypeContainer CreateNewContainer(object ContainedObject) { if (ContainedObject == null) { return(null); } Type type = ContainedObject.GetType(); ITypeContainer obj = null; var vs = GetValueSerializerByCache(type); try { { obj = CreateAValueSerializerContainerGeneric(type, vs.ConvertToString(ContainedObject, null)); } } catch (Exception e) { Log.WriteLine(e.Message); } if (obj == null) { Log.WriteLine(string.Format( ErrorMessagesWPF.GetText(2) //"The type '{0}' uses {1} as ValueSerializer, but it was not transcoded correctly. Please investigate or contact the author." , type.FullName, vs.GetType().FullName)); } return(obj); }
public TypeBuilderSkeletonStep(ModuleBuilder modBuilder, ITypeContainer container, INameResolver resolver, IErrorReport errorReport) { this.modBuilder = modBuilder; this.container = container; this.resolver = resolver; this.errorReport = errorReport; }
public EnumNodeWithSymbols( EnumDeclarationSyntax declaration, ITypeContainer container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
public DelegateNodeWithSymbols( DelegateDeclarationSyntax declaration, ITypeContainer container, SemanticModel semanticModel) : base(declaration, container) { this.semanticModel = semanticModel; }
public void RegisterController(ITypeContainer typeContainer) { Assembly .GetAssembly(typeof(Startup)) .GetTypes() .Where(t => t.GetCustomAttribute <RouteAttribute>() != null) .ForEach(t => typeContainer.Register(t, t, InstanceBehaviour.Instance)); }
public TypeBuilderSkeletonStep(ModuleBuilder modBuilder, ITypeContainer container, INameResolver resolver, IErrorReport errorReport) { this.modBuilder = modBuilder; this.container = container; this.resolver = resolver; this.errorReport = errorReport; }
public void GenClassItems(WalkState ws, ITypeContainer parent) { var c = parent.GetClass(ws.Assembly, ws.Namespace, Name, Public); foreach (var s in Statements) { var t = s.GetType(); if (t == typeof(Class)) { (s as Class).GenClassItems(ws, c); } else if (t == typeof(FunctionDef)) { c.Functions.Add(new Function(c, s as FunctionDef, ws)); } else if (t == typeof(PropertySet)) { var ps = s as PropertySet; if (ps.CalcTypeList(ws)) { ExprList el = null; if (ps.Vals != null) { el = ps.Vals as ExprList; if (ps.Props.Count != el.Expressions.Count) { ws.AddError("Mismatched property/value counts: " + ps.Props.Count + " != " + el.Expressions.Count); el = null; } } for (int i = 0; i < ps.Props.Count; i++) { var p = ps.Props[i]; var prop = p.Static ? new Constant(p, ws) : new Field(p, ws); prop.CreateField(c); if (el != null) { object val = el.Expressions[i].Calculate(ws); if (val != null) { prop.SetDefault(p.SystemType.Cast(val, ws)); } // TODO - Do something with default values for fields. } c.Fields.Add(prop); } } } else { ws.AddError("Unknown class statement: " + t); } } }
public void RegisterDatabase(string source, ITypeContainer typeContainer) { var builder = new DbContextOptionsBuilder(); builder.UseSqlite($"Data Source={source}"); var db = new SqliteDatabase(builder.Options); db.Database.EnsureCreated(); //db.Database.Migrate(); typeContainer.Register <IDatabase>(db); }
public ITypeContainer CreateNewContainer(object ContainedObject) { if (ContainedObject == null) { return(null); } Type type = (Type)ContainedObject; ITypeContainer obj = CreateATypeContainerGeneric(type); return(obj); }
public ITypeContainer CreateNewContainer(object ContainedObject) { Type type = ContainedObject.GetType(); ITypeContainer obj = null; obj = CreateABinaryContainerGeneric( type, ContainedObject); return(obj); }
/// <summary> /// Returns a TypeConverterContainer<T>. /// </summary> public ITypeContainer CreateNewContainer(object ContainedObject) { if (ContainedObject == null) { return(null); } Type type = ContainedObject.GetType(); ITypeContainer obj = null; TypeConverter tc = GetTypeConverterByCache(type); try { if (tc.CanConvertTo(TypeString) && tc.CanConvertFrom(TypeString)) { obj = CreateATypeConverterContainerGeneric(type, TypeString, tc.ConvertTo(null, Tools.EnUSCulture, ContainedObject, TypeString)); if (obj != null) { var o2 = obj as _CLRTypeConverterContainerGeneric <string>; if (o2.Serialized == null || o2.Serialized == type.FullName) { Log.WriteLine(string.Format( ErrorMessages.GetText(15) //"The type '{0}' uses {1} as TypeConverter, but it does not convert to string correctly. Please investigate or contact the type's author." , type.FullName, tc.GetType().FullName)); return(null); } } } else if (tc.CanConvertTo(TypeByteArray) && tc.CanConvertFrom(TypeByteArray)) { obj = CreateATypeConverterContainerGeneric(type, TypeByteArray, tc.ConvertTo(null, Tools.EnUSCulture, ContainedObject, TypeByteArray)); } } catch (Exception e) { Log.WriteLine(e.Message); } if (obj == null) { Log.WriteLine(string.Format( ErrorMessages.GetText(16) //"The type '{0}' uses {1} as TypeConverter, but its transcoding type is unknown. Please investigate or contact the type's author." , type.FullName, tc.GetType().FullName)); } return(obj); }
private static void Register(ITypeContainer typeContainer) { typeContainer.Register <Settings>(InstanceBehaviour.Singleton); typeContainer.Register <ISettings, Settings>(InstanceBehaviour.Singleton); typeContainer.Register <ExtensionLoader>(InstanceBehaviour.Singleton); typeContainer.Register <IExtensionLoader, ExtensionLoader>(InstanceBehaviour.Singleton); typeContainer.Register <IExtensionResolver, ExtensionLoader>(InstanceBehaviour.Singleton); typeContainer.Register <DefinitionManager>(InstanceBehaviour.Singleton); typeContainer.Register <IDefinitionManager, DefinitionManager>(InstanceBehaviour.Singleton); typeContainer.Register <ContainerResourceManager>(InstanceBehaviour.Singleton); typeContainer.Register <IResourceManager, ContainerResourceManager>(InstanceBehaviour.Singleton); typeContainer.Register <GameService>(InstanceBehaviour.Singleton); typeContainer.Register <IGameService, GameService>(InstanceBehaviour.Singleton); typeContainer.Register <UpdateHub>(InstanceBehaviour.Singleton); typeContainer.Register <IUpdateHub, UpdateHub>(InstanceBehaviour.Singleton); }
public Type Resolve(TypeReference type, GenericBindingContext bindingContext) { ITypeContainer container = _moduleResolver.Resolve(type.Scope); GenericInstanceType genericInstanceType = type as GenericInstanceType; if (genericInstanceType != null) { Type genericType = Resolve(genericInstanceType.Resolve()); Type[] genericArguments = genericInstanceType.GenericArguments .Select(bindingContext.Resolve) .Select(argument => Resolve(argument, bindingContext)).ToArray(); return(genericType.MakeGenericType(genericArguments)); } return(container.GetType(type.FullName)); }
public void GenTypes(WalkState ws, ITypeContainer parent) { if (!string.IsNullOrEmpty(ws.Namespace)) { var c = parent.GetClass(ws.Assembly, ws.Namespace, Name, Public); foreach(var s in Statements) { var t = s.GetType(); if (t == typeof(Class)) { (s as Class).GenTypes(ws, c); } } } else { ws.AddError("No namespace specified for class " + Name); } }
public static void Register(ITypeContainer typeContainer) { typeContainer.Register <GlobalChunkCache, GlobalChunkCache>(InstanceBehaviour.Instance); typeContainer.Register <IGlobalChunkCache, GlobalChunkCache>(InstanceBehaviour.Instance); typeContainer.Register <Logging.NullLogger, Logging.NullLogger>(); typeContainer.Register <Logging.Logger, Logging.Logger>(); typeContainer.Register <Logging.ILogger, Logging.Logger>(); typeContainer.Register <IPool <Awaiter>, Pool <Awaiter> >(InstanceBehaviour.Singleton); typeContainer.Register <Pool <Awaiter>, Pool <Awaiter> >(InstanceBehaviour.Singleton); typeContainer.Register <IPool <BlockChangedNotification>, Pool <BlockChangedNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <Pool <BlockChangedNotification>, Pool <BlockChangedNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <IPool <BlocksChangedNotification>, Pool <BlocksChangedNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <Pool <BlocksChangedNotification>, Pool <BlocksChangedNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <IPool <EntityNotification>, Pool <EntityNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <Pool <EntityNotification>, Pool <EntityNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <IPool <PropertyChangedNotification>, Pool <PropertyChangedNotification> >(InstanceBehaviour.Singleton); typeContainer.Register <Pool <PropertyChangedNotification>, Pool <PropertyChangedNotification> >(InstanceBehaviour.Singleton); }
public static void AddChildTypes(this ITypeContainer parent, MemberDeclarationSyntax s, SortedSet <ClassInfo> classes = null, SortedSet <StructInfo> structs = null, SortedSet <InterfaceInfo> interfaces = null, SortedSet <EnumInfo> enums = null) { // ugly but works switch (s) { case ClassDeclarationSyntax decl: new ClassInfo(decl, parent).AddOrReuse(decl, classes); break; case EnumDeclarationSyntax decl: enums?.Add(new EnumInfo(decl, parent)); break; case StructDeclarationSyntax decl: new StructInfo(decl, parent).AddOrReuse(decl, structs); break; case InterfaceDeclarationSyntax decl: new InterfaceInfo(decl, parent).AddOrReuse(decl, interfaces); break; } }
public static void ToDirectory(ITypeContainer asm, string lang, string dir) { string format = string.Format("lang = {0}; mode = full", lang); Directory.CreateDirectory(dir); foreach (var type in asm.Types) { if (CanWrite(type)) { string text = type.ToString(format, null); string typeDir = dir; string ns = type.Namespace; if (!string.IsNullOrEmpty(ns)) { typeDir = Path.Combine(dir, ns); Directory.CreateDirectory(typeDir); } string path = Path.Combine(typeDir, MakeValidPath(type.Name) + ".cs"); File.WriteAllText(path, text); } } }
static TypeContainer() { instance = new StandaloneTypeContainer(); instance.Register(instance as StandaloneTypeContainer); instance.Register <ITypeContainer, StandaloneTypeContainer>(instance); }
internal static Tuple parent_namespace(ITypeContainer child, INamespace parent) => new Tuple("parent_namespace", child, parent);
internal static Tuple cil_type_parameter(ITypeContainer unboundTypeOrMethod, int index, ITypeParameter parameter) => new Tuple("cil_type_parameter", unboundTypeOrMethod, index, parameter);
internal static Tuple cil_type_argument(ITypeContainer constructedTypeOrMethod, int index, IType argument) => new Tuple("cil_type_argument", constructedTypeOrMethod, index, argument);
internal static Tuple cil_type(IType t, string name, CilTypeKind kind, ITypeContainer parent, IType sourceDecl) => new Tuple("cil_type", t, name, (int)kind, parent, sourceDecl);
/// <summary> /// Register the types to DI container. /// </summary> /// <param name="container"></param> internal protected virtual void RegisterTypes(ITypeContainer container) { }
/// <summary> /// Register all modules /// </summary> public static void RegisterModules(RouteCollection routes, ITypeContainer container) { var typeSearcher = TypeSearcher.Instance(); var moduleTypes = typeSearcher.SearchTypesByBaseType(typeof(IModule)); Modules = new Dictionary<string, ModuleDescriptor>(); foreach (var moduleType in moduleTypes) { if (moduleType.IsAbstract) continue; var module = (IModule)Activator.CreateInstance(moduleType); if (module != null && string.IsNullOrEmpty(module.Name)) continue; if (Modules.ContainsKey(module.Name)) continue; var _asmName = moduleType.Assembly.GetName(); var moduleDescriptor = new ModuleDescriptor() { Name = module.Name, AssemblyQualifiedName = moduleType.AssemblyQualifiedName, AssemblyFullName = _asmName.FullName, AssemblyName = _asmName.Name }; moduleDescriptor.LoadAssemblyInfo(); ServiceModule serviceModule = module as ServiceModule; if (serviceModule != null) { serviceModule.RegisterTypes(container); serviceModule.RegisterRoutes(RouteTable.Routes); } SolutionModule solutionModule = module as SolutionModule; if (solutionModule != null && !solutionModule.DisableAutoRoutesRegistration) { #region Auto route generation var routeName = string.Format("solution_{0}", module.Name); var additional_ns = solutionModule.GetNamespaces(); var ns = new List<string>(); ns.Add(moduleType.Namespace); if (additional_ns != null && additional_ns.Length > 0) ns.AddRange(additional_ns); if (routes[routeName] == null) { moduleDescriptor.RouteName = routeName; var ctrls = moduleType.Assembly.GetTypes().Where(t => t.BaseType != null && t.BaseType.Equals(typeof(Controller))).ToList(); if (ctrls.Count > 0) { var hostDashboardType = Type.GetType("DNA.Web.HostDashboardAttribute,DNA.Web.ServiceModel"); var myDashboardType = Type.GetType("DNA.Web.MyDashboardAttribute,DNA.Web.ServiceModel"); foreach (var ctrl in ctrls) { var dashboardMethods = ctrl.GetMethods().Where(m => m.IsDefined(hostDashboardType, false)); var myDashboards = ctrl.GetMethods().Where(m => m.IsDefined(myDashboardType, false)); foreach (var m in dashboardMethods) { var ctrlName = ctrl.Name.Replace("Controller", ""); var dashboardRouteName = "host_module_" + module.Name + "_" + ctrlName + "_" + m.Name; if (RouteTable.Routes[dashboardRouteName] == null) routes.MapRoute(dashboardRouteName, "{host}/{solution}/{controller}/{action}/{id}", new { id = UrlParameter.Optional }, new { host = "host", solution = module.Name, controller = ctrlName, action = m.Name }); } foreach (var m in myDashboards) { var ctrlName = ctrl.Name.Replace("Controller", ""); var myRouteName = "mysite_" + module.Name + "_" + ctrlName + "_" + m.Name; if (RouteTable.Routes[myRouteName] == null) routes.MapRoute(myRouteName, "{mysite}/{solution}/{controller}/{action}/{id}", new { id = UrlParameter.Optional }, new { mysite = "mysite", solution = module.Name, controller = ctrlName, action = m.Name }); } } if (RouteTable.Routes[routeName] == null) routes.MapRoute(routeName, "{website}/{locale}/{solution}/{controller}/{action}/{id}", new { action = "index", id = UrlParameter.Optional }, new { solution = module.Name, locale = @"([a-z]{2})-([a-z]{2}|[A-Z]{2})" }); } } #endregion } Modules.Add(module.Name, moduleDescriptor); } container.Apply(); }
public DefaultNameResolver(ITypeContainer typeContainer) { this.typeContainer = typeContainer; }
/// <summary> /// Register the types to DI container. /// </summary> /// <param name="container"></param> protected internal virtual void RegisterTypes(ITypeContainer container) { }
public static T Construct <T>(this ITypeContainer container) { return(Constructor.Construct <T>()); }
public Discoverer(ITypeContainer typeContainer) : this(typeContainer, null) { }
public static void Register(ITypeContainer typeContainer) { typeContainer.Register <PackagePool, PackagePool>(InstanceBehaviour.Singleton); }
public static void Register(ITypeContainer typeContainer) { typeContainer.Register <IDbProvider, SqliteDatabaseProvider>(); }
/// <summary> /// Register all modules /// </summary> public static void RegisterModules(RouteCollection routes, ITypeContainer container) { var typeSearcher = TypeSearcher.Instance(); var moduleTypes = typeSearcher.SearchTypesByBaseType(typeof(IModule)); Modules = new Dictionary <string, ModuleDescriptor>(); foreach (var moduleType in moduleTypes) { if (moduleType.IsAbstract) { continue; } var module = (IModule)Activator.CreateInstance(moduleType); if (module != null && string.IsNullOrEmpty(module.Name)) { continue; } if (Modules.ContainsKey(module.Name)) { continue; } var _asmName = moduleType.Assembly.GetName(); var moduleDescriptor = new ModuleDescriptor() { Name = module.Name, AssemblyQualifiedName = moduleType.AssemblyQualifiedName, AssemblyFullName = _asmName.FullName, AssemblyName = _asmName.Name }; moduleDescriptor.LoadAssemblyInfo(); ServiceModule serviceModule = module as ServiceModule; if (serviceModule != null) { serviceModule.RegisterTypes(container); serviceModule.RegisterRoutes(RouteTable.Routes); } SolutionModule solutionModule = module as SolutionModule; if (solutionModule != null && !solutionModule.DisableAutoRoutesRegistration) { #region Auto route generation var routeName = string.Format("solution_{0}", module.Name); var additional_ns = solutionModule.GetNamespaces(); var ns = new List <string>(); ns.Add(moduleType.Namespace); if (additional_ns != null && additional_ns.Length > 0) { ns.AddRange(additional_ns); } if (routes[routeName] == null) { moduleDescriptor.RouteName = routeName; var ctrls = moduleType.Assembly.GetTypes().Where(t => t.BaseType != null && t.BaseType.Equals(typeof(Controller))).ToList(); if (ctrls.Count > 0) { var hostDashboardType = Type.GetType("DNA.Web.HostDashboardAttribute,DNA.Web.ServiceModel"); var myDashboardType = Type.GetType("DNA.Web.MyDashboardAttribute,DNA.Web.ServiceModel"); foreach (var ctrl in ctrls) { var dashboardMethods = ctrl.GetMethods().Where(m => m.IsDefined(hostDashboardType, false)); var myDashboards = ctrl.GetMethods().Where(m => m.IsDefined(myDashboardType, false)); foreach (var m in dashboardMethods) { var ctrlName = ctrl.Name.Replace("Controller", ""); var dashboardRouteName = "host_module_" + module.Name + "_" + ctrlName + "_" + m.Name; if (RouteTable.Routes[dashboardRouteName] == null) { routes.MapRoute(dashboardRouteName, "{host}/{solution}/{controller}/{action}/{id}", new { id = UrlParameter.Optional }, new { host = "host", solution = module.Name, controller = ctrlName, action = m.Name }); } } foreach (var m in myDashboards) { var ctrlName = ctrl.Name.Replace("Controller", ""); var myRouteName = "mysite_" + module.Name + "_" + ctrlName + "_" + m.Name; if (RouteTable.Routes[myRouteName] == null) { routes.MapRoute(myRouteName, "{mysite}/{solution}/{controller}/{action}/{id}", new { id = UrlParameter.Optional }, new { mysite = "mysite", solution = module.Name, controller = ctrlName, action = m.Name }); } } } if (RouteTable.Routes[routeName] == null) { routes.MapRoute(routeName, "{website}/{locale}/{solution}/{controller}/{action}/{id}", new { action = "index", id = UrlParameter.Optional }, new { solution = module.Name, locale = @"([a-z]{2})-([a-z]{2}|[A-Z]{2})" }); } } } #endregion } Modules.Add(module.Name, moduleDescriptor); } container.Apply(); }
public OctoGame() : base() { //graphics = new GraphicsDeviceManager(this); //graphics.PreferredBackBufferWidth = 1080; //graphics.PreferredBackBufferHeight = 720; //Content.RootDirectory = "Content"; Title = "OctoAwesome"; IsMouseVisible = true; Icon = Properties.Resources.octoawesome; typeContainer = TypeContainer.Get <ITypeContainer>(); Register(typeContainer); //Window.AllowUserResizing = true; Settings = TypeContainer.Get <Settings>(); ExtensionLoader = TypeContainer.Get <ExtensionLoader>(); ExtensionLoader.LoadExtensions(); Service = TypeContainer.Get <GameService>(); //TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 15); int width = Settings.Get("Width", 1080); int height = Settings.Get("Height", 720); Window.ClientSize = new Size(width, height); Window.Fullscreen = Settings.Get("EnableFullscreen", false); if (Settings.KeyExists("Viewrange")) { var viewrange = Settings.Get <int>("Viewrange"); if (viewrange < 1) { throw new NotSupportedException("Viewrange in app.config darf nicht kleiner 1 sein"); } SceneControl.VIEWRANGE = viewrange; } Assets = new AssetComponent(this); Components.Add(Assets); Screen = new ScreenComponent(this); Screen.UpdateOrder = 1; Screen.DrawOrder = 1; Components.Add(Screen); KeyMapper = new KeyMapper(Screen, Settings); #region GameComponents DefinitionManager = TypeContainer.Get <DefinitionManager>(); //var persistenceManager = new DiskPersistenceManager(ExtensionLoader, DefinitionManager, Settings); //ResourceManager = new ResourceManager(ExtensionLoader, DefinitionManager, Settings, persistenceManager); ResourceManager = TypeContainer.Get <ContainerResourceManager>(); Player = new PlayerComponent(this, ResourceManager); Player.UpdateOrder = 2; Components.Add(Player); Simulation = new Components.SimulationComponent(this, ExtensionLoader, ResourceManager); Entity = new Components.EntityComponent(this, Simulation); Entity.UpdateOrder = 2; Components.Add(Entity); Camera = new CameraComponent(this); Camera.UpdateOrder = 3; Components.Add(Camera); Simulation.UpdateOrder = 4; Components.Add(Simulation); #endregion GameComponents /*Resize += (s, e) => * { * //if (Window.ClientBounds.Height == graphics.PreferredBackBufferHeight && * // Window.ClientBounds.Width == graphics.PreferredBackBufferWidth) * // return; * * //graphics.PreferredBackBufferHeight = Window.ClientBounds.Height; * //graphics.PreferredBackBufferWidth = Window.ClientBounds.Width; * //graphics.ApplyChanges(); * };*/ SetKeyBindings(); }