Ejemplo n.º 1
0
        public static String GetArrayLiteral(object MyObject)
        {
            Array MyArray      = (Array)MyObject;
            var   declaration  = "new " + MyArray.GetType().GetElementType() + "[] {";
            var   elementIndex = 0;

            foreach (var element in MyArray)
            {
                if (elementIndex > 0)
                {
                    declaration += ",";
                }
                declaration += VariableLiteral.GetNewLiteral(element);

                elementIndex++;
            }
            declaration += "}";
            return(declaration);
        }
Ejemplo n.º 2
0
        public static String GetIListLiteral(object MyObject)
        {
            var declaration   = "new List<" + MyObject.GetType().GetGenericArguments().Single() + ">{";
            var myCollection  = (IEnumerable)MyObject;
            var listItemIndex = 0;

            foreach (var listItem in myCollection)
            {
                if (listItemIndex > 0)
                {
                    declaration += ",";
                }
                declaration += VariableLiteral.GetNewLiteral(listItem);

                listItemIndex++;
            }
            declaration += "}";
            return(declaration);
        }
Ejemplo n.º 3
0
        public static String GetClassLiteral(object MyObject)
        {
            var declaration   = "new " + MyObject.GetType().Name + " {";
            var propertyIndex = 0;

            foreach (var property in MyObject.GetType().GetProperties())
            {
                if (property.GetGetMethod() != null)
                {
                    if (propertyIndex > 0)
                    {
                        declaration += ",";
                    }
                    declaration += property.Name + " = " +
                                   VariableLiteral.GetNewLiteral(property.GetValue(MyObject, null));

                    propertyIndex++;
                }
            }
            declaration += "}";
            return(declaration);
        }