Source/NFX/RelationalModel/RDBMSCompiler.cs
/// <summary>
/// Turns domain name into domain instance
/// </summary>
Turns domain name into domain instance
Turns domain name into domain instance
protected virtual RDBMSDomain CreateDomain(string sourcePath, string name, IConfigNode node)
            {
               try
               {
                string argsLine = null;
                var iop = name.LastIndexOf('(');
                var icp = name.LastIndexOf(')');
                if (iop>0 && icp>iop)
                {
                  argsLine = name.Substring(iop+1, icp-iop-1);
                  name = name.Substring(0, iop);
                }
                Type dtype = Type.GetType(name, false, true);
                if (dtype==null)
                {
                    var paths = DomainSearchPaths.Split('|', ';');
                    foreach(var path in paths)
                    {
                        var fullName = path.Replace(".*", "." + name);
                        dtype = Type.GetType(fullName, false, true);
                        if (dtype!=null) break;
                    }
                }
                if (dtype==null)
                {
                      m_CompileErrors.Add(new SchemaCompilationException(sourcePath, "Domain type not found in any paths: " + name));
                      return null;
                }
                object[] args = null;
                var ctor = dtype.GetConstructor(Type.EmptyTypes);
                if (argsLine!=null)
                {
                    var argsStrings = argsLine.Split(',');
                    ctor = dtype.GetConstructors().Where(ci => ci.GetParameters().Length==argsStrings.Length).FirstOrDefault();
                    if (ctor==null)
                    {
                      m_CompileErrors.Add(new SchemaCompilationException(sourcePath, "Domain .ctor '{0}' argument mismatch '{1}'".Args(dtype.FullName, argsLine)));
                      return null;
                    }
                    args = new object[ctor.GetParameters().Length];
                    var i = 0;
                    foreach(var pi in ctor.GetParameters())
                    {
                        args[i] = argsStrings[i].Trim().AsType(pi.ParameterType);
                        i++;
                    }
                }
                var result = Activator.CreateInstance(dtype, args) as RDBMSDomain;
                if (node is IConfigSectionNode)
                    result.Configure((IConfigSectionNode)node);
                return result;
               }
               catch(Exception error)
               {
                 m_CompileErrors.Add(new SchemaCompilationException(sourcePath, "Domain '{0}' creation error: {1} ".Args(name, error.ToMessageWithType())));
                 return null;
               }
            }
protected virtual RDBMSDomain CreateDomain ( string sourcePath , string name , IConfigNode node ) { try { string argsLine = null ; var iop = name . LastIndexOf ( ' ' ) ; var icp = name . LastIndexOf ( ' ' ) ; if ( iop > 0 && icp > iop ) { argsLine = name . Substring ( iop + 1 , icp - iop - 1 ) ; name = name . Substring ( 0 , iop ) ; } Type dtype = Type . GetType ( name , false , true ) ; if ( dtype == null ) { var paths = DomainSearchPaths . Split ( ' ' , ' ' ) ; foreach ( var path in paths ) { var fullName = path . Replace ( " " , " " + name ) ; dtype = Type . GetType ( fullName , false , true ) ; if ( dtype != null ) break ; } } if ( dtype == null ) { m_CompileErrors . Add ( new SchemaCompilationException ( sourcePath , " " + name ) ) ; return null ; } object [ ] args = null ; var ctor = dtype . GetConstructor ( Type . EmptyTypes ) ; if ( argsLine != null ) { var argsStrings = argsLine . Split ( ' ' ) ; ctor = dtype . GetConstructors ( ) . Where ( ci => ci . GetParameters ( ) . Length == argsStrings . Length ) . FirstOrDefault ( ) ; if ( ctor == null ) { m_CompileErrors . Add ( new SchemaCompilationException ( sourcePath , " " . Args ( dtype . FullName , argsLine ) ) ) ; return null ; } args = new object [ ctor . GetParameters ( ) . Length ] ; var i = 0 ; foreach ( var pi in ctor . GetParameters ( ) ) { args [ i ] = argsStrings [ i ] . Trim ( ) . AsType ( pi . ParameterType ) ; i ++ ; } } var result = Activator . CreateInstance ( dtype , args ) as RDBMSDomain ; if ( node is IConfigSectionNode ) result . Configure ( ( IConfigSectionNode ) node ) ; return result ; } catch ( Exception error ) { m_CompileErrors . Add ( new SchemaCompilationException ( sourcePath , " " . Args ( name , error . ToMessageWithType ( ) ) ) ) ; return null ; } }
Turns domain name into domain instance
Turns domain name into domain instance
sourcePath
string
name
string
node
IConfigNode