Exemplo n.º 1
0
    public static void Main(string[] args)
    {
        ConstructorParam c1 = new ConstructorParam(101, "singh", 22);
        ConstructorParam c2 = new ConstructorParam(102, "ram", 23);

        c1.display();
        c2.display();
    }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if a constructor matches the set of properties, and initialised data about the constructor parameters at the same time.
        /// </summary>
        /// <param name="constructor">Constructor to test.</param>
        /// <param name="properties">Properties to match against.</param>
        /// <returns>Constructor parameter info, or <c>null</c> if no match.</returns>
        private static ConstructorParam[] MatchConstructor(ConstructorInfo constructor, TypeData.PropertyData[] properties)
        {
            ParameterInfo[] parameters = constructor.GetParameters();
            if (parameters.Length != properties.Length)
            {
                return(null);
            }

            var result = new ConstructorParam[parameters.Length];

            foreach (var prop in properties)
            {
                string name = prop.Name.ToLower();      // We don't care about case

                // Not worth doing hashtable-type things, a simple scan is probably faster
                bool found = false;
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i].Name.ToLower() == name && parameters[i].ParameterType == prop.Type)
                    {
                        // Match
                        found     = true;
                        result[i] = new ConstructorParam {
                            LowerName = parameters[i].Name.ToLower(), Kind = prop.Kind, TypeData = prop.TypeData
                        };
                        break;
                    }
                }

                if (!found)
                {
                    return(null);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if a constructor matches the set of properties, and initialised data about the constructor parameters at the same time.
        /// </summary>
        /// <param name="constructor">Constructor to test.</param>
        /// <param name="properties">Properties to match against.</param>
        /// <returns>Constructor parameter info, or <c>null</c> if no match.</returns>
        private static ConstructorParam[] MatchConstructor(ConstructorInfo constructor, TypeData.PropertyData[] properties)
        {
            ParameterInfo[] parameters = constructor.GetParameters();
            if (parameters.Length != properties.Length)
                return null;

            var result = new ConstructorParam[parameters.Length];

            foreach (var prop in properties)
            {
                string name = prop.Name.ToLower();      // We don't care about case

                // Not worth doing hashtable-type things, a simple scan is probably faster
                bool found = false;
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (parameters[i].Name.ToLower() == name && parameters[i].ParameterType == prop.Type)
                    {
                        // Match
                        found = true;
                        result[i] = new ConstructorParam { LowerName = parameters[i].Name.ToLower(), Kind = prop.Kind, TypeData = prop.TypeData };
                        break;
                    }
                }

                if (!found)
                    return null;
            }

            return result;
        }
Exemplo n.º 4
0
 private static ConstructorInfo FindConstructor(ConstructorInfo[] constructors, TypeData.PropertyData[] properties, out ConstructorParam[] constructorParams)
 {
     foreach (var constructor in constructors)
     {
         constructorParams = MatchConstructor(constructor, properties);
         if (constructorParams != null)
             return constructor;
     }
     constructorParams = null;
     return null;
 }
        // ----------------------------------------------------
        #region // Public Methods

        public MainRoutineSystem(ConstructorParam param)
        {
            this._barrageParamPtr = param.BarrageParamPtr;
            this._enemyParams     = param.EnemyParams;
        }