GenerateValue() public method

public GenerateValue ( object value, Type type ) : System.CodeDom.CodeExpression
value object
type System.Type
return System.CodeDom.CodeExpression
コード例 #1
0
        protected virtual void GeneratePropertySet(GeneratorContext ctx, CodeExpression var, PropertyDescriptor prop)
        {
            object oval = prop.GetValue(Wrapped);

            if (oval == null || (prop.HasDefault && prop.IsDefaultValue(oval)))
            {
                return;
            }

            CodeExpression val = ctx.GenerateValue(oval, prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated(Wrapped));
            CodeExpression cprop;

            TypedPropertyDescriptor tprop = prop as TypedPropertyDescriptor;

            if (tprop == null || tprop.GladeProperty == prop)
            {
                cprop = new CodePropertyReferenceExpression(var, prop.Name);
            }
            else
            {
                cprop = new CodePropertyReferenceExpression(var, tprop.GladeProperty.Name);
                cprop = new CodePropertyReferenceExpression(cprop, prop.Name);
            }
            ctx.Statements.Add(new CodeAssignStatement(cprop, val));
        }
コード例 #2
0
 internal protected virtual CodeExpression GenerateObjectCreation(GeneratorContext ctx)
 {
     if (ClassDescriptor.InitializationProperties != null)
     {
         CodeExpression[] paramters = new CodeExpression [ClassDescriptor.InitializationProperties.Length];
         for (int n = 0; n < paramters.Length; n++)
         {
             PropertyDescriptor prop = ClassDescriptor.InitializationProperties [n];
             paramters [n] = ctx.GenerateValue(prop.GetValue(Wrapped), prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated(Wrapped));
         }
         return(new CodeObjectCreateExpression(WrappedTypeName.ToGlobalTypeRef(), paramters));
     }
     else
     {
         return(new CodeObjectCreateExpression(WrappedTypeName.ToGlobalTypeRef()));
     }
 }
コード例 #3
0
ファイル: ObjectWrapper.cs プロジェクト: Kalnor/monodevelop
		protected virtual void GeneratePropertySet (GeneratorContext ctx, CodeExpression var, PropertyDescriptor prop)
		{
			object oval = prop.GetValue (Wrapped);
			if (oval == null || (prop.HasDefault && prop.IsDefaultValue (oval)))
				return;
				
			CodeExpression val = ctx.GenerateValue (oval, prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated (Wrapped));
			CodeExpression cprop;
			
			TypedPropertyDescriptor tprop = prop as TypedPropertyDescriptor;
			if (tprop == null || tprop.GladeProperty == prop) {
				cprop = new CodePropertyReferenceExpression (var, prop.Name);
			} else {
				cprop = new CodePropertyReferenceExpression (var, tprop.GladeProperty.Name);
				cprop = new CodePropertyReferenceExpression (cprop, prop.Name);
			}
			ctx.Statements.Add (new CodeAssignStatement (cprop, val));
		}
コード例 #4
0
ファイル: ObjectWrapper.cs プロジェクト: Kalnor/monodevelop
		internal protected virtual CodeExpression GenerateObjectCreation (GeneratorContext ctx)
		{
			if (ClassDescriptor.InitializationProperties != null) {
				CodeExpression[] paramters = new CodeExpression [ClassDescriptor.InitializationProperties.Length];
				for (int n=0; n < paramters.Length; n++) {
					PropertyDescriptor prop = ClassDescriptor.InitializationProperties [n];
					paramters [n] = ctx.GenerateValue (prop.GetValue (Wrapped), prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated (Wrapped));
				}
				return new CodeObjectCreateExpression (WrappedTypeName.ToGlobalTypeRef (), paramters);
			} else
				return new CodeObjectCreateExpression (WrappedTypeName.ToGlobalTypeRef ());
		}