Beispiel #1
0
        /// <summary>
        /// Gets the fully qualified name of the type from the expression.
        /// </summary>
        /// <remarks>
        /// The expression is the first target of a call expression.
        ///
        /// A call expression is a method or constructor call (right hand side of expression below):
        ///
        /// a = Root.Test.Class1()
        ///
        /// So the expression passed to this method will be a field expression in the
        /// above example which refers to Class1. The next target will be a field
        /// expression referring to Test. The The last target will be a name expression
        /// referring to Root.
        ///
        /// If we have
        ///
        /// a = Class1()
        ///
        /// then the expression will be a name expression referring to Class1.
        /// </remarks>
        string GetTypeName(Expression expression)
        {
            NameExpression nameExpression = expression as NameExpression;

            if (nameExpression != null)
            {
                return(nameExpression.Name);
            }
            return(PythonControlFieldExpression.GetMemberName(expression as MemberExpression));
        }
        static PythonControlFieldExpression Create(string[] memberNames)
        {
            string memberName = String.Empty;

            if (memberNames.Length > 1)
            {
                memberName = memberNames[memberNames.Length - 1];
            }
            string fullMemberName = PythonControlFieldExpression.GetMemberName(memberNames);

            return(new PythonControlFieldExpression(memberName, GetVariableNameFromSelfReference(fullMemberName), String.Empty, fullMemberName));
        }
 /// <summary>
 /// Gets the fully qualified name of the base class.
 /// </summary>
 public static string GetBaseClassName(ClassDefinition classDefinition)
 {
     if (classDefinition.Bases.Count > 0)
     {
         Expression       baseClassExpression = classDefinition.Bases[0];
         NameExpression   nameExpression      = baseClassExpression as NameExpression;
         MemberExpression memberExpression    = baseClassExpression as MemberExpression;
         if (nameExpression != null)
         {
             return(nameExpression.Name);
         }
         return(PythonControlFieldExpression.GetMemberName(memberExpression));
     }
     return(String.Empty);
 }
 /// <summary>
 /// Looks for any base types for the class defined in the
 /// list of expressions and adds them to the class.
 /// </summary>
 void AddBaseTypes(IClass c, IList <Expression> baseTypes)
 {
     foreach (Expression expression in baseTypes)
     {
         NameExpression   nameExpression   = expression as NameExpression;
         MemberExpression memberExpression = expression as MemberExpression;
         if (nameExpression != null)
         {
             AddBaseType(c, nameExpression.Name);
         }
         else if (memberExpression != null)
         {
             AddBaseType(c, PythonControlFieldExpression.GetMemberName(memberExpression));
         }
     }
 }
        /// <summary>
        /// Creates a new instance with the specified name.
        /// </summary>
        object CreateInstance(string name, CallExpression node)
        {
            MemberExpression memberExpression = node.Target as MemberExpression;

            if (memberExpression != null)
            {
                string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);
                Type   type     = componentCreator.GetType(typeName);
                if (type != null)
                {
                    if (type.IsAssignableFrom(typeof(ComponentResourceManager)))
                    {
                        return(componentCreator.CreateInstance(type, new object[0], name, false));
                    }
                    List <object> args = deserializer.GetArguments(node);
                    return(componentCreator.CreateInstance(type, args, name, false));
                }
            }
            return(null);
        }
Beispiel #6
0
        void AddBaseType(MemberExpression memberExpression)
        {
            string name = PythonControlFieldExpression.GetMemberName(memberExpression);

            AddBaseType(name);
        }
        Type GetType(MemberExpression memberExpression)
        {
            string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);

            return(componentCreator.GetType(typeName));
        }
        void ThrowCouldNotFindTypeException(MemberExpression memberExpression)
        {
            string typeName = PythonControlFieldExpression.GetMemberName(memberExpression);

            throw new PythonComponentWalkerException(String.Format(StringParser.Parse("${res:ICSharpCode.PythonBinding.UnknownTypeName}"), typeName));
        }
        /// <summary>
        /// Returns true if the expression is of the form:
        ///
        /// resources.GetObject(...) or
        /// resources.GetString(...)
        /// </summary>
        bool IsResource(MemberExpression memberExpression)
        {
            string fullName = PythonControlFieldExpression.GetMemberName(memberExpression);

            return(fullName.StartsWith("resources.", StringComparison.InvariantCultureIgnoreCase));
        }