Exemple #1
0
        private static object InvokeHelper(CallInfo callinfo, IList <object> args, Activate buildType = null)
        {
            bool   setWithName = true;
            object theArgument = null;

            if (callinfo.ArgumentNames.Count == 0 && callinfo.ArgumentCount == 1)
            {
                theArgument = args[0];

                if (TypeFactorization.IsTypeAnonymous(theArgument) ||
                    theArgument is IEnumerable <KeyValuePair <string, object> > )
                {
                    setWithName = false;
                }
            }

            if (setWithName && callinfo.ArgumentNames.Count != callinfo.ArgumentCount)
            {
                throw new ArgumentException("Requires argument names for every argument");
            }

            object result;

            if (buildType != null)
            {
                result = buildType.Create();
            }
            else
            {
                try
                {
                    result = Activator.CreateInstance <TObjectProtoType>();
                }
                catch (MissingMethodException)
                {
                    result = InvocationBinding.CreateInstance(typeof(TObjectProtoType));
                }
            }
            if (setWithName)
            {
                theArgument = callinfo.ArgumentNames.Zip(args, (n, a) => new KeyValuePair <string, object>(n, a));
            }

            return(InvocationBinding.InvokeSetAll(result, theArgument));
        }
Exemple #2
0
        public dynamic ListSetup(params dynamic[] constructorArgs)
        {
            var activation = constructorArgs.OfType <Activate>().SingleOrDefault();

            if (null == activation)
            {
                if (!_buildType.TryGetValue("Object", out activation))
                {
                    activation = null;
                }
                if (activation != null)
                {
                    activation = new Activate(activation.Type, constructorArgs);
                }
                if (null == activation)
                {
                    activation = new Activate <ShapeableExpandoList>(constructorArgs);
                }
            }

            _buildType["List"]  = activation;
            _buildType["Array"] = activation;
            return(this);
        }
Exemple #3
0
 public dynamic ObjectSetup(params dynamic[] constructorArgs)
 {
     _buildType["Object"] = new Activate <TObjectProtoType>(constructorArgs);
     return(this);
 }