static IntPtr GetAddressOfValueField(ValueConstruct parameter) { unsafe { ValueConstruct *pointer = ¶meter; return((IntPtr)pointer); } }
public void you_should_know_the_behavior_of_passing_by_value() { var value = new ValueConstruct(); IntPtr argumentAddress = GetAddressOfValueField(value); unsafe { ValueConstruct *pointerToValue = &value; IntPtr valueAddress = (IntPtr)pointerToValue; // Please correct this line to pass the test. bool?areEqual = false; Assert.Equal(areEqual, argumentAddress == valueAddress); // Output some information to make you feel better output.WriteLine($"The value address is 0x{valueAddress.ToInt64():x}"); output.WriteLine($"The argument address is 0x{argumentAddress.ToInt64():x}"); } }
public void then_you_can_guess_what_in_parameter_behaves() { var value = new ValueConstruct(); IntPtr argumentAddress = GetAddressOfValueField(in value); unsafe { ValueConstruct *pointerToValue = &value; var valueAddress = (IntPtr)pointerToValue; // Please correct this line to pass the test. bool?areEqual = null; Assert.Equal(areEqual, valueAddress == argumentAddress); // Output some information to make you feel better output.WriteLine($"The value address is 0x{valueAddress.ToInt64():x}"); output.WriteLine($"The argument address is 0x{argumentAddress.ToInt64():x}"); } }
protected override void CoreExpandTemplate(ITemplatingContext templatingContext) { string aqtn; DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; ISourceStrategy sourceStrategy; Type sourceStrategyType; string sourceFilePath, var; object source; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy(); aqtn = templatingContext.Tokenizer.ExpandTokens(this.AssemblyQualifiedTypeName, dynamicWildcardTokenReplacementStrategy); sourceFilePath = templatingContext.Tokenizer.ExpandTokens(this.SourceFilePath, dynamicWildcardTokenReplacementStrategy); var = templatingContext.Tokenizer.ExpandTokens(this.Var, dynamicWildcardTokenReplacementStrategy); sourceStrategyType = Type.GetType(aqtn, false); if ((object)sourceStrategyType == null) { throw new InvalidOperationException(string.Format("Failed to load the source strategy type '{0}' via Type.GetType(..).", aqtn)); } if (!typeof(ISourceStrategy).IsAssignableFrom(sourceStrategyType)) { throw new InvalidOperationException(string.Format("The source strategy type is not assignable to type '{0}'.", typeof(ISourceStrategy).FullName)); } sourceStrategy = (ISourceStrategy)Activator.CreateInstance(sourceStrategyType); source = sourceStrategy.GetSourceObject(/*templatingContext, */ sourceFilePath, templatingContext.Properties); if (!this.UseAlloc) { templatingContext.IteratorModels.Push(source); if ((object)this.Items != null) { foreach (ITemplateMechanism templateMechanism in this.Items) { templateMechanism.ExpandTemplate(templatingContext); } } templatingContext.IteratorModels.Pop(); } else { if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(var)) { IExpressionContainerConstruct expressionContainerConstruct; ValueConstruct valueConstruct; new AllocConstruct() { Token = var }.ExpandTemplate(templatingContext); expressionContainerConstruct = new ExpressionContainerConstruct(); valueConstruct = new ValueConstruct() { __ = source }; ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct; new AssignConstruct() { Token = var, Expression = expressionContainerConstruct }.ExpandTemplate(templatingContext); } } }
protected override void CoreExpandTemplate(ITemplatingContext templatingContext) { const uint MAX_ITERATIONS_INFINITE_LOOP_CHECK = 999999; string varIx; uint index = 1; // one-based DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy(); varIx = templatingContext.Tokenizer.ExpandTokens(this.VarIx, dynamicWildcardTokenReplacementStrategy); if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx)) { new AllocConstruct() { Token = varIx }.ExpandTemplate(templatingContext); } this.CoreConditionalIterationInitialize(templatingContext); // DO NOT USE REAL FOR LOOP HERE while (true) { if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx)) { IExpressionContainerConstruct expressionContainerConstruct; ValueConstruct valueConstruct; expressionContainerConstruct = new ExpressionContainerConstruct(); valueConstruct = new ValueConstruct() { Type = typeof(int).FullName, __ = index }; ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct; new AssignConstruct() { Token = varIx, Expression = expressionContainerConstruct }.ExpandTemplate(templatingContext); } if (index > MAX_ITERATIONS_INFINITE_LOOP_CHECK) { throw new InvalidOperationException(string.Format("The conditional iteration construct has exceeded the maximun number of iterations '{0}'; this is an infinite loop prevention mechansim.", MAX_ITERATIONS_INFINITE_LOOP_CHECK)); } if (this.Precondition) { if (!this.CheckCondition(templatingContext)) { break; } } if ((object)this.Body != null) { this.Body.ExpandTemplate(templatingContext); } this.CoreConditionalIterationStep(templatingContext, index); if (!this.Precondition) { if (!this.CheckCondition(templatingContext)) { break; } } index++; } this.CoreConditionalIterationTerminate(templatingContext); if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx)) { new FreeConstruct() { Token = varIx }.ExpandTemplate(templatingContext); } }
protected override void CoreExpandTemplate(ITemplatingContext templatingContext) { string @in, varCt, varItem, varIx; uint count = 0, index = 1; // one-based IEnumerable values; object obj; DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy(); @in = templatingContext.Tokenizer.ExpandTokens(this.In, dynamicWildcardTokenReplacementStrategy); varItem = templatingContext.Tokenizer.ExpandTokens(this.VarItem, dynamicWildcardTokenReplacementStrategy); varCt = templatingContext.Tokenizer.ExpandTokens(this.VarCt, dynamicWildcardTokenReplacementStrategy); varIx = templatingContext.Tokenizer.ExpandTokens(this.VarIx, dynamicWildcardTokenReplacementStrategy); if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varItem)) { new AllocConstruct() { Token = varItem }.ExpandTemplate(templatingContext); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varCt)) { new AllocConstruct() { Token = varCt }.ExpandTemplate(templatingContext); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx)) { new AllocConstruct() { Token = varIx }.ExpandTemplate(templatingContext); } if (!dynamicWildcardTokenReplacementStrategy.GetByToken(@in, out obj)) { throw new InvalidOperationException(string.Format("The facet name '{0}' was not found on the target model.", @in)); } if ((object)obj == null) { return; } if (!(obj is IEnumerable)) { throw new InvalidOperationException(string.Format("The in expression the for-each construct is not assignable to type '{0}'.", typeof(IEnumerable).FullName)); } values = (IEnumerable)obj; obj = null; // not needed if ((object)this.Filter != null) { ArrayList temp; bool shouldFilter; temp = new ArrayList(); if ((object)values != null) { foreach (object value in values) { templatingContext.IteratorModels.Push(value); obj = this.Filter.EvaluateExpression(templatingContext); templatingContext.IteratorModels.Pop(); if ((object)obj != null && !(obj is bool) && !(obj is bool?)) { throw new InvalidOperationException(string.Format("The for-each construct filter expression has evaluated to a non-null value with an unsupported type '{0}'; only '{1}' and '{2}' types are supported.", value.GetType().FullName, typeof(bool).FullName, typeof(bool?).FullName)); } shouldFilter = !((bool)(obj ?? true)); if (!shouldFilter) { count++; temp.Add(value); } } } values = temp; } else { if ((object)values != null) { foreach (object value in values) { count++; } } } if ((object)this.Sort != null) { values = this.Sort.EvaluateSort(templatingContext, values); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varCt)) { IExpressionContainerConstruct expressionContainerConstruct; ValueConstruct valueConstruct; expressionContainerConstruct = new ExpressionContainerConstruct(); valueConstruct = new ValueConstruct() { Type = typeof(int).FullName, __ = count }; ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct; new AssignConstruct() { Token = varCt, Expression = expressionContainerConstruct }.ExpandTemplate(templatingContext); } if ((object)values != null) { foreach (object value in values) { if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varItem)) { IExpressionContainerConstruct expressionContainerConstruct; ValueConstruct valueConstruct; expressionContainerConstruct = new ExpressionContainerConstruct(); valueConstruct = new ValueConstruct() { __ = value }; ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct; new AssignConstruct() { Token = varItem, Expression = expressionContainerConstruct }.ExpandTemplate(templatingContext); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx)) { IExpressionContainerConstruct expressionContainerConstruct; ValueConstruct valueConstruct; expressionContainerConstruct = new ExpressionContainerConstruct(); valueConstruct = new ValueConstruct() { Type = typeof(int).FullName, __ = index }; ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct; new AssignConstruct() { Token = varIx, Expression = expressionContainerConstruct }.ExpandTemplate(templatingContext); } templatingContext.IteratorModels.Push(value); if ((object)this.Body != null) { this.Body.ExpandTemplate(templatingContext); } templatingContext.IteratorModels.Pop(); index++; } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varIx)) { new FreeConstruct() { Token = varIx }.ExpandTemplate(templatingContext); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varCt)) { new FreeConstruct() { Token = varCt }.ExpandTemplate(templatingContext); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(varItem)) { new FreeConstruct() { Token = varItem }.ExpandTemplate(templatingContext); } } }
protected override void CoreExpandTemplate(ITemplatingContext templatingContext) { string scopeName; bool appendMode; Encoding encoding; DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetDynamicWildcardTokenReplacementStrategy(); scopeName = templatingContext.Tokenizer.ExpandTokens(this.ScopeName, dynamicWildcardTokenReplacementStrategy); appendMode = this.Append; if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(this.EncodingName)) { encoding = Encoding.GetEncoding(this.EncodingName); } else { encoding = Encoding.UTF8; } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(scopeName)) { new AllocConstruct() { Token = "#OutputScopeName" }.ExpandTemplate(templatingContext); } if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(scopeName)) { IExpressionContainerConstruct expressionContainerConstruct; ValueConstruct valueConstruct; expressionContainerConstruct = new ExpressionContainerConstruct(); valueConstruct = new ValueConstruct() { Type = typeof(string).FullName, __ = scopeName }; ((IContentContainerXmlObject <IExpressionXmlObject>)expressionContainerConstruct).Content = valueConstruct; new AssignConstruct() { Token = "#OutputScopeName", Expression = expressionContainerConstruct }.ExpandTemplate(templatingContext); } templatingContext.Output.LogTextWriter.WriteLine("['{0:O}' (UTC)]\tEntering output scope '{1}'.", DateTime.UtcNow, scopeName); templatingContext.Output.EnterScope(scopeName, appendMode, encoding); if ((object)this.Items != null) { foreach (ITemplateMechanism templateMechanism in this.Items) { templateMechanism.ExpandTemplate(templatingContext); } } templatingContext.Output.LeaveScope(scopeName); templatingContext.Output.LogTextWriter.WriteLine("['{0:O}' (UTC)]\tLeaving output scope '{1}'.", DateTime.UtcNow, scopeName); if (!SolderFascadeAccessor.DataTypeFascade.IsNullOrWhiteSpace(scopeName)) { new FreeConstruct() { Token = "#OutputScopeName" }.ExpandTemplate(templatingContext); } }