Ejemplo n.º 1
0
        /// <summary>
        /// Process inner node
        /// </summary>
        /// <param name="context">XML context</param>
        /// <param name="reader">Reader</param>
        protected override void ProcessInnerNode(IXsContext context, XmlReader reader)
        {
            PropertyInfo collProperty = null;

            switch (reader.NodeType)
            {
                case XmlNodeType.Comment:
                    collProperty = FindCollectionForNode(reader);
                    if (collProperty != null)
                        SetChildObject(reader, new Rem(reader.Value), null, collProperty);
                    reader.Read();
                    break;
                case XmlNodeType.ProcessingInstruction:
                    IScriptAction a = null;

                    if (string.Compare(reader.LocalName, "_", StringComparison.OrdinalIgnoreCase) == 0 ||
                        string.Compare(reader.LocalName, "code", StringComparison.OrdinalIgnoreCase) == 0)
                        a = new Code(reader.Value);
                    else if (string.Compare(reader.LocalName, "_d", StringComparison.OrdinalIgnoreCase) == 0 ||
                        string.Compare(reader.LocalName, "codeD", StringComparison.OrdinalIgnoreCase) == 0 ||
                        string.Compare(reader.LocalName, "codeDynamic", StringComparison.OrdinalIgnoreCase) == 0)
                        a = new Code(reader.Value) {Dynamic = true};
                    else if (string.Compare(reader.LocalName, "header", StringComparison.OrdinalIgnoreCase) == 0 ||
                             string.Compare(reader.LocalName, "h", StringComparison.OrdinalIgnoreCase) == 0)
                        a = new Header(reader.Value);
                    else if (string.Compare(reader.LocalName, "headerWithTypes", StringComparison.OrdinalIgnoreCase) == 0 ||
                             string.Compare(reader.LocalName, "ht", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        var h = new Header(reader.Value) {WithTypes = true};
                        h.RunWithTypes(context);
                        a = h;
                    }
                    else if (string.Compare(reader.LocalName, "rem", StringComparison.OrdinalIgnoreCase) == 0)
                        a = new Rem { Text = reader.Value };
                    else if (string.Compare(reader.LocalName, "xsharper-args", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        reader.Read();
                        break;
                    }

                    if (a == null)
                        throw new XsException(reader, string.Format("Unexpected processing instruction {0}", reader.Name));

                    if (this is Code)
                    {
                        if (a is Code)
                            ProcessAttribute(context, string.Empty, reader.Value, null);
                        else
                            ((Code) this).Add(a);
                    }
                    else
                    {
                        collProperty = FindCollectionForNode(reader);
                        try
                        {
                            SetChildObject(reader, a, null, collProperty);
                        }
                        catch (XsException)
                        {
                            if (!(a is Rem))
                                throw;

                        }
                    }
                    //    coll.Add(a);

                    reader.Read();
                    break;
                default:
                    base.ProcessInnerNode(context, reader);
                    break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write element to the output stream
        /// </summary>
        /// <param name="writer">Where to write</param>
        /// <param name="nameOverride">Local name to be used, or null if name should be retirevent from <see cref="XsTypeAttribute"/> of the type.</param>
        public override void WriteXml(XmlWriter writer, string nameOverride)
        {
            Code ce = new Code();
            ce.Methods = Methods;
            ce.Id = Id;
            string sourceCode=Script.GetSourceCode();
            if (sourceCode==null)
                throw new ScriptRuntimeException("This script cannot be decompiled!");
            ce.Value = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(sourceCode));

            ce.WriteXml(writer,nameOverride);
        }
Ejemplo n.º 3
0
 /// Constructor
 public CompiledCode(Code code)
 {
     Methods = code.Methods;
     Id = code.Id;
 }
Ejemplo n.º 4
0
            private void graphSaveNET35(object o, Code originalCode, int level)
            {
                bool first;
                Type t = o.GetType();
                string indent = new string('\t', level);
                string indent1 = new string('\t', level + 1);

                if (o is IEnumerable && (CustomAttributeHelper.All<XsTypeAttribute>(o.GetType()).Length == 0))
                {
                    first = true;
                    MainCode.Write("new " + _re.GetTypeName(t)  );
                    foreach (var obj in (o as IEnumerable))
                    {
                        MainCode.WriteLine(first ? " {" : ",");
                        MainCode.Write(indent1);
                        first = false;
                        GenerateObjectCode(obj, null, level + 1);
                    }
                    if (!first)
                    {
                        MainCode.WriteLine();
                        MainCode.Write(indent);
                        MainCode.Write("}");
                    }
                    else
                    {
                        MainCode.Write("()");
                    }
                    MainCode.Write(" ");
                }
                else
                {
                    newClass(o);

                    first = true;
                    foreach (var pi in getPropertiesToSave(o))
                    {
                        object propValue = pi.GetValue(o, null);

                        MainCode.WriteLine(first ? "{" : ",");
                        MainCode.Write(indent1);
                        first = false;
                        MainCode.Write(pi.Name + " = ");

                        if (pi.PropertyType == typeof(ExecutableScriptBase))
                            MainCode.Write("new " + originalCode.GetClassName() + "()");
                        else
                            GenerateObjectCode(propValue, null, level + 1);
                    }
                    if (!first)
                    {
                        MainCode.WriteLine();
                        MainCode.Write(indent);
                        MainCode.Write("}");
                    }
                }
            }
Ejemplo n.º 5
0
            private void graphSaveNET20(object o, string prevVarName, Code originalCode, int level)
            {
                Type t = o.GetType();
                string indent = new string('\t', level);

                if (o is IEnumerable && (CustomAttributeHelper.All<XsTypeAttribute>(o.GetType()).Length==0))
                {
                    if (t.GetGenericArguments().Length==0)
                        MainCode.Write("new "+_re.GetTypeName(t)+"()");
                    else
                    {
                        string bestType = _re.GetTypeName(t.GetGenericArguments()[0]);
                        MainCode.Write("new List<" + bestType + ">()");
                    }

                    foreach (var obj in (o as IEnumerable))
                    {
                        MainCode.WriteLine(";");
                        MainCode.Write(indent);
                        string v = getNextVar(obj);
                        if (obj is Code && ((Code)obj).Dynamic==false)
                            MainCode.Write(_re.GetTypeName(typeof(CompiledCode)));
                        else
                            MainCode.Write(_re.GetTypeName(obj.GetType()));

                        MainCode.Write(" " + v + " = ");
                        GenerateObjectCode(obj, v, level + 1);
                        MainCode.WriteLine(";");
                        MainCode.Write(indent + prevVarName + ".Add(" + v + ")");
                    }
                }
                else
                {
                    newClass(o);
                    foreach (var pi in getPropertiesToSave(o))
                    {
                        MainCode.WriteLine(";");
                        MainCode.Write(indent);

                        if (!pi.PropertyType.IsClass || pi.PropertyType == typeof(string) || pi.PropertyType == typeof(ExecutableScriptBase))
                        {
                            MainCode.Write(prevVarName + "." + pi.Name + " = ");
                            if (pi.PropertyType == typeof(ExecutableScriptBase))
                                MainCode.Write("new " + originalCode.GetClassName() + "()");
                            else
                            {
                                object propValue = pi.GetValue(o, null);
                                writeSimple(propValue);
                            }
                        }
                        else
                        {
                            object propValue = pi.GetValue(o, null);
                            if (propValue != null)
                            {
                                string v = getNextVar(propValue);
                                MainCode.Write(_re.GetTypeName(propValue.GetType()) + " " + v + " = ");
                                GenerateObjectCode(propValue, v, level + 1);
                                MainCode.WriteLine(";");
                                MainCode.Write(indent + prevVarName + "." + pi.Name + " = " + v);
                            }
                        }
                    }
                }
            }
Ejemplo n.º 6
0
 internal void RunWithTypes(IXsContext context)
 {
     if (WithTypes)
     {
         Initialize();
         ScriptContext c = (ScriptContext) context;
         c.Compiler.AddHeaders(GetTransformedValueStr());
         Code code = new Code();
         c.Initialize(code);
         Assembly a = c.GetClassInstanceType(code).Assembly;
         c.AddAssembly(a,true);
     }
 }