Inheritance: System.CodeDom.CodeExpression
        public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
        {
            if (!entry.Expression.Contains(","))
              {
            throw new ArgumentException("Must include two numbers separated by a comma.");
              }
              else
              {
            // get 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))
              {
            CodeTypeReferenceExpression typeRef = new CodeTypeReferenceExpression(this.GetType());
            CodeExpression[] methodParameters = new CodeExpression[2];
            methodParameters[0] = new CodePrimitiveExpression(lowerLimit);
            methodParameters[1] = new CodePrimitiveExpression(upperLimit);

            return new CodeMethodInvokeExpression(typeRef, "GetRandomNumber", methodParameters);
              }
              else
              {
            throw new ArgumentException("Use valid Integers");
              }
            }
              }
        }
 private static CodePropertyReferenceExpression DeserializeAppConfigExpression(string[] expressionParts)
 {
     int index = expressionParts.Length - 1;
     CodePropertyReferenceExpression expression = new CodePropertyReferenceExpression {
         PropertyName = expressionParts[index]
     };
     index--;
     CodeIndexerExpression expression2 = new CodeIndexerExpression();
     expression.TargetObject = expression2;
     expression2.Indices.Add(new CodePrimitiveExpression(expressionParts[index]));
     index--;
     CodePropertyReferenceExpression expression3 = new CodePropertyReferenceExpression();
     expression2.TargetObject = expression3;
     expression3.PropertyName = expressionParts[index];
     index--;
     CodeTypeReferenceExpression expression4 = new CodeTypeReferenceExpression();
     expression3.TargetObject = expression4;
     expression4.Type.Options = (CodeTypeReferenceOptions) Enum.Parse(typeof(CodeTypeReferenceOptions), expressionParts[index]);
     index--;
     expression4.Type.BaseType = expressionParts[index];
     index--;
     while (index > 0)
     {
         expression4.Type.BaseType = expressionParts[index] + "." + expression4.Type.BaseType;
         index--;
     }
     return expression;
 }
 public override void ImportClass()
 {
     SoapAddressBinding binding = (base.ImportContext.Port == null) ? null : ((SoapAddressBinding) base.ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding)));
     if (base.ImportContext.Style == ServiceDescriptionImportStyle.Client)
     {
         base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);
         CodeConstructor ctor = WebCodeGenerator.AddConstructor(base.ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
         ctor.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
         bool flag = true;
         if (base.ImportContext is Soap12ProtocolImporter)
         {
             flag = false;
             CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
             CodeFieldReferenceExpression right = new CodeFieldReferenceExpression(targetObject, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
             CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
             CodeAssignStatement statement = new CodeAssignStatement(left, right);
             ctor.Statements.Add(statement);
         }
         ServiceDescription serviceDescription = base.ImportContext.Binding.ServiceDescription;
         string url = (binding != null) ? binding.Location : null;
         string appSettingUrlKey = serviceDescription.AppSettingUrlKey;
         string appSettingBaseUrl = serviceDescription.AppSettingBaseUrl;
         ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, appSettingUrlKey, appSettingBaseUrl, flag && !base.ImportContext.IsEncodedBinding);
     }
     else if (base.ImportContext.Style == ServiceDescriptionImportStyle.Server)
     {
         base.ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
     }
 }
 public static CodeExpression Is(CodeVariableReferenceExpression var,
     CodeTypeReferenceExpression type, CodeDomProvider provider)
 {
     return new CodeSnippetExpression(
         "((" + ExpressionToString(var, provider) + ") is " +
         ExpressionToString(type, provider) + ")");
 }
 /// <summary>
 /// Initializes a new instance of the CodeTypeOperationExpression class.
 /// </summary>
 /// <param name="source">The source expression.</param>
 /// <param name="targetType">The target type reference expression.</param>
 protected CodeTypeOperationExpression(CodeExpression source, CodeTypeReferenceExpression targetType)
 {
     ExceptionUtilities.CheckArgumentNotNull(source, "source");
     ExceptionUtilities.CheckArgumentNotNull(targetType, "targetType");
     this.Source = source;
     this.TargetType = targetType;
 }
 public override void ImportClass() {
     // grab this here so it gets marked "handled" for both client and server
     SoapAddressBinding soapAddress = ImportContext.Port == null ? null : (SoapAddressBinding)ImportContext.Port.Extensions.Find(typeof(SoapAddressBinding));
     if (ImportContext.Style == ServiceDescriptionImportStyle.Client) {
         ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(SoapHttpClientProtocol).FullName);                                
         CodeConstructor ctor = WebCodeGenerator.AddConstructor(ImportContext.CodeTypeDeclaration, new string[0], new string[0], null, CodeFlags.IsPublic);
         ctor.Comments.Add(new CodeCommentStatement(Res.GetString(Res.CodeRemarks), true));
         bool soap11 = true;
         if (ImportContext is Soap12ProtocolImporter) {
             soap11 = false;
             // add version code
             CodeTypeReferenceExpression versionEnumTypeReference = new CodeTypeReferenceExpression(typeof(SoapProtocolVersion));
             CodeFieldReferenceExpression versionEnumFieldReference = new CodeFieldReferenceExpression(versionEnumTypeReference, Enum.Format(typeof(SoapProtocolVersion), SoapProtocolVersion.Soap12, "G"));
             CodePropertyReferenceExpression versionPropertyReference = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "SoapVersion");
             CodeAssignStatement assignVersionStatement = new CodeAssignStatement(versionPropertyReference, versionEnumFieldReference);
             ctor.Statements.Add(assignVersionStatement);
         }
         ServiceDescription serviceDescription = ImportContext.Binding.ServiceDescription;
         string url = (soapAddress != null) ? soapAddress.Location : null;
         string urlKey = serviceDescription.AppSettingUrlKey;
         string baseUrl = serviceDescription.AppSettingBaseUrl;
         ProtocolImporterUtil.GenerateConstructorStatements(ctor, url, urlKey, baseUrl, soap11 && !ImportContext.IsEncodedBinding);
     }
     else if (ImportContext.Style == ServiceDescriptionImportStyle.Server) {
         ImportContext.CodeTypeDeclaration.BaseTypes.Add(typeof(WebService).FullName);
     }
 }
        protected override CodeMemberMethod CreateService(CodeTypeReference typerefWCFService, CodeTypeReference typerefService)
        {
            CodeTypeReferenceExpression typerefexprService = new CodeTypeReferenceExpression(typerefService);
            CodeMethodReferenceExpression methodrefDbusServiceCreate = new CodeMethodReferenceExpression(typerefexprService, "Create");

            CodeMemberMethod methodCreateService = new CodeMemberMethod();
            methodCreateService.Name = CreateServiceName;
            methodCreateService.ReturnType = typerefWCFService;
            methodCreateService.Attributes = MemberAttributes.Static;
            methodCreateService.Parameters.Add(new CodeParameterDeclarationExpression(CodeBuilderCommon.typerefWCFServiceParams, nameWCFServiceParamsArg));
            CodeMethodReferenceExpression methodrefCreateDbusService = new CodeMethodReferenceExpression(CodeBuilderCommon.typerefexprLookupTargetFunctions, CodeBuilderCommon.CreateDbusService);
            methodrefCreateDbusService.TypeArguments.Add(typerefService);

            methodCreateService.Statements.Add(new CodeVariableDeclarationStatement(typerefService, dbusService, // * <dbus_service> dbusService =
                new CodeMethodInvokeExpression(methodrefCreateDbusService // * Udbus.WCF.Dbus.Service.LookupTargetFunctions.CreateDbusService(
                    , argrefWCFServiceParams // * wcfserviceparams
                    , methodrefDbusServiceCreate // * , <dbus_service>.Create // createService1
                    , methodrefDbusServiceCreate // * , <dbus_service>.Create // createService2
                    , new CodePropertyReferenceExpression(typerefexprService, CodeBuilderCommon.DefaultConnectionParameters) // * <dbus_service>.DefaultConnectionParameters);
                )
            ));

            // * <wcfservice> wcfService = new <wcfservice>(dbusservice);
            methodCreateService.Statements.Add(new CodeVariableDeclarationStatement(typerefWCFService, wcfService
                , new CodeObjectCreateExpression(typerefWCFService, varrefDbusService)
            ));

            // return wcfService;
            methodCreateService.Statements.Add(new CodeMethodReturnStatement(varrefWcfService));
            return methodCreateService;
        }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeTypeReference type = new CodeTypeReference ("System.Int32");
			CodeTypeReferenceExpression ctre = new CodeTypeReferenceExpression (type);
			Assert.AreSame (type, ctre.Type, "Type");
			ctre.Type = new CodeTypeReference ("System.Void");
		}
		void Init ()
		{
			unit = new CodeCompileUnit ();
			mainNS = new CodeNamespace ("ASP");
			unit.Namespaces.Add (mainNS);
			mainClass = new CodeTypeDeclaration (parser.ClassName);
			mainClass.TypeAttributes = TypeAttributes.Public;
			mainNS.Types.Add (mainClass);
			mainClass.BaseTypes.Add (new CodeTypeReference (parser.BaseType.FullName));
			mainClassExpr = new CodeTypeReferenceExpression ("ASP." + parser.ClassName);
			foreach (object o in parser.Imports) {
				if (o is string)
					mainNS.Imports.Add (new CodeNamespaceImport ((string) o));
			}

			if (parser.Assemblies != null) {
				foreach (object o in parser.Assemblies) {
					if (o is string)
						unit.ReferencedAssemblies.Add ((string) o);
				}
			}

			// Late-bound generators specifics (as for MonoBASIC/VB.NET)
			unit.UserData["RequireVariableDeclaration"] = parser.ExplicitOn;
			unit.UserData["AllowLateBound"] = !parser.StrictOn;
			
			AddInterfaces ();
			AddClassAttributes ();
			CreateStaticFields ();
			AddApplicationAndSessionObjects ();
			AddScripts ();
			CreateConstructor (null, null);
		}
 public static CodeTypeReferenceExpression Clone(this CodeTypeReferenceExpression expression)
 {
     if (expression == null) return null;
     CodeTypeReferenceExpression e = new CodeTypeReferenceExpression();
     e.Type = expression.Type.Clone();
     e.UserData.AddRange(expression.UserData);
     return e;
 }
        public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
        {
            string property = (string) parsedData;

            CodePrimitiveExpression prim = new CodePrimitiveExpression(property);
            CodeExpression[] args = new[] {prim};
            CodeTypeReferenceExpression refType = new CodeTypeReferenceExpression(this.GetType());
            return new CodeMethodInvokeExpression(refType, "GetProperty", args);
        }
        internal CodeConstructor CreateEmptyConstructor()
        {
            // Example:  new TestService() : this(NullAuthenticator.Instance)
            var constructor = new CodeConstructor();

            constructor.Attributes = MemberAttributes.Public;
            var nullAuthenticator = new CodeTypeReferenceExpression(typeof(NullAuthenticator));
            constructor.ChainedConstructorArgs.Add(new CodeFieldReferenceExpression(nullAuthenticator, "Instance"));
            return constructor;
        }
 public TypescriptTypeReferenceExpression(
     CodeTypeReferenceExpression codeExpression,
     CodeGeneratorOptions options,
     ITypescriptTypeMapper typescriptTypeMapper)
 {
     _codeExpression = codeExpression;
     _options = options;
     _typescriptTypeMapper = typescriptTypeMapper;
     System.Diagnostics.Debug.WriteLine("TypescriptTypeReferenceExpression Created");
 }
        public override CodeExpression GetCodeExpression(System.Web.UI.BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
        {
            _log.Write(_id, SPTraceLogger.TraceSeverity.InformationEvent, "GetCodeExpression", "Info", "Called");

            CodeTypeReferenceExpression thisType = new CodeTypeReferenceExpression(base.GetType());

            CodePrimitiveExpression expression = new CodePrimitiveExpression(entry.Expression.Trim().ToString());

            string evaluationMethod = "GetKeyValue";

            return new CodeMethodInvokeExpression(thisType, evaluationMethod, new CodeExpression[] { expression });
        }
        /// <summary>
        /// Generates code for value
        /// </summary>
        /// <param name="parentClass">The parent class.</param>
        /// <param name="method">The method.</param>
        /// <param name="value">The value.</param>
        /// <param name="baseName">Name of the base.</param>
        /// <param name="dictionary">The dictionary.</param>
        /// <returns></returns>
        public CodeExpression Generate(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName, ResourceDictionary dictionary = null)
        {
            CodeExpression valueExpression = null;
            if (value != null)
            {
                FontWeight fontWeight = (FontWeight)value;
                CodeTypeReferenceExpression typeReference = new CodeTypeReferenceExpression("FontStyle");
                valueExpression = new CodeFieldReferenceExpression(typeReference, fontWeight.ToString());
            }

            return valueExpression;
        }
		public void Constructor2 ()
		{
			string baseType = "mono";

			CodeTypeReferenceExpression ctre = new CodeTypeReferenceExpression (baseType);
			Assert.IsNotNull (ctre.Type, "#1");
			Assert.AreEqual (baseType, ctre.Type.BaseType, "#2");

			ctre = new CodeTypeReferenceExpression ((string) null);
			Assert.IsNotNull (ctre.Type, "#3");
			Assert.AreEqual (typeof (void).FullName, ctre.Type.BaseType, "#4");
		}
 internal static void GenerateConstructorStatements(CodeConstructor ctor, string url, string appSettingUrlKey, string appSettingBaseUrl, bool soap11)
 {
     bool flag = (url != null) && (url.Length > 0);
     bool flag2 = (appSettingUrlKey != null) && (appSettingUrlKey.Length > 0);
     CodeAssignStatement statement = null;
     if (flag || flag2)
     {
         CodeExpression expression;
         CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Url");
         if (flag)
         {
             expression = new CodePrimitiveExpression(url);
             statement = new CodeAssignStatement(left, expression);
         }
         if (flag && !flag2)
         {
             ctor.Statements.Add(statement);
         }
         else if (flag2)
         {
             CodeVariableReferenceExpression expression3 = new CodeVariableReferenceExpression("urlSetting");
             CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(typeof(ConfigurationManager));
             CodePropertyReferenceExpression expression5 = new CodePropertyReferenceExpression(targetObject, "AppSettings");
             expression = new CodeIndexerExpression(expression5, new CodeExpression[] { new CodePrimitiveExpression(appSettingUrlKey) });
             ctor.Statements.Add(new CodeVariableDeclarationStatement(typeof(string), "urlSetting", expression));
             if ((appSettingBaseUrl == null) || (appSettingBaseUrl.Length == 0))
             {
                 expression = expression3;
             }
             else
             {
                 if ((url == null) || (url.Length == 0))
                 {
                     throw new ArgumentException(Res.GetString("IfAppSettingBaseUrlArgumentIsSpecifiedThen0"));
                 }
                 string str = new Uri(appSettingBaseUrl).MakeRelative(new Uri(url));
                 CodeExpression[] parameters = new CodeExpression[] { expression3, new CodePrimitiveExpression(str) };
                 expression = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), "Concat", parameters);
             }
             CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, expression) };
             CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(expression3, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
             if (flag)
             {
                 ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[] { statement }));
             }
             else
             {
                 ctor.Statements.Add(new CodeConditionStatement(condition, trueStatements));
             }
         }
     }
 }
        public override void SetTestInitializeMethod(TestClassGenerationContext generationContext)
        {
            base.SetTestInitializeMethod(generationContext);

            // SenarioContext.Current.SetTestInstance(this);
            var scenarioContext = new CodeTypeReferenceExpression("ScenarioContext");
            var currentContext = new CodePropertyReferenceExpression(scenarioContext, "Current");
            var scenarioContextExtensions = new CodeTypeReferenceExpression("ScenarioContextExtensions");
            var setTestInstance = new CodeMethodInvokeExpression(scenarioContextExtensions, "SetTestInstance",
                currentContext, new CodeThisReferenceExpression());

            // Add it to ScenarioSetup
            generationContext.ScenarioInitializeMethod.Statements.Add(new CodeExpressionStatement(setTestInstance));
        }
示例#19
0
        static CodeGeneratorInternalClass()
        {
            CodeTypeReferenceExpression flagsType = new CodeTypeReferenceExpression ("System.Reflection.BindingFlags");
            bindingFlags = new CodeBinaryOperatorExpression (
                new CodeFieldReferenceExpression (flagsType, "Public"),
                CodeBinaryOperatorType.BitwiseOr,
                new CodeFieldReferenceExpression (flagsType, "NonPublic")
            );

            bindingFlags = new CodeBinaryOperatorExpression (
                bindingFlags,
                CodeBinaryOperatorType.BitwiseOr,
                new CodeFieldReferenceExpression (flagsType, "Instance")
            );
        }
 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     CodeExpression left = null;
     using (CodeDomSerializerBase.TraceScope("EnumCodeDomSerializer::Serialize"))
     {
         Enum[] enumArray;
         if (!(value is Enum))
         {
             return left;
         }
         bool flag = false;
         TypeConverter converter = TypeDescriptor.GetConverter(value);
         if ((converter != null) && converter.CanConvertTo(typeof(Enum[])))
         {
             enumArray = (Enum[]) converter.ConvertTo(value, typeof(Enum[]));
             flag = enumArray.Length > 1;
         }
         else
         {
             enumArray = new Enum[] { (Enum) value };
             flag = true;
         }
         CodeTypeReferenceExpression targetObject = new CodeTypeReferenceExpression(value.GetType());
         TypeConverter converter2 = new EnumConverter(value.GetType());
         foreach (Enum enum2 in enumArray)
         {
             string str = (converter2 != null) ? converter2.ConvertToString(enum2) : null;
             CodeExpression right = !string.IsNullOrEmpty(str) ? new CodeFieldReferenceExpression(targetObject, str) : null;
             if (right != null)
             {
                 if (left == null)
                 {
                     left = right;
                 }
                 else
                 {
                     left = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.BitwiseOr, right);
                 }
             }
         }
         if ((left != null) && flag)
         {
             left = new CodeCastExpression(value.GetType(), left);
         }
     }
     return left;
 }
 void CreateImportFor(bool isNestedSrc, IEnumerable<TypeDefinition> types, CodeMemberMethod method)
 {
     foreach (var type in types) {
         // If the library was written in F#, those resource ID classes are not nested but rather combined with '_'.
         var srcClassRef = new CodeTypeReferenceExpression (
             new CodeTypeReference (primary_name + (isNestedSrc ? '.' : '_') + type.Name, CodeTypeReferenceOptions.GlobalReference));
         // destination language may not support nested types, but they should take care of such types by themselves.
         var dstClassRef = new CodeTypeReferenceExpression (
             new CodeTypeReference (type.FullName.Replace ('/', '.'), CodeTypeReferenceOptions.GlobalReference));
         foreach (var field in type.Fields) {
             var dstField = new CodeFieldReferenceExpression (dstClassRef, field.Name);
             var srcField = new CodeFieldReferenceExpression (srcClassRef, field.Name);
             // This simply assigns field regardless of whether it is int or int[].
             method.Statements.Add (new CodeAssignStatement (dstField, srcField));
         }
     }
 }
        public virtual void SetScenarioSetup(CodeMemberMethod memberMethod)
        {
            //ScenarioContext
            var scenarioContext = new CodeTypeReferenceExpression("ScenarioContext");

            // .Current
            var currentContext = new CodePropertyReferenceExpression(scenarioContext, "Current");

            // ["SomeKey"]
            var indexer = new CodeIndexerExpression(currentContext, new CodePrimitiveExpression(CALLING_FEATURE_KEY));

            // = this;
            var assignMent = new CodeAssignStatement(indexer, new CodeThisReferenceExpression());

            //ScenarioContext.Current["SomeKey"] = this;
            memberMethod.Statements.Add(assignMent);
        }
		protected virtual void BuildPageClass (CodeTypeDeclaration codeType)
		{

			this.PageTypeReferenceExpression = new CodeTypeReferenceExpression (new CodeTypeReference (codeType.Name));

			AddPageBaseTypes (codeType.BaseTypes);
			AddPageFields (codeType.Members);
			AddPageProperties (codeType.Members);
         
			CodeTypeConstructor cctor = new CodeTypeConstructor ();
			cctor.CustomAttributes.Add (new CodeAttributeDeclaration (DebuggerNonUserCodeTypeReference));
			AddPageTypeCtorStatements (cctor.Statements);
         
			if (cctor.Statements.Count > 0)
				codeType.Members.Add (cctor);

			AddPageMethods (codeType.Members);
		}
 internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
 {
     CodeBinaryOperatorExpression expression2 = (CodeBinaryOperatorExpression) expression;
     RuleBinaryExpressionInfo info = analysis.Validation.ExpressionInfo(expression2) as RuleBinaryExpressionInfo;
     if (info != null)
     {
         MethodInfo methodInfo = info.MethodInfo;
         if (methodInfo != null)
         {
             List<CodeExpression> attributedExprs = new List<CodeExpression>();
             CodeExpressionCollection argExprs = new CodeExpressionCollection();
             argExprs.Add(expression2.Left);
             argExprs.Add(expression2.Right);
             CodeExpression targetExpr = new CodeTypeReferenceExpression(methodInfo.DeclaringType);
             analysis.AnalyzeRuleAttributes(methodInfo, targetExpr, qualifier, argExprs, methodInfo.GetParameters(), attributedExprs);
         }
     }
     RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Left, true, false, null);
     RuleExpressionWalker.AnalyzeUsage(analysis, expression2.Right, true, false, null);
 }
		public void Constructor1 ()
		{
			CodeTypeReference type1 = new CodeTypeReference ("mono1");

			CodeTypeReferenceExpression ctre = new CodeTypeReferenceExpression (type1);
			Assert.IsNotNull (ctre.Type, "#1");
			Assert.AreSame (type1, ctre.Type, "#2");

			ctre.Type = null;
			Assert.IsNotNull (ctre.Type, "#3");
			Assert.AreEqual (typeof (void).FullName, ctre.Type.BaseType, "#4");

			CodeTypeReference type2 = new CodeTypeReference ("mono2");
			ctre.Type = type2;
			Assert.IsNotNull (ctre.Type, "#5");
			Assert.AreSame (type2, ctre.Type, "#6");

			ctre = new CodeTypeReferenceExpression ((CodeTypeReference) null);
			Assert.IsNotNull (ctre.Type, "#7");
			Assert.AreEqual (typeof (void).FullName, ctre.Type.BaseType, "#8");
		}
示例#26
0
	    protected override void Emit (CodeTypeDeclaration type)
	    {
		type.CustomAttributes.Add (new CodeAttributeDeclaration ("System.Serializable"));

		// Initialized constructor

		CodeFieldReferenceExpression left = CDH.ThisDot ("Value");

		CodeConstructor ctor = EmitEmptyCtor (type);
		ctor.Parameters.Add (CDH.Param (etype, "init"));
		ctor.Statements.Add (new CodeAssignStatement (left, CDH.VRef ("init")));

		// Default constructor.

		ctor = EmitEmptyCtor (type);

		CodeTypeReferenceExpression tre = 
		    new CodeTypeReferenceExpression (etype.AsCodeDom);
		CodeFieldReferenceExpression right = 
		    new CodeFieldReferenceExpression (tre, DefaultName);
		ctor.Statements.Add (new CodeAssignStatement (left, right));
	    }
示例#27
0
    public static System.CodeDom.CodeCompileUnit BuildGraph()
    {
        System.CodeDom.CodeCompileUnit CompileUnit = new System.CodeDom.CodeCompileUnit();

        System.CodeDom.CodeNamespace nSpace = new System.CodeDom.CodeNamespace("HelloWorldViaCodeDOM");
        CompileUnit.Namespaces.Add(nSpace);

        nSpace.Imports.Add(new System.CodeDom.CodeNamespaceImport("System"));

        System.CodeDom.CodeTypeDeclaration clsStartup = new System.CodeDom.CodeTypeDeclaration("Startup");
        nSpace.Types.Add(clsStartup);

        System.CodeDom.CodeEntryPointMethod        main   = new System.CodeDom.CodeEntryPointMethod();
        System.CodeDom.CodePrimitiveExpression     exp    = new System.CodeDom.CodePrimitiveExpression("Hello World!");
        System.CodeDom.CodeTypeReferenceExpression refExp = new System.CodeDom.CodeTypeReferenceExpression("System.Console");
        System.CodeDom.CodeMethodInvokeExpression  invoke = new System.CodeDom.CodeMethodInvokeExpression(refExp, "WriteLine", exp);
        main.Statements.Add(new System.CodeDom.CodeExpressionStatement(invoke));

        clsStartup.Members.Add(main);

        return(CompileUnit);
    }
        internal CodeMemberMethod CreateRegisterSerializer()
        {
            const string VAR_NAME = "serializer";
            var genericService = new CodeTypeReferenceExpression(ServiceClassGenerator.GenericServiceName);

            // public void RegisterSerializer(ISerializer serializer)
            var method = new CodeMemberMethod();
            method.Name = RegisterSerializerMethodName;
            method.Attributes = MemberAttributes.Public;
            method.Parameters.Add(
                new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(ISerializer)), VAR_NAME));
            method.ReturnType = new CodeTypeReference(typeof(void));

            // genericService.Serializer = serializer;
            var propertySet = new CodeAssignStatement();
            propertySet.Left = new CodePropertyReferenceExpression(genericService, BaseService.SerializerPropertyName);
            propertySet.Right = new CodeVariableReferenceExpression(VAR_NAME);

            // Add the statement to the method
            method.Statements.Add(propertySet);

            return method;
        }
示例#29
0
        static CodeMemberProperty GetIndexer()
        {
            var indexer = new CodeMemberProperty();
            indexer.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            indexer.Name = "Item";
            indexer.Type = new CodeTypeReference(typeof(object));
            indexer.HasSet = true;
            indexer.HasGet = true;
            indexer.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(string)), "field"));

            //return RecordHelper.Get(this, field);
            //RecordHelper.Set(this, field, value);
            var helper = new CodeTypeReferenceExpression("RecordHelper");
            var field = new CodeVariableReferenceExpression("field");
            var _this = new CodeThisReferenceExpression();
            var value = new CodeVariableReferenceExpression("value");

            var g = new CodeMethodInvokeExpression(helper, "Get", _this, field);
            indexer.GetStatements.Add(new CodeMethodReturnStatement(g));

            var s = new CodeMethodInvokeExpression(helper, "Set", _this, field, value);
            indexer.SetStatements.Add(s);
            return indexer;
        }
 private static CodePropertyReferenceExpression DeserializeApplicationSettingsExpression(string[] expressionParts)
 {
     int index = expressionParts.Length - 1;
     CodePropertyReferenceExpression expression = new CodePropertyReferenceExpression {
         PropertyName = expressionParts[index]
     };
     index--;
     CodePropertyReferenceExpression expression2 = new CodePropertyReferenceExpression();
     expression.TargetObject = expression2;
     expression2.PropertyName = expressionParts[index];
     index--;
     CodeTypeReferenceExpression expression3 = new CodeTypeReferenceExpression();
     expression2.TargetObject = expression3;
     expression3.Type.Options = (CodeTypeReferenceOptions) Enum.Parse(typeof(CodeTypeReferenceOptions), expressionParts[index]);
     index--;
     expression3.Type.BaseType = expressionParts[index];
     index--;
     while (index > 0)
     {
         expression3.Type.BaseType = expressionParts[index] + "." + expression3.Type.BaseType;
         index--;
     }
     return expression;
 }
示例#31
0
 /// <summary>
 /// Creates the instance.
 /// </summary>
 /// <param name="type">The instance type.</param>
 /// <param name="ctorParams">The ctor params.</param>
 /// <returns>return code of new objectinstance</returns>
 internal static CodeObjectCreateExpression CreateInstance(Type type, CodeTypeReferenceExpression[] ctorParams)
 {
     return new CodeObjectCreateExpression(new CodeTypeReference(type), ctorParams);
 }
        public void GCode_CodeDom_GenerateCode(CodeTypeDeclaration codeClass, CodeStatementCollection codeStatementCollection, CodeExpression expression, string strValueName)
        {
            GetGradientDatas();
            if (GradientDatas.Count > 1)
            {
                for (int i = 1; i < GradientDatas.Count; i++)
                {
                    var value   = expression;
                    var offset1 = GradientDatas[i - 1].Offset;
                    var color1  = GradientDatas[i - 1].GradientColor;
                    var offset2 = GradientDatas[i].Offset;
                    var color2  = GradientDatas[i].GradientColor;

                    CodeObjectCreateExpression color1obj = new CodeObjectCreateExpression("EngineNS.Color4", new CodeExpression[] { });
                    color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Alpha));
                    color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Red));
                    color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Green));
                    color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Blue));

                    CodeObjectCreateExpression color2obj = new CodeObjectCreateExpression("EngineNS.Color4", new CodeExpression[] { });
                    color2obj.Parameters.Add(new CodePrimitiveExpression(color2.Alpha));
                    color2obj.Parameters.Add(new CodePrimitiveExpression(color2.Red));
                    color2obj.Parameters.Add(new CodePrimitiveExpression(color2.Green));
                    color2obj.Parameters.Add(new CodePrimitiveExpression(color2.Blue));

                    //"t = (value - offset1) / (offset2 - offset1) "
                    CodeBinaryOperatorExpression v1 = new CodeBinaryOperatorExpression(
                        value,
                        CodeBinaryOperatorType.Subtract,
                        new CodePrimitiveExpression(offset2));

                    CodeBinaryOperatorExpression v2 = new CodeBinaryOperatorExpression(
                        new CodePrimitiveExpression(offset1),
                        CodeBinaryOperatorType.Subtract,
                        new CodePrimitiveExpression(offset2));

                    CodeBinaryOperatorExpression v3 = new CodeBinaryOperatorExpression(
                        v1,
                        CodeBinaryOperatorType.Divide,
                        v2);

                    var typeref = new System.CodeDom.CodeTypeReferenceExpression("EngineNS.Color4");
                    //Lerp( Color4 color1, Color4 color2, float amount )
                    var methodInvoke = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(
                        // targetObject that contains the method to invoke.
                        typeref,
                        // methodName indicates the method to invoke.
                        "Lerp",
                        // parameters array contains the parameters for the method.
                        new CodeExpression[] { color2obj, color1obj, v3 });

                    CodeAssignStatement result = new CodeAssignStatement(new CodeVariableReferenceExpression(strValueName), methodInvoke);
                    //  CodeBinaryOperatorExpression result = new CodeBinaryOperatorExpression(
                    //new CodeVariableReferenceExpression(strValueName),
                    // CodeBinaryOperatorType.Assign,
                    // methodInvoke);

                    var greaterthan = new CodeBinaryOperatorExpression(
                        value,
                        CodeBinaryOperatorType.GreaterThan,
                        new CodePrimitiveExpression(offset2));

                    var lessthan = new CodeBinaryOperatorExpression(
                        value,
                        CodeBinaryOperatorType.LessThan,
                        new CodePrimitiveExpression(offset1));

                    if (i == GradientDatas.Count - 1)
                    {
                        var first = new CodeBinaryOperatorExpression(
                            value,
                            CodeBinaryOperatorType.LessThanOrEqual,
                            new CodePrimitiveExpression(offset2));

                        codeStatementCollection.Add(new CodeConditionStatement(
                                                        first,
                                                        new CodeAssignStatement(new CodeVariableReferenceExpression(strValueName), color2obj)));
                    }

                    if (i == 1)
                    {
                        var last = new CodeBinaryOperatorExpression(
                            value,
                            CodeBinaryOperatorType.GreaterThanOrEqual,
                            new CodePrimitiveExpression(offset1));

                        codeStatementCollection.Add(new CodeConditionStatement(
                                                        last,
                                                        new CodeAssignStatement(new CodeVariableReferenceExpression(strValueName), color1obj)));
                    }
                    codeStatementCollection.Add(new CodeConditionStatement(
                                                    new CodeBinaryOperatorExpression(greaterthan, CodeBinaryOperatorType.BooleanAnd, lessthan),
                                                    result));
                }
            }
            else if (GradientDatas.Count == 1)
            {
                var color1 = GradientDatas[0].GradientColor;

                CodeObjectCreateExpression color1obj = new CodeObjectCreateExpression("EngineNS.Color4", new CodeExpression[] { });
                color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Alpha));
                color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Red));
                color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Green));
                color1obj.Parameters.Add(new CodePrimitiveExpression(color1.Blue));

                codeStatementCollection.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(strValueName), color1obj));
            }
        }