public override System.CodeDom.CodeExpression GetCodeExpression(
     BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     CodeTypeReferenceExpression targetClass =
         new CodeTypeReferenceExpression(typeof(ExpressionBuilderIdentity));
     string targetMethod = "GetIdentity";
     CodeExpression methodParameter =
         new CodePrimitiveExpression(entry.Expression.Trim());
     return new CodeMethodInvokeExpression(
         targetClass, targetMethod, methodParameter);
 }
Ejemplo n.º 2
0
	public override CodeExpression GetCodeExpression(
		BoundPropertyEntry entry, object parsedData,
		ExpressionBuilderContext context)
	{
		// entry.Expression is the number string
		// (minus the RandomNumber: prefix).
		if (!entry.Expression.Contains(","))
		{
			throw new ArgumentException("Must include two numbers separated by a comma.");
		}
		else
		{
			// Get the two numbers.
			string[] numbers = entry.Expression.Split(',');

			if (numbers.Length != 2)
			{
				throw new ArgumentException("Only include two numbers.");
			}
			else
			{
				int lowerLimit, upperLimit;
				if (Int32.TryParse(numbers[0], out lowerLimit) &&
					Int32.TryParse(numbers[1], out upperLimit))
				{

					// So far all the operations have been performed in
					// normal code. That's because the two numbers are
					// specified in the expression, and so they won't
					// change each time the page is requested.
					// However, the random number should be allowed to
					// change each time, so you need to switch to CodeDOM.
					Type type = entry.DeclaringType;
					PropertyDescriptor descriptor = TypeDescriptor.GetProperties(type)[entry.PropertyInfo.Name];
					CodeExpression[] expressionArray = new CodeExpression[2];
					expressionArray[0] = new CodePrimitiveExpression(lowerLimit);
					expressionArray[1] = new CodePrimitiveExpression(upperLimit); 
					return new CodeCastExpression(descriptor.PropertyType, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(base.GetType()), "GetRandomNumber", expressionArray));
				}
				else
				{
					throw new ArgumentException("Use valid integers.");
				}

			}
		}
		
	}
    public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
        object parsedData, ExpressionBuilderContext context)
    {
        // entry.Expression - строка с числом 
        // без префикса (например: "1,6").
        if (!entry.Expression.Contains(","))
        {
            throw new ArgumentException(" Должны быть указаны два числа, разделенные запятой");
        }
        else
        {
            // Получить два числа
            string[] numbers = entry.Expression.Split(',');

            if (numbers.Length != 2)
            {
                throw new ArgumentException("Должны быть указаны два числа");
            }
            else
            {
                int min, max;
                if (Int32.TryParse(numbers[0], out min) &&
                    Int32.TryParse(numbers[1], out max))
                {

                    // Получить ссылку на класс, имеющий метод GetRandomNumber(). 
                    // (Это класс, где данный код выполняется.)
                    CodeTypeReferenceExpression typeRef = new CodeTypeReferenceExpression(this.GetType());

                    // Определить параметры для GetRandomNumber().
                    CodeExpression[] methodParameters = new CodeExpression[2];
                    methodParameters[0] = new CodePrimitiveExpression(min);
                    methodParameters[1] = new CodePrimitiveExpression(max);

                    // Вернуть выражение привязки вызвав метод GetRandomNumber()
                    CodeMethodInvokeExpression methodCall = new CodeMethodInvokeExpression(
                        typeRef, "GetRandomNumber", methodParameters);
                    return methodCall;
                }
                else
                {
                    throw new ArgumentException("Должны использоваться допустимые целые числа");
                }

            }
        }
    }
Ejemplo n.º 4
0
 public abstract CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData,
                                                  ExpressionBuilderContext context);
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(typeof(Site)), (string)parsedData));
 }
Ejemplo n.º 6
0
        internal virtual void BuildExpression(BoundPropertyEntry bpe, ControlBuilder controlBuilder, CodeExpression controlReference, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, ref bool hasTempObject)
        {
            CodeExpression expression = this.GetCodeExpression(bpe, bpe.ParsedExpressionData, new ExpressionBuilderContext(controlBuilder.VirtualPath));

            CodeDomUtility.CreatePropertySetStatements(methodStatements, statements, controlReference, bpe.Name, bpe.Type, expression, linePragma);
        }
 // This method is used only from within pages that aren't compiled
 public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     // Mono doesn't use this, so let's leave it like that for now
     throw new NotImplementedException();
 }
    public override System.CodeDom.CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
    {
        CodeExpression[] expressionArray1 = new CodeExpression[1] { new CodePrimitiveExpression(entry.Expression.Trim()) };

        return new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(base.GetType()), "GetEvalData", expressionArray1);
    }
Ejemplo n.º 9
0
 public override System.CodeDom.CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData,
         ExpressionBuilderContext context)
 {
     return new CodeCastExpression("Int64",
         new CodePrimitiveExpression(parsedData));
 }
Ejemplo n.º 10
0
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(CodeExpressionHelper.MakeStaticMethodInvokeExpression(
                typeof(WebAreaCommonResources), "ProvideURLFor", entry.Expression.Trim()
                ));
 }
Ejemplo n.º 11
0
 public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(WebAreaCommonResources.ProvideURLFor(entry.Expression.Trim()));
 }
 /// <summary>
 ///     Для некомпилируемой страницы. Нужно только если SupportsEvaluate==true
 /// </summary>
 public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(base.EvaluateExpression(target, entry, parsedData, context));
 }
Ejemplo n.º 13
0
 public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(GetAppSetting(entry.Expression.Trim()));
 }
 /// <summary>Gets the code expresion evaluated at page compile time.</summary>
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(new CodeSnippetExpression(string.Format(ExpressionFormat, entry.Expression, entry.DeclaringType)));
 }
 /// <summary>
 /// When overridden in a derived class, returns an object that represents an evaluated expression.
 /// </summary>
 /// <param name="target">
 /// The object containing the expression.
 /// </param>
 /// <param name="entry">
 /// The object that represents information about the property bound to by the expression.
 /// </param>
 /// <param name="parsedData">
 /// The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"/>.
 /// </param>
 /// <param name="context">
 /// Contextual information for the evaluation of the expression.
 /// </param>
 /// <returns>
 /// An object that represents the evaluated expression; otherwise, null if the inheritor does not implement <see cref="M:System.Web.Compilation.ExpressionBuilder.EvaluateExpression(System.Object,System.Web.UI.BoundPropertyEntry,System.Object,System.Web.Compilation.ExpressionBuilderContext)"/>.
 /// </returns>
 public override object EvaluateExpression(
     object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(this.GetRequestedValue(entry.Expression.Trim(), target.GetType(), entry.PropertyInfo.Name));
 }
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(Settings)), "GetValue", new CodePrimitiveExpression(parsedData)));
 }
 public abstract override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context);
 public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return GetEvalData(entry.Expression);
 }
Ejemplo n.º 19
0
 internal override void BuildExpression(BoundPropertyEntry bpe, ControlBuilder controlBuilder,
                                        CodeExpression controlReference, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, ref bool hasTempObject)
 {
     BuildExpressionStatic(bpe, controlBuilder, controlReference, methodStatements, statements, linePragma, bpe.IsEncoded, ref hasTempObject);
 }
        private static string LocalizeObject(IServiceProvider serviceProvider, object obj, ObjectPersistData persistData, ResourceExpressionEditor resEditor, IDesignTimeResourceWriter resourceWriter, string resourceKey, string objectModelName, object topLevelObject, string filter, bool shouldLocalizeInnerContent, bool isComplexProperty, bool implicitlyLocalizeComplexProperty)
        {
            bool flag;

            if (isComplexProperty)
            {
                flag = implicitlyLocalizeComplexProperty;
            }
            else
            {
                flag = (persistData == null) || persistData.Localize;
            }
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(obj);

            for (int i = 0; i < properties.Count; i++)
            {
                try
                {
                    PropertyDescriptor propertyDescriptor = properties[i];
                    if (string.Equals(propertyDescriptor.Name, "Controls", StringComparison.Ordinal))
                    {
                        Control control = obj as Control;
                        if ((control != null) && shouldLocalizeInnerContent)
                        {
                            if (!ParseChildren(control.GetType()))
                            {
                                foreach (Control control2 in control.Controls)
                                {
                                    IControlBuilderAccessor accessor       = control2;
                                    ControlBuilder          controlBuilder = accessor.ControlBuilder;
                                    if (controlBuilder != null)
                                    {
                                        string str = controlBuilder.GetResourceKey();
                                        string b   = LocalizeObject(serviceProvider, control2, controlBuilder.GetObjectPersistData(), resEditor, resourceWriter, str, string.Empty, control2, string.Empty, true, false, false);
                                        if (!string.Equals(str, b, StringComparison.OrdinalIgnoreCase))
                                        {
                                            controlBuilder.SetResourceKey(b);
                                        }
                                    }
                                }
                            }
                            continue;
                        }
                    }
                    PersistenceModeAttribute attribute = (PersistenceModeAttribute)propertyDescriptor.Attributes[typeof(PersistenceModeAttribute)];
                    string str3 = (objectModelName.Length > 0) ? (objectModelName + '.' + propertyDescriptor.Name) : propertyDescriptor.Name;
                    if ((attribute.Mode == PersistenceMode.Attribute) && (propertyDescriptor.SerializationVisibility == DesignerSerializationVisibility.Content))
                    {
                        resourceKey = LocalizeObject(serviceProvider, propertyDescriptor.GetValue(obj), persistData, resEditor, resourceWriter, resourceKey, str3, topLevelObject, filter, true, true, flag);
                    }
                    else if ((attribute.Mode == PersistenceMode.Attribute) || (propertyDescriptor.PropertyType == typeof(string)))
                    {
                        bool   flag2 = false;
                        bool   flag3 = false;
                        object obj2  = null;
                        string name  = string.Empty;
                        if (persistData != null)
                        {
                            PropertyEntry filteredProperty = persistData.GetFilteredProperty(string.Empty, str3);
                            if (filteredProperty is BoundPropertyEntry)
                            {
                                BoundPropertyEntry entry2 = (BoundPropertyEntry)filteredProperty;
                                if (!entry2.Generated)
                                {
                                    if (string.Equals(entry2.ExpressionPrefix, "resources", StringComparison.OrdinalIgnoreCase))
                                    {
                                        System.Web.Compilation.ResourceExpressionFields parsedExpressionData = entry2.ParsedExpressionData as System.Web.Compilation.ResourceExpressionFields;
                                        if ((parsedExpressionData != null) && string.IsNullOrEmpty(parsedExpressionData.ClassKey))
                                        {
                                            name = parsedExpressionData.ResourceKey;
                                            obj2 = resEditor.EvaluateExpression(entry2.Expression, entry2.ParsedExpressionData, propertyDescriptor.PropertyType, serviceProvider);
                                            if (obj2 != null)
                                            {
                                                flag3 = true;
                                            }
                                            flag2 = true;
                                        }
                                    }
                                }
                                else
                                {
                                    flag2 = true;
                                }
                            }
                            else
                            {
                                flag2 = flag && IsPropertyLocalizable(propertyDescriptor);
                            }
                        }
                        else
                        {
                            flag2 = flag && IsPropertyLocalizable(propertyDescriptor);
                        }
                        if (flag2)
                        {
                            if (!flag3)
                            {
                                obj2 = propertyDescriptor.GetValue(obj);
                            }
                            if (name.Length == 0)
                            {
                                if (string.IsNullOrEmpty(resourceKey))
                                {
                                    resourceKey = resourceWriter.CreateResourceKey(null, topLevelObject);
                                }
                                name = resourceKey + '.' + str3;
                                if (filter.Length != 0)
                                {
                                    name = filter + ':' + name;
                                }
                            }
                            resourceWriter.AddResource(name, obj2);
                        }
                        if (persistData != null)
                        {
                            foreach (PropertyEntry entry3 in persistData.GetPropertyAllFilters(str3))
                            {
                                if (entry3.Filter.Length > 0)
                                {
                                    if (entry3 is SimplePropertyEntry)
                                    {
                                        if (flag && IsPropertyLocalizable(propertyDescriptor))
                                        {
                                            if (name.Length == 0)
                                            {
                                                if (string.IsNullOrEmpty(resourceKey))
                                                {
                                                    resourceKey = resourceWriter.CreateResourceKey(null, topLevelObject);
                                                }
                                                name = resourceKey + '.' + str3;
                                            }
                                            string str5 = entry3.Filter + ':' + name;
                                            resourceWriter.AddResource(str5, ((SimplePropertyEntry)entry3).Value);
                                        }
                                    }
                                    else if (!(entry3 is ComplexPropertyEntry) && (entry3 is BoundPropertyEntry))
                                    {
                                        BoundPropertyEntry entry4 = (BoundPropertyEntry)entry3;
                                        if (!entry4.Generated && string.Equals(entry4.ExpressionPrefix, "resources", StringComparison.OrdinalIgnoreCase))
                                        {
                                            System.Web.Compilation.ResourceExpressionFields fields2 = entry4.ParsedExpressionData as System.Web.Compilation.ResourceExpressionFields;
                                            if ((fields2 != null) && string.IsNullOrEmpty(fields2.ClassKey))
                                            {
                                                object obj3 = resEditor.EvaluateExpression(entry4.Expression, entry4.ParsedExpressionData, entry3.PropertyInfo.PropertyType, serviceProvider);
                                                if (obj3 == null)
                                                {
                                                    obj3 = string.Empty;
                                                }
                                                resourceWriter.AddResource(fields2.ResourceKey, obj3);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else if (shouldLocalizeInnerContent)
                    {
                        if (typeof(ICollection).IsAssignableFrom(propertyDescriptor.PropertyType))
                        {
                            if (persistData != null)
                            {
                                foreach (ComplexPropertyEntry entry5 in persistData.GetPropertyAllFilters(propertyDescriptor.Name))
                                {
                                    foreach (ComplexPropertyEntry entry6 in entry5.Builder.GetObjectPersistData().CollectionItems)
                                    {
                                        ControlBuilder builder = entry6.Builder;
                                        object         obj4    = builder.BuildObject();
                                        string         str6    = builder.GetResourceKey();
                                        string         str7    = LocalizeObject(serviceProvider, obj4, builder.GetObjectPersistData(), resEditor, resourceWriter, str6, string.Empty, obj4, string.Empty, true, false, false);
                                        if (!string.Equals(str6, str7, StringComparison.OrdinalIgnoreCase))
                                        {
                                            builder.SetResourceKey(str7);
                                        }
                                    }
                                }
                            }
                        }
                        else if (typeof(ITemplate).IsAssignableFrom(propertyDescriptor.PropertyType))
                        {
                            if (persistData != null)
                            {
                                foreach (TemplatePropertyEntry entry7 in persistData.GetPropertyAllFilters(propertyDescriptor.Name))
                                {
                                    TemplateBuilder builder3     = (TemplateBuilder)entry7.Builder;
                                    IDesignerHost   designerHost = (IDesignerHost)serviceProvider.GetService(typeof(IDesignerHost));
                                    Control[]       controlArray = ControlParser.ParseControls(designerHost, builder3.Text);
                                    for (int j = 0; j < controlArray.Length; j++)
                                    {
                                        if (!(controlArray[j] is LiteralControl) && !(controlArray[j] is DesignerDataBoundLiteralControl))
                                        {
                                            LocalizeControl(controlArray[j], serviceProvider, resourceWriter, true);
                                        }
                                    }
                                    StringBuilder builder4 = new StringBuilder();
                                    for (int k = 0; k < controlArray.Length; k++)
                                    {
                                        if (controlArray[k] is LiteralControl)
                                        {
                                            builder4.Append(((LiteralControl)controlArray[k]).Text);
                                        }
                                        else
                                        {
                                            builder4.Append(ControlPersister.PersistControl(controlArray[k], designerHost));
                                        }
                                    }
                                    builder3.Text = builder4.ToString();
                                }
                            }
                        }
                        else if (persistData != null)
                        {
                            object               obj5 = propertyDescriptor.GetValue(obj);
                            ObjectPersistData    objectPersistData = null;
                            ComplexPropertyEntry entry8            = (ComplexPropertyEntry)persistData.GetFilteredProperty(string.Empty, propertyDescriptor.Name);
                            if (entry8 != null)
                            {
                                objectPersistData = entry8.Builder.GetObjectPersistData();
                            }
                            resourceKey = LocalizeObject(serviceProvider, obj5, objectPersistData, resEditor, resourceWriter, resourceKey, str3, topLevelObject, string.Empty, true, true, flag);
                            foreach (ComplexPropertyEntry entry9 in persistData.GetPropertyAllFilters(propertyDescriptor.Name))
                            {
                                if (entry9.Filter.Length > 0)
                                {
                                    ControlBuilder builder5 = entry9.Builder;
                                    objectPersistData = builder5.GetObjectPersistData();
                                    obj5        = builder5.BuildObject();
                                    resourceKey = LocalizeObject(serviceProvider, obj5, objectPersistData, resEditor, resourceWriter, resourceKey, str3, topLevelObject, entry9.Filter, true, true, flag);
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    if (serviceProvider != null)
                    {
                        IComponentDesignerDebugService service = serviceProvider.GetService(typeof(IComponentDesignerDebugService)) as IComponentDesignerDebugService;
                        if (service != null)
                        {
                            service.Fail(exception.Message);
                        }
                    }
                }
            }
            return(resourceKey);
        }
Ejemplo n.º 21
0
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
                                                  object parsedData, ExpressionBuilderContext context)
 {
     Debug.Fail("This should never be called");
     return(null);
 }
Ejemplo n.º 22
0
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(new CodeSnippetExpression(entry.Expression));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Returns a <see cref="System.CodeDom"/> expression for invoking the expression from a
 ///     compiled page at runtime.
 /// </summary>
 /// <param name="entry">
 /// The entry for the bound property.
 /// </param>
 /// <param name="parsedData">
 /// The parsed expression data.
 /// </param>
 /// <param name="context">
 /// The expression builder context.
 /// </param>
 /// <returns>
 /// A <see cref="CodeExpression"/> for invoking the expression.
 /// </returns>
 public override CodeExpression GetCodeExpression(
     BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(new CodePrimitiveExpression(parsedData));
 }
 public override object EvaluateExpression(object target, BoundPropertyEntry entry,
                                           object parsedData, ExpressionBuilderContext context)
 {
     return(GetEvalData(entry.Expression, target.GetType(), entry.Name));
 }
Ejemplo n.º 25
0
 GetCodeExpression(BoundPropertyEntry entry, object parsedData,
                   ExpressionBuilderContext context)
 {
     return(new CodeCastExpression("Int64",
                                   new CodePrimitiveExpression(1000)));
 }
 public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return((string)parsedData);
 }
Ejemplo n.º 27
0
 override CodeExpression GetCodeExpression(BoundPropertyEntry entry, ...)
 {
     return(new CodeSnippetExpression(entry.Expression));
 }
Ejemplo n.º 28
0
 public virtual object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData,
                                          ExpressionBuilderContext context)
 {
     return(null);
 }
        private CodeExpression GetAppResCodeExpression(string classKey, string resourceKey, BoundPropertyEntry entry)
        {
            // We generate the following
            //      this.GetGlobalResourceObject(classKey)
            CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression();

            expr.Method.TargetObject = new CodeThisReferenceExpression();

            expr.Method.MethodName = "GetGlobalResourceObject";
            expr.Parameters.Add(new CodePrimitiveExpression(classKey));
            expr.Parameters.Add(new CodePrimitiveExpression(resourceKey));

            // If the property is not of type string, it will need to be converted
            if (entry.Type != typeof(string) && entry.Type != null)
            {
                expr.Parameters.Add(new CodeTypeOfExpression(entry.DeclaringType));
                expr.Parameters.Add(new CodePrimitiveExpression(entry.PropertyInfo.Name));
            }

            return(expr);
        }
Ejemplo n.º 30
0
 public override object EvaluateExpression(object target, BoundPropertyEntry entry,
                                           object parsedData, ExpressionBuilderContext context)
 {
     return(GetRouteUrl(context.TemplateControl, entry.Expression.Trim()));
 }
Ejemplo n.º 31
0
 public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
 {
     return(new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(base.GetType()), "GetRouteValue", new CodeExpression[] { new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Page"), new CodePrimitiveExpression(entry.Expression.Trim()), new CodeTypeOfExpression(new CodeTypeReference(entry.ControlType)), new CodePrimitiveExpression(entry.Name) }));
 }