本文整理汇总了C#中ICodeBlock.End方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeBlock.End方法的具体用法?C# ICodeBlock.End怎么用?C# ICodeBlock.End使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeBlock
的用法示例。
在下文中一共展示了ICodeBlock.End方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateInterpolateBetween
private void GenerateInterpolateBetween(ElementSave elementSave, ICodeBlock currentBlock,
string enumType, IEnumerable<StateSave> states)
{
// We used to only generate these if there was were any states in this category, but
// since Gum generated code supports dynamic states, there could be states in a category
// even if they're not defined in Gum.
//if (states.Count() > 0)
{
currentBlock = currentBlock.Function("public void",
"InterpolateBetween", enumType + " firstState, " + enumType + " secondState, float interpolationValue");
GenerateDebugCheckForInterpolationValueNaN(currentBlock);
Dictionary<VariableSave, InterpolationCharacteristic> interpolationCharacteristics =
new Dictionary<VariableSave, InterpolationCharacteristic>();
CreateStartingValueVariables(elementSave, states, currentBlock, interpolationCharacteristics);
currentBlock = currentBlock.Switch("firstState");
currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock,
interpolationCharacteristics, FirstValue);
currentBlock = currentBlock.End();
currentBlock = currentBlock.Switch("secondState");
currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock,
interpolationCharacteristics, SecondValue);
currentBlock = currentBlock.End();
currentBlock = AssignValuesUsingStartingValues(elementSave, currentBlock, interpolationCharacteristics);
currentBlock = currentBlock.If("interpolationValue < 1");
string fieldToAssign;
if (enumType == "VariableState")
{
fieldToAssign = "mCurrentVariableState";
}
else
{
fieldToAssign = "mCurrent" + enumType + "State";
}
currentBlock.Line(fieldToAssign + " = firstState;");
currentBlock = currentBlock.End().Else();
currentBlock.Line(fieldToAssign + " = secondState;");
currentBlock = currentBlock.End();
}
}
示例2: GenerateAdditionalMethods
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
{
//////////////////////////EARLY OUT//////////////////////////////////////
if (element is ScreenSave)
{
return codeBlock;
}
///////////////////////END EARLY OUT/////////////////////////////////////
codeBlock = codeBlock.Function("public void", "MoveToLayer", "Layer layerToMoveTo");
foreach (NamedObjectSave nos in element.NamedObjects)
{
if (!nos.IsDisabled)
{
if (nos.GetAssetTypeInfo() != null && !string.IsNullOrEmpty(nos.GetAssetTypeInfo().RemoveFromLayerMethod))
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
bool shouldSkip = GetShouldSkip(nos);
if (!shouldSkip)
{
codeBlock.If("LayerProvidedByContainer != null")
.Line(nos.GetAssetTypeInfo().RemoveFromLayerMethod.Replace("this", nos.InstanceName).Replace("mLayer", "LayerProvidedByContainer") + ";")
.End();
codeBlock.Line(nos.GetAssetTypeInfo().LayeredAddToManagersMethod[0].Replace("this", nos.InstanceName).Replace("mLayer", "layerToMoveTo") + ";");
}
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
}
else if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType))
{
NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos);
codeBlock.Line(nos.InstanceName + ".MoveToLayer(layerToMoveTo);");
NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos);
}
}
}
codeBlock.Line("LayerProvidedByContainer = layerToMoveTo;");
codeBlock = codeBlock.End();
return codeBlock;
}
示例3: GenerateAdditionalMethods
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, IElement element)
{
if (element is EntitySave)
{
EntitySave entitySave = (EntitySave)element;
if (entitySave.IsScrollableEntityList && !string.IsNullOrEmpty(entitySave.ItemType))
{
string itemTypeWithoutPath = FileManager.RemovePath(entitySave.ItemType);
string visibleSettingLine = "";
if (entitySave.ImplementsIVisible)
{
visibleSettingLine = "newItem.Visible = this.Visible;";
}
#region AddItemToTop
codeBlock
.Function("void", "AddItemToTop", "")
.Line(string.Format("{0} newItem = Factories.{0}Factory.CreateNew(LayerProvidedByContainer);", itemTypeWithoutPath))
.Line(visibleSettingLine)
.Line("mLastCreatedScrollableItem = newItem;")
.Line("newItem.AttachTo(mScrollableHandle, false);")
.If("mScrollableItems.Count > 0")
.Line("newItem.RelativeY = mScrollableItems[0].RelativeY + mScrollableSpacing;")
.End()
.Line("newItem.ForceUpdateDependencies();")
.Line("mScrollableFirstIndex--;")
.Line("mScrollableItems.Insert(0, newItem);")
.If("ScrollItemModified != null")
.Line("ScrollItemModified(newItem);")
.End()
.Line("mLastCreatedScrollableItem = null;")
.End()
#endregion
#region AddItemToBottom
.Function("void", "AddItemToBottom", "")
.Line(string.Format("{0} newItem = Factories.{0}Factory.CreateNew(LayerProvidedByContainer);", itemTypeWithoutPath))
.Line("mLastCreatedScrollableItem = newItem;")
.Line("newItem.AttachTo(mScrollableHandle, false);")
.If("mScrollableItems.Count > 0")
.Line("newItem.RelativeY = mScrollableItems.Last.RelativeY - mScrollableSpacing;")
.End()
.Else()
.Line("newItem.RelativeY = 0;")
.End()
.Line("newItem.ForceUpdateDependencies();")
.Line("mScrollableItems.Add(newItem);")
.If("ScrollItemModified != null")
.Line("ScrollItemModified(newItem);")
.End()
.Line("mLastCreatedScrollableItem = null;")
.End();
#endregion
codeBlock = codeBlock.Function("void", "ScrollableListActivity", "");
var curBlock = codeBlock
.If("ListShowing != null")
.Line("FlatRedBall.Gui.Cursor cursor = FlatRedBall.Gui.GuiManager.Cursor;");
if (entitySave.ImplementsIClickable || entitySave.ImplementsIWindow || entitySave.GetInheritsFromIWindowOrIClickable())
{
curBlock = curBlock.If("cursor.PrimaryDown && HasCursorOver(GuiManager.Cursor)");
}
else
{
curBlock = curBlock.If("cursor.PrimaryDown");
}
curBlock = curBlock
.Line("mScrollableHandle.RelativeY += FlatRedBall.Gui.GuiManager.Cursor.WorldYChangeAt(this.Z, LayerProvidedByContainer);")
.Line("FixScrollableHandleRelativeY();")
.Line("mScrollableHandle.ForceUpdateDependenciesDeep();")
.End();
curBlock
.Line("PerformScrollableItemAdditionLogic();")
.Line("// remove from top")
.While("mScrollableItems.Count > 2 && mScrollableItems[1].Y > mScrollableTopBoundary")
.Line("RemoveItemFromTop();")
.End()
.Line("// remove from bottom")
.While("mScrollableItems.Count > 2 && mScrollableItems[mScrollableItems.Count - 2].Y < mScrollableBottomBoundary")
.Line("RemoveItemFromBottom();")
.End()
.Line("bool shouldRefreshAll = false;")
.While("ListShowing.Count < mScrollableItems.Count")
.Line("RemoveItemFromBottom();")
.Line("shouldRefreshAll = true;")
//.........这里部分代码省略.........
示例4: AppendEnum
private static ICodeBlock AppendEnum(ICodeBlock currentBlock, List<StateSave> statesForThisCategory, string enumName, IElement element)
{
if (statesForThisCategory.Count != 0)
{
string prefix = "public";
if (ShouldUseNewKeyword(element, enumName))
{
prefix += " new";
}
currentBlock = currentBlock
.Enum(prefix, enumName)
.Line("Uninitialized = 0, //This exists so that the first set call actually does something")
.Line("Unknown = 1, //This exists so that if the entity is actually a child entity and has set a child state, you will get this");
for (int i = 0; i < statesForThisCategory.Count; i++)
{
string whatToAppend = "";
if (i != statesForThisCategory.Count - 1)
{
whatToAppend += ", ";
}
currentBlock.Line(statesForThisCategory[i].Name + " = " + (i + 2) + whatToAppend);
}
currentBlock = currentBlock.End();
}
return currentBlock;
}
示例5: AssignValuesUsingStartingValues
private ICodeBlock AssignValuesUsingStartingValues(ElementSave element, ICodeBlock curBlock, Dictionary<VariableSave, InterpolationCharacteristic> mInterpolationCharacteristics)
{
foreach (KeyValuePair<VariableSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
{
var variable = kvp.Key;
if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
{
string stringSuffix = variable.MemberNameInCode(element, mVariableNamesToReplaceForStates).Replace(".", "");
curBlock = curBlock.If("set" + stringSuffix + FirstValue + " && set" + stringSuffix + SecondValue);
AddAssignmentForInterpolationForVariable(curBlock, variable, element);
curBlock = curBlock.End();
}
}
return curBlock;
}
示例6: CreateInstructionForInterpolationRelative
private void CreateInstructionForInterpolationRelative(StateCodeGeneratorContext context, ICodeBlock currentBlock, AnimatedStateSave previousState, AnimatedStateSave currentState)
{
if(previousState != null)
{
currentBlock.Line("var toReturn = new FlatRedBall.Instructions.DelegateInstruction(() =>");
{
currentBlock = currentBlock.Block();
// Is the start clone necessary?
currentBlock.Line("var relativeStart = ElementSave.AllStates.FirstOrDefault(item => item.Name == \"" + previousState.StateName + "\").Clone();");
currentBlock.Line("var relativeEnd = ElementSave.AllStates.FirstOrDefault(item => item.Name == \"" + currentState.StateName + "\").Clone();");
currentBlock.Line("Gum.DataTypes.Variables.StateSaveExtensionMethods.SubtractFromThis(relativeEnd, relativeStart);");
currentBlock.Line("var difference = relativeEnd;");
string categoryName = "VariableState";
var category = context.Element.Categories.FirstOrDefault(item => item.States.Any(stateCandidate => stateCandidate.Name == currentState.StateName));
string enumValue = currentState.StateName;
if(currentState.StateName.Contains('/'))
{
var split = currentState.StateName.Split('/');
category = context.Element.Categories.FirstOrDefault(item => item.Name == split[0]);
enumValue = split[1];
}
if(category != null)
{
categoryName = category.Name;
}
currentBlock.Line("Gum.DataTypes.Variables.StateSave first = GetCurrentValuesOnState(" + categoryName + "." + enumValue + ");");
currentBlock.Line("Gum.DataTypes.Variables.StateSave second = first.Clone();");
currentBlock.Line("Gum.DataTypes.Variables.StateSaveExtensionMethods.AddIntoThis(second, difference);");
string interpolationTime = ToFloatString(currentState.Time - previousState.Time);
string easing = "FlatRedBall.Glue.StateInterpolation.Easing." + previousState.Easing;
string interpolationType = "FlatRedBall.Glue.StateInterpolation.InterpolationType." + previousState.InterpolationType;
currentBlock.Line(
string.Format("FlatRedBall.Glue.StateInterpolation.Tweener tweener = new FlatRedBall.Glue.StateInterpolation.Tweener(from: 0, to: 1, duration: {0}, type: {1}, easing: {2});",
interpolationTime,
interpolationType,
easing));
currentBlock.Line("tweener.Owner = this;");
currentBlock.Line("tweener.PositionChanged = newPosition => this.InterpolateBetween(first, second, newPosition);");
currentBlock.Line("tweener.Start();");
currentBlock.Line("StateInterpolationPlugin.TweenerManager.Self.Add(tweener);");
currentBlock = currentBlock.End();
}
currentBlock.Line(");");
string previousStateTime = ToFloatString(previousState.Time);
currentBlock.Line("toReturn.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + " + previousStateTime + ";");
currentBlock.Line("yield return toReturn;");
}
}
示例7: CreateInstructionForSubAnimation
private static void CreateInstructionForSubAnimation(ICodeBlock currentBlock, AnimationReferenceSave animationReferenceSave, AbsoluteOrRelative absoluteOrRelative, AnimationSave parentAnimation)
{
currentBlock = currentBlock.Block();
//var instruction = new FlatRedBall.Instructions.DelegateInstruction(() =>
//FlatRedBall.Instructions.InstructionManager.Instructions.AddRange(ClickableBushInstance.GrowAnimation));
//instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + asdf;
//yield return instruction;
string animationName = animationReferenceSave.PropertyNameInCode();
//animationReferenceSave. FlatRedBall.IO.FileManager.RemovePath(animationReferenceSave.Name) + "Animation";
if(absoluteOrRelative == AbsoluteOrRelative.Relative)
{
animationName += "Relative";
}
currentBlock.Line($"var instruction = new FlatRedBall.Instructions.DelegateInstruction(()=>{animationName}.Play({parentAnimation.PropertyNameInCode()}));");
currentBlock.Line("instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + " + ToFloatString(animationReferenceSave.Time) + ";");
currentBlock.Line("yield return instruction;");
currentBlock = currentBlock.End();
}
示例8: GenerateAddToManagersBottomUp
internal static void GenerateAddToManagersBottomUp(ICodeBlock codeBlock, IElement element)
{
foreach (EventResponseSave ers in element.Events)
{
EventSave eventSave = ers.GetEventSave();
// Right now I'm hardcoding this event, but eventually we may want to pull this value from the data
// if it's something we want to support on other events
bool raiseInAddToManagers = eventSave != null && eventSave.EventName == "ResolutionOrOrientationChanged";
if (raiseInAddToManagers)
{
codeBlock.Line("OnResolutionOrOrientationChanged(this, null);");
codeBlock = codeBlock.End();
}
}
}
示例9: GetActivityForNamedObject
public static void GetActivityForNamedObject(NamedObjectSave namedObjectSave, ICodeBlock codeBlock)
{
///////////////////////////EARLY OUT/////////////////////////////////////////////////
if (
(namedObjectSave.SetByContainer && namedObjectSave.GetContainer() is EntitySave)
||
namedObjectSave.IsDisabled || namedObjectSave.CallActivity == false ||
namedObjectSave.InstantiatedByBase || !namedObjectSave.IsFullyDefined)
{
return;
}
/////////////////////////END EARLY OUT///////////////////////////////////////////////
bool setByDerived = namedObjectSave.SetByDerived;
AddIfConditionalSymbolIfNecesssary(codeBlock, namedObjectSave);
if (!setByDerived)
{
if (namedObjectSave.Instantiate == false)
{
// This may be null or it may be instantiated later by the user, so we should
// handle both cases:
codeBlock = codeBlock.If(namedObjectSave.InstanceName + " != null");
}
if (namedObjectSave.SourceType == SourceType.Entity)
{
// Entities need activity!
codeBlock.Line(namedObjectSave.InstanceName + ".Activity();");
}
else if (namedObjectSave.SourceType == SourceType.FlatRedBallType &&
namedObjectSave.ClassType != null &&
namedObjectSave.ClassType.Contains("PositionedObjectList<"))
{
// Now let's see if the object in the list is an entity
string genericType = namedObjectSave.SourceClassGenericType;
if (genericType.Contains("Entities\\"))
{
codeBlock.For("int i = " + namedObjectSave.InstanceName + ".Count - 1; i > -1; i--")
.If("i < " + namedObjectSave.InstanceName + ".Count")
.Line("// We do the extra if-check because activity could destroy any number of entities")
.Line(namedObjectSave.InstanceName + "[i].Activity();");
}
}
}
// If it's an emitter, call TimedEmit:
ParticleCodeGenerator.GenerateTimedEmit(codeBlock, namedObjectSave);
if (!setByDerived)
{
if (namedObjectSave.Instantiate == false)
{
// end the if-statement we started above.
codeBlock = codeBlock.End();
}
}
AddEndIfIfNecessary(codeBlock, namedObjectSave);
}
示例10: FillWithGeneratedEventCode
public static ICodeBlock FillWithGeneratedEventCode(ICodeBlock currentBlock, EventResponseSave ers, IElement element)
{
EventSave eventSave = ers.GetEventSave();
string args = ers.GetArgsForMethod(element);
if (!string.IsNullOrEmpty(ers.SourceObject) && !string.IsNullOrEmpty(ers.SourceObjectEvent))
{
currentBlock = currentBlock
.Function("void", "On" + ers.EventName + "Tunnel", args);
string reducedArgs = StripTypesFromArguments(args);
currentBlock.If("this." + ers.EventName + " != null")
.Line(ers.EventName + "(" + reducedArgs + ");")
.End();
currentBlock = currentBlock.End();
}
return currentBlock;
}
示例11: FillWithCustomEventCode
public static ICodeBlock FillWithCustomEventCode(ICodeBlock currentBlock, EventResponseSave ers, string contents, IElement element)
{
string args = ers.GetArgsForMethod(element);
// We used to not
// generate the empty
// shell of an event if
// the contents were empty.
// However now we want to for
// two reasons:
// 1: A user may want to add an
// event in Glue, but then mdoify
// the event in Visual Studio. The
// user shouldn't be forced into adding
// some content in Glue first to wdit the
// event in Visual Studio.
// 2: A designer may decide to remove the
// contents of a method. If this happens then
// code that the designer doesn't work with shouldn't
// break (IE, if the code calls the OnXXXX method).
//if (!string.IsNullOrEmpty(contents))
{
// Need to modify the event CSV to include the arguments for this event
currentBlock = currentBlock
.Function("void", "On" + ers.EventName, args);
currentBlock.TabCharacter = "";
int tabCount = currentBlock.TabCount;
currentBlock.TabCount = 0;
currentBlock
.Line(contents);
currentBlock = currentBlock.End();
}
return currentBlock;
}
示例12: GenerateActivity
public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, IElement element)
{
foreach (EventResponseSave ers in element.Events)
{
if ((ers.GetEventSave() != null && !string.IsNullOrEmpty(ers.GetEventSave().ConditionCode)))
{
codeBlock = codeBlock.If(ers.GetEventSave().ConditionCode + " && " + ers.EventName + " != null");
codeBlock.Line(ers.EventName + "();");
codeBlock = codeBlock.End();
}
}
return codeBlock;
}
示例13: GetMakeUnusedFactory
private static ICodeBlock GetMakeUnusedFactory(ICodeBlock codeBlock, string factoryClassName, bool poolObjects)
{
string className = factoryClassName.Substring(0, factoryClassName.Length - "Factory".Length);
codeBlock.Line("/// <summary>");
codeBlock.Line("/// Makes the argument objectToMakeUnused marked as unused. This method is generated to be used");
codeBlock.Line("/// by generated code. Use Destroy instead when writing custom code so that your code will behave");
codeBlock.Line("/// the same whether your Entity is pooled or not.");
codeBlock.Line("/// </summary>");
codeBlock = codeBlock
.Function("public static void", "MakeUnused", className + " objectToMakeUnused")
.Line("MakeUnused(objectToMakeUnused, true);")
.End()
._()
.Line("/// <summary>")
.Line("/// Makes the argument objectToMakeUnused marked as unused. This method is generated to be used")
.Line("/// by generated code. Use Destroy instead when writing custom code so that your code will behave")
.Line("/// the same whether your Entity is pooled or not.")
.Line("/// </summary>")
.Function("public static void", "MakeUnused", className + " objectToMakeUnused, bool callDestroy");
if (poolObjects)
{
codeBlock
.Line("mPool.MakeUnused(objectToMakeUnused);")
._()
.If("callDestroy")
.Line("objectToMakeUnused.Destroy();")
.End();
}
else
{
// We still need to check if we should call destroy even if not pooled, because the parent may be pooled, in which case an infinite loop
// can occur if we don't check the callDestroy value. More info on this bug:
// http://www.hostedredmine.com/issues/413966
codeBlock
.If("callDestroy")
.Line("objectToMakeUnused.Destroy();");
}
codeBlock = codeBlock.End();
return codeBlock;
}
示例14: GetInitializeFactoryMethod
private static ICodeBlock GetInitializeFactoryMethod(ICodeBlock codeBlock, string className, bool poolObjects, string listToAssign)
{
codeBlock = codeBlock
.Function("public static void", "Initialize", string.Format("FlatRedBall.Math.PositionedObjectList<{0}> listFromScreen, string contentManager", className))
.Line("mContentManagerName = contentManager;")
.Line(listToAssign + " = listFromScreen;");
if (poolObjects)
{
codeBlock.Line("FactoryInitialize();");
}
codeBlock = codeBlock.End();
return codeBlock;
}
示例15: GetInitializationForReferencedFile
public static void GetInitializationForReferencedFile(ReferencedFileSave referencedFile, IElement container,
ICodeBlock codeBlock, bool loadsUsingGlobalContentManager, LoadType loadType)
{
#region early-outs (not loaded at runtime, loaded only when referenced)
if (referencedFile.LoadedOnlyWhenReferenced)
{
return;// "";
}
if (referencedFile.IsDatabaseForLocalizing == false && !referencedFile.GetGeneratesMember())
{
return; // There is no qualified type to load to, so let's not generate code to load it
}
#endregion
// I'm going to only do this if we're non-null so that we don't add it for global content. Global Content may load
// async and cause bad data
if (container != null)
{
PerformancePluginCodeGenerator.GenerateStart(container, codeBlock, "LoadStaticContent" + FileManager.RemovePath(referencedFile.Name));
}
AddIfConditionalSymbolIfNecesssary(codeBlock, referencedFile);
bool directives = false;
for (int i = referencedFile.ProjectSpecificFiles.Count; i >= 0; i--)
{
bool isProjectSpecific = i != 0;
string fileName;
ProjectBase project;
if (isProjectSpecific)
{
fileName = referencedFile.ProjectSpecificFiles[i - 1].FilePath.ToLower().Replace("\\", "/");
// At one point
// the project specific
// files were platform specific
// but instead we want them to be
// based off of the project name instead.
// The reason for this is because a user could
// create a synced project that targets the same
// platform.
project = ProjectManager.GetProjectByName(referencedFile.ProjectSpecificFiles[i - 1].ProjectId);
if (project == null)
{
project = ProjectManager.GetProjectByTypeId(referencedFile.ProjectSpecificFiles[i - 1].ProjectId);
}
}
else
{
fileName = referencedFile.Name.ToLower().Replace("\\", "/");
project = ProjectManager.ProjectBase;
}
string containerName = ContentLoadWriter.GlobalContentContainerName;
if (container != null)
{
containerName = container.Name;
}
AddCodeforFileLoad(referencedFile, ref codeBlock, loadsUsingGlobalContentManager,
ref directives, isProjectSpecific, ref fileName, project, loadType, containerName);
}
if (directives == true)
{
codeBlock = codeBlock.End()
.Line("#endif");
}
AddEndIfIfNecessary(codeBlock, referencedFile);
// See above why this if-statement exists
if (container != null)
{
PerformancePluginCodeGenerator.GenerateEnd(container, codeBlock, "LoadStaticContent" + FileManager.RemovePath(referencedFile.Name));
}
}