本文整理汇总了C#中ICodeBlock.Property方法的典型用法代码示例。如果您正苦于以下问题:C# ICodeBlock.Property方法的具体用法?C# ICodeBlock.Property怎么用?C# ICodeBlock.Property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICodeBlock
的用法示例。
在下文中一共展示了ICodeBlock.Property方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateAbsoluteVisible
private void GenerateAbsoluteVisible(ICodeBlock codeBlock, EntitySave entitySave)
{
if (!entitySave.GetInheritsFromIVisible())
{
var prop = codeBlock.Property("AbsoluteVisible", Public: true, Override: false, Type: "bool");
prop.Get().Line("return Visible && (Parent == null || IgnoresParentVisibility || Parent is FlatRedBall.Graphics.IVisible == false || (Parent as FlatRedBall.Graphics.IVisible).AbsoluteVisible);");
}
}
示例2: GenerateIVisibleParent
private void GenerateIVisibleParent(ICodeBlock codeBlock, EntitySave entitySave)
{
if (!entitySave.GetInheritsFromIVisible())
{
var prop = codeBlock.Property("FlatRedBall.Graphics.IVisible.Parent", Override: false, Type: "FlatRedBall.Graphics.IVisible");
var get = prop.Get();
get.If("this.Parent != null && this.Parent is FlatRedBall.Graphics.IVisible")
.Line("return this.Parent as FlatRedBall.Graphics.IVisible;").End()
.Else()
.Line("return null;");
}
}
示例3: GenerateFields
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, IElement element)
{
if (ShouldGenerate(element))
{
var entitySave = element as EntitySave;
// The following are already handled by the Entity:
// X, Y, Z
codeBlock.Property("bool", "FlatRedBall.Graphics.IDrawableBatch.UpdateEveryFrame")
.Get()
.Line("return false;");
}
return codeBlock;
}
示例4: GenerateFields
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element)
{
EntitySave asEntitySave = element as EntitySave;
if (asEntitySave != null && asEntitySave.ImplementsICollidable)
{
codeBlock.Line("private FlatRedBall.Math.Geometry.ShapeCollection mGeneratedCollision;");
var propBlock = codeBlock.Property("public FlatRedBall.Math.Geometry.ShapeCollection", "Collision");
propBlock.Get().Line("return mGeneratedCollision;");
return codeBlock;
}
else
{
return base.GenerateFields(codeBlock, element);
}
}
示例5: GenerateCurrentStateProperty
private static ICodeBlock GenerateCurrentStateProperty(IElement element, ICodeBlock codeBlock, string enumType, List<StateSave> states)
{
var createField = false;
if (enumType == "VariableState" && !DoesBaseHaveUncategorizedStates(element)) //Uncategorized and not base
{
createField = true;
}
else if (enumType != "VariableState") //Check if this state category exists in a parent entity
{
if (element.BaseElement != null)
{
var categories = GetAllStateCategoryNames(ObjectFinder.Self.GetIElement(element.BaseElement), true);
if (!categories.Any(category => category == enumType))
{
createField = true;
}
}else
{
createField = true;
}
}
string variableNameModifier = enumType;
if (enumType == "VariableState")
{
variableNameModifier = "";
}
string qualifiedEnumType = element.Name.Replace("\\", ".").Replace("/", ".") + "." + enumType;
if (states.Count != 0)
{
string variableToLookFor = "Current" + variableNameModifier + "State";
CustomVariable customVariable = element.GetCustomVariable(variableToLookFor);
bool hasEvent = customVariable != null && customVariable.CreatesEvent;
#region Header and Getter stuff - simple stuff with no logic
if (createField)
{
codeBlock
.Line(string.Format("protected int mCurrent{0}State = 0;", variableNameModifier));
}
string publicWithOptionalNew = "public";
if (ShouldUseNewKeyword(element, enumType))
{
publicWithOptionalNew += " new";
}
var setBlock = codeBlock
.Property(publicWithOptionalNew + " " + qualifiedEnumType, "Current" + variableNameModifier + "State")
.Get()
.If(string.Format("System.Enum.IsDefined(typeof({0}), mCurrent{1}State)", enumType, variableNameModifier))
.Line(string.Format("return ({0})mCurrent{1}State;", enumType, variableNameModifier))
.End()
.Else()
.Line(string.Format("return {0}.Unknown;", enumType))
.End()
.End()
.Set();
#endregion
#region Set the state value and call an event if necessary
bool stillNeedsToAssignValue = true;
if (element is EntitySave)
{
EntitySave asEntitySave = element as EntitySave;
//if (!string.IsNullOrEmpty(asEntitySave.CurrentStateChange))
//{
// setBlock
// .If("value != mCurrent" + variableNameModifier + "State")
// .Line("mCurrent" + variableNameModifier + "State = value;")
// .Line(asEntitySave.CurrentStateChange + "(this, null);");
// stillNeedsToAssignValue = false;
//}
}
if (hasEvent)
{
EventCodeGenerator.GenerateEventRaisingCode(setBlock, BeforeOrAfter.Before, variableToLookFor, element);
}
if (stillNeedsToAssignValue)
{
setBlock.Line("mCurrent" + variableNameModifier + "State = (int)value;");
}
#endregion
var switchBlock = setBlock.Switch("Current" + variableNameModifier + "State");
switchBlock.Case(enumType + ".Uninitialized");
switchBlock.Case(enumType + ".Unknown");
//.........这里部分代码省略.........
示例6: GenerateEnabledVariable
private static void GenerateEnabledVariable(ICodeBlock codeBlock, IElement element)
{
CustomVariable exposedEnabledVariable = element.CustomVariables.FirstOrDefault(item => item.Name == "Enabled" && item.Type == "bool");
bool isEnableVariableExposed = exposedEnabledVariable != null;
bool hasEvents = exposedEnabledVariable != null && exposedEnabledVariable.CreatesEvent && element.Events.Any(item => item.SourceVariable == exposedEnabledVariable.Name);
if (hasEvents)
{
EventCodeGenerator.GenerateEventsForVariable(codeBlock, exposedEnabledVariable.Name);
}
string prefix;
string propertyName;
if (isEnableVariableExposed)
{
prefix = "public bool";
propertyName = "Enabled";
}
else
{
prefix = "bool";
propertyName = "FlatRedBall.Gui.IWindow.Enabled";
}
codeBlock.Line(Resources.Resource1.IWindowTemplate);
var property = codeBlock.Property(prefix, propertyName);
property.Get().Line("return mEnabled;");
var setBlock = property.Set();
if (hasEvents)
{
EventCodeGenerator.GenerateEventRaisingCode(setBlock, BeforeOrAfter.Before, exposedEnabledVariable.Name, element);
}
var setIf = setBlock.If("mEnabled != value");
setIf.Line("mEnabled = value;");
setIf.Line("EnabledChange?.Invoke(this);");
if (hasEvents)
{
EventCodeGenerator.GenerateEventRaisingCode(setIf, BeforeOrAfter.After, exposedEnabledVariable.Name, element);
}
}
示例7: GenerateAnimationMember
private void GenerateAnimationMember(StateCodeGeneratorContext context, ICodeBlock currentBlock, AnimationSave animation, AbsoluteOrRelative absoluteOrRelative)
{
string propertyName = animation.PropertyNameInCode();
if (absoluteOrRelative == AbsoluteOrRelative.Relative)
{
propertyName += "Relative";
}
string referencedInstructionProperty = propertyName + "Instructions";
// Force the property to be upper-case, since the field is lower-case:
// We want to generate something like:
//private FlatRedBall.Gum.Animation.GumAnimation uncategorizedAnimation;
//public FlatRedBall.Gum.Animation.GumAnimation UncategorizedAnimation
//{
// get
// {
// if (uncategorizedAnimation == null)
// {
// uncategorizedAnimation = new FlatRedBall.Gum.Animation.GumAnimation(1, () => UncategorizedAnimationInstructions);
// uncategorizedAnimation.AddEvent("Event1", 3.0f);
// }
// return uncategorizedAnimation;
// }
//}
var firstCharacterLower = propertyName.Substring(0, 1).ToLowerInvariant();
var fieldName = firstCharacterLower + propertyName.Substring(1);
currentBlock.Line($"private FlatRedBall.Gum.Animation.GumAnimation {fieldName};");
currentBlock = currentBlock.Property("public FlatRedBall.Gum.Animation.GumAnimation", propertyName).Get();
float length = GetAnimationLength(context.Element, animation);
string lengthAsString = ToFloatString(length);
var ifBlock = currentBlock.If($"{fieldName} == null");
{
ifBlock.Line(
$"{fieldName} = new FlatRedBall.Gum.Animation.GumAnimation({lengthAsString}, () => {referencedInstructionProperty});");
foreach(var namedEvent in animation.Events)
{
string timeAsString = ToFloatString(namedEvent.Time);
ifBlock.Line(
$"{fieldName}.AddEvent(\"{namedEvent.Name}\", {timeAsString});");
}
foreach(var subAnimation in animation.Animations)
{
if(string.IsNullOrEmpty(subAnimation.SourceObject) == false)
{
ifBlock.Line($"{fieldName}.SubAnimations.Add({subAnimation.PropertyNameInCode()});");
}
}
}
currentBlock.Line($"return {fieldName};");
}
示例8: GenerateEnumerableFor
private void GenerateEnumerableFor(StateCodeGeneratorContext context, ICodeBlock currentBlock, AnimationSave animation, AbsoluteOrRelative absoluteOrRelative)
{
string animationType = "VariableState";
string animationName = animation.PropertyNameInCode();
if(absoluteOrRelative == AbsoluteOrRelative.Relative)
{
animationName += "Relative";
}
string propertyName = animationName + "Instructions";
// Instructions used to be public - the user would grab them and add them to the InstructionManager,
// but now everything is encased in an Animation object which handles stopping itself and provides a simple
// Play method.
if (animation.States.Count == 0 && animation.Animations.Count == 0)
{
currentBlock = currentBlock.Property("private System.Collections.Generic.IEnumerable<FlatRedBall.Instructions.Instruction>", propertyName).Get();
currentBlock.Line("yield break;");
}
else if(absoluteOrRelative == AbsoluteOrRelative.Relative && animation.States.Count < 2 && animation.Animations.Count == 0)
{
currentBlock = currentBlock.Property("private System.Collections.Generic.IEnumerable<FlatRedBall.Instructions.Instruction>", propertyName).Get();
currentBlock.Line("yield break;");
}
else
{
if (animation.States.Count != 0)
{
var firstState = context.Element.AllStates.FirstOrDefault(item => item.Name == animation.States.First().StateName);
var category = context.Element.Categories.FirstOrDefault(item => item.States.Contains(firstState));
if (category != null)
{
animationType = category.Name;
}
}
currentBlock = currentBlock.Property("private System.Collections.Generic.IEnumerable<FlatRedBall.Instructions.Instruction>", propertyName).Get();
GenerateOrderedStateAndSubAnimationCode(context, currentBlock, animation, animationType, absoluteOrRelative);
if(animation.Loops)
{
currentBlock = currentBlock.Block();
currentBlock.Line("var toReturn = new FlatRedBall.Instructions.DelegateInstruction( " +
"() => FlatRedBall.Instructions.InstructionManager.Instructions.AddRange(this." + propertyName + "));");
string executionTime = "0.0f";
if(animation.States.Count != 0)
{
executionTime = ToFloatString( animation.States.Last().Time);
}
currentBlock.Line("toReturn.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + " + executionTime + ";");
currentBlock.Line("yield return toReturn;");
currentBlock = currentBlock.End();
}
}
}
示例9: AppendPropertyForReferencedFileSave
private static void AppendPropertyForReferencedFileSave(ICodeBlock codeBlock, ReferencedFileSave referencedFile, string containerName, IElement element, string contentManagerName, AssetTypeInfo ati, string variableName, string typeName)
{
codeBlock.Line(StringHelper.Modifiers(Static: referencedFile.IsSharedStatic, Type: typeName, Name: "m" + variableName) + ";");
// No need to use
// ManualResetEvents
// if the ReferencedFileSave
// is LoadedOnlyWhenReferenced.
bool shouldBlockThreads = containerName ==
ContentLoadWriter.GlobalContentContainerName && !referencedFile.LoadedOnlyWhenReferenced;
if (shouldBlockThreads)
{
codeBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");
codeBlock.Line("//Blocks the thread on request of " + variableName + " until it has been loaded");
codeBlock.Line("static ManualResetEvent m" + variableName + "Mre = new ManualResetEvent(false);");
codeBlock.Line("// Used to lock getter and setter so that " + variableName + " can be set on any thread even if its load is in progrss");
codeBlock.Line("static object m" + variableName + "_Lock = new object();");
codeBlock.Line("#endif");
}
string lastContentManagerVariableName = "mLastContentManagerFor" + variableName;
if (referencedFile.LoadedAtRuntime && element != null)
{
codeBlock.Line("static string " + lastContentManagerVariableName + ";");
}
// Silverlight and Windows Phone only allow reflection on public methods
// Since it's common practice to use reflection to reference LoadedOnlyWhenReferenced
// properties, we need to make them public.
var propBlock = codeBlock.Property(variableName, Public: true, Static: referencedFile.IsSharedStatic, Type: typeName);
var getBlock = propBlock.Get();
if (referencedFile.LoadedOnlyWhenReferenced)
{
WriteLoadedOnlyWhenReferencedPropertyBody(referencedFile, containerName, element, contentManagerName, ati, variableName, lastContentManagerVariableName, getBlock);
}
else if (containerName == ContentLoadWriter.GlobalContentContainerName)
{
#region Write the getter
getBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");
if (shouldBlockThreads)
{
getBlock = getBlock.Lock("m" + variableName + "_Lock");
}
//Perform a WaitOne on the event with a timeout value of zero.
// It will return true if the event is not set, or false if the timeout occurs.
// In other words, false -> event is set, true -> event is not set.
getBlock.Line("bool isBlocking = !m" + variableName + "Mre.WaitOne(0);");
{
var ifBlock = getBlock.If("isBlocking");
// This is our way of telling the GlobalContentManager to hurry up - we're waiting
// on some content!
ifBlock.Line("RequestContentLoad(\"" + referencedFile.Name + "\");");
#region If RecordLockRecord - write the code for recording the load order so that it can be optimized
if (ProjectManager.GlueProjectSave.GlobalContentSettingsSave.RecordLockContention)
{
ifBlock.Line("LockRecord.Add(\"\\n" + variableName + "\");");
}
#endregion
}
getBlock.Line("m" + variableName + "Mre.WaitOne();");
getBlock.Line("return m" + variableName + ";");
if (shouldBlockThreads)
{
getBlock = getBlock.End();
}
getBlock.Line("#else");
WriteLoadedOnlyWhenReferencedPropertyBody(referencedFile, containerName, element, contentManagerName, ati, variableName, lastContentManagerVariableName, getBlock);
getBlock.Line("#endif");
#endregion
#region Write the setter
var setBlock = propBlock.Set();
setBlock.Line("#if !REQUIRES_PRIMARY_THREAD_LOADING");
if (shouldBlockThreads)
//.........这里部分代码省略.........
示例10: GenerateFieldAndPropertyForNamedObject
public static void GenerateFieldAndPropertyForNamedObject(NamedObjectSave namedObjectSave, ICodeBlock codeBlock)
{
string typeName = GetQualifiedTypeName(namedObjectSave);
CodeGenerationType codeGenerationType = GetFieldCodeGenerationType(namedObjectSave);
if (codeGenerationType == CodeGenerationType.OnlyContainedObjects)
{
// Since the base defines it, we don't want to define the object here; however,
// any objects that it contains will not be defined by base, so we do need to loop
// through contained NamedObjectSaves and define those. We also want to create variable
// reset fields.
CreateVariableResetField(namedObjectSave, typeName, codeBlock);
foreach (NamedObjectSave childNos in namedObjectSave.ContainedObjects)
{
GenerateFieldAndPropertyForNamedObject(childNos, codeBlock);
}
}
else if(codeGenerationType == CodeGenerationType.Full)
{
AddIfConditionalSymbolIfNecesssary(codeBlock, namedObjectSave);
#region Get the Access Modifier
string accessModifier = "private";
if (namedObjectSave.SetByDerived || namedObjectSave.ExposedInDerived)
{
accessModifier = "protected";
}
#endregion
string variableName = namedObjectSave.FieldName;
codeBlock.Line(StringHelper.SpaceStrings(accessModifier, typeName, variableName) + ";");
#region If should create public property
bool shouldCreateProperty = namedObjectSave.HasPublicProperty || namedObjectSave.SetByContainer;
if (shouldCreateProperty)
{
var prop = codeBlock.Property(StringHelper.SpaceStrings("public", typeName),
namedObjectSave.InstanceName);
prop.Get()
.Line("return " + variableName + ";");
if (namedObjectSave.SetByContainer)
{
prop.Set()
.Line(variableName + " = value;");
}
else if (namedObjectSave.SetByDerived)
{
prop.Set("protected")
.Line(variableName + " = value;");
}
else
{
// This should still have a private setter to not break
// internal code
prop.Set("private")
.Line(variableName + " = value;");
}
}
#endregion
CreateVariableResetField(namedObjectSave, typeName, codeBlock);
// If this NamedObjectSave has children, then create fields for those too
foreach (NamedObjectSave childNos in namedObjectSave.ContainedObjects)
{
GenerateFieldAndPropertyForNamedObject(childNos, codeBlock);
}
AddEndIfIfNecessary(codeBlock, namedObjectSave);
}
}
示例11: GenerateFields
public override ICodeBlock GenerateFields(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);
codeBlock.Line(string.Format("public System.Action<{0}> ScrollItemModified;", itemTypeWithoutPath));
codeBlock.Line(string.Format(
"FlatRedBall.Math.PositionedObjectList<{0}> mScrollableItems = new FlatRedBall.Math.PositionedObjectList<{0}>();",
itemTypeWithoutPath));
codeBlock.Line("FlatRedBall.PositionedObject mScrollableHandle;");
codeBlock.Line(string.Format("float mScrollableSpacing = {0};", entitySave.SpacingBetweenItems));
codeBlock.Line(string.Format("float mScrollableTopBoundary = {0};", entitySave.ListTopBound));
codeBlock.Line(string.Format("float mScrollableBottomBoundary = {0};", entitySave.ListBottomBound));
codeBlock.Line("int mScrollableFirstIndex = 0;");
codeBlock.Line(string.Format("{0} mLastCreatedScrollableItem;", itemTypeWithoutPath));
codeBlock
.Property("public int", "ScrollableFirstIndex")
.Set()
.Line("mScrollableFirstIndex = System.Math.Max(0, value);")
.If("mListShowingButUsePropertyPlease == null")
.While("mScrollableItems.Count > 0")
.Line("mScrollableItems.Last.Destroy();")
.End()
.End()
.Else()
// We add 1 because let's say the spacing is 10. Even if the top to bottom was 1 unit, we'd see 1 item.
.Line("int maxShown = 1 + (int)((mScrollableTopBoundary - mScrollableBottomBoundary) / mScrollableSpacing);")
.Line("int maximumFirst = System.Math.Max(0, mListShowingButUsePropertyPlease.Count - maxShown);")
.Line("mScrollableFirstIndex = System.Math.Min(maximumFirst, mScrollableFirstIndex);")
.Line("mScrollableHandle.RelativeY = mScrollableFirstIndex * mScrollableSpacing + mScrollableTopBoundary;")
.Line("FixScrollableHandleRelativeY();")
.Line("int numberOfEntities = System.Math.Min(maxShown, ListShowing.Count);")
.While("mScrollableItems.Count > ListShowing.Count || mScrollableItems.Count > numberOfEntities")
.Line("mScrollableItems.Last.Destroy();")
.End()
.For("int i = 0; i < mScrollableItems.Count; i++")
.Line("mScrollableItems[i].RelativeY = -( i + mScrollableFirstIndex ) * mScrollableSpacing;")
.Line("mScrollableItems[i].ForceUpdateDependencies();")
.If("ScrollItemModified != null")
.Line("ScrollItemModified(mScrollableItems[i]);")
.End()
.End()
.Line("PerformScrollableItemAdditionLogic();");
codeBlock.Line("private System.Collections.IList mListShowingButUsePropertyPlease;");
codeBlock
.Property("public System.Collections.IList", "ListShowing")
.Get()
.Line("return mListShowingButUsePropertyPlease;")
.End()
.Set()
.If("value != mListShowingButUsePropertyPlease")
.Line("mListShowingButUsePropertyPlease = value;")
.Line("ScrollableFirstIndex = 0;")
.Line("RefreshAllScrollableListItems();");
}
}
return codeBlock;
}
示例12: GenerateVisibleProperty
private static void GenerateVisibleProperty(ICodeBlock codeBlock, IElement element, EntitySave entitySave)
{
bool inheritsFromIVisible = entitySave.GetInheritsFromIVisible();
#region Get whether we use virtual or override
if (!inheritsFromIVisible)
{
codeBlock.Line("protected bool mVisible = true;");
}
#endregion
var prop = codeBlock.Property("Visible", Public: true, Override: entitySave.GetInheritsFromIVisible(), Virtual: !entitySave.GetInheritsFromIVisible(), Type: "bool");
if (inheritsFromIVisible)
{
prop.Get()
.Line("return base.Visible;");
}
else
{
prop.Get()
.Line("return mVisible;");
}
var set = prop.Set();
#region History on the before set code
// See comment above about why we no longer
// check to see if it creates an event.
//if (createsVisibleEvent)
//{
// Keep hasChanged around just in case we want to make a Changed event. It won't be used by the Set event
// Update November 27, 2011
// This is just polluting code. Let's remove it for now
//set.Line("bool hasChanged = value != mVisible;");
#endregion
EventCodeGenerator.GenerateEventRaisingCode(set, BeforeOrAfter.Before, "Visible", entitySave);
if (entitySave.GetInheritsFromIVisible())
{
set.Line("base.Visible = value;");
}
else
{
set.Line("mVisible = value;");
}
// May 6, 2012
// We used to manually
// set the Visible of all
// children, but now we no
// longer do that because there
// is a concept of relative visibility.
// WriteVisibleSetForNamedObjectSaves(set, entitySave);
EventCodeGenerator.GenerateEventRaisingCode(set, BeforeOrAfter.After, "Visible", entitySave);
}
示例13: CreateNewVariableMember
private static void CreateNewVariableMember(ICodeBlock codeBlock, CustomVariable customVariable, bool isExposing, IElement element)
{
string variableAssignment = "";
if (customVariable.DefaultValue != null)
{
if (!IsTypeFromCsv(customVariable))
{
variableAssignment =
CodeParser.ParseObjectValue(customVariable.DefaultValue);
// If this is a file, we don't want to assign it here
if (customVariable.GetIsFile())
{
variableAssignment = null;
}
if (customVariable.Type == "Color")
{
variableAssignment = "Color." + variableAssignment.Replace("\"", "");
}
else if (customVariable.Type != "string" && variableAssignment == "\"\"")
{
variableAssignment = null;
}
if (variableAssignment != null)
{
variableAssignment = " = " + variableAssignment;
}
}
else if(!string.IsNullOrEmpty(customVariable.DefaultValue as string) && (string)customVariable.DefaultValue != "<NULL>")
{
// If the variable IsShared (ie static) then we
// don't want to assign the value because the CSV
// may not yet be loaded. This may create behavior
// the user doesn't expect, but the alternative is either
// to load the file before the user wants to (which maybe we
// will end up doing) or to get a crash
// Update June 2, 2013
// If the customVariable
// is not "IsShared" (it's
// not static), we don't want
// to assign the value where we
// create the variable as a field
// because this means the value will
// attempt to assign before LoadStaticContent.
// This can cause a crash, and has in the GlueTestProject.
// Update June 2, 2013
// Used to set it to null
// if it's static, but we should
// allow statics to set their values
// if they come from global content files.
if (
ReferencesCsvFromGlobalContent(customVariable) &&
ShouldAssignToCsv(customVariable, customVariable.DefaultValue as string))
{
variableAssignment = " = " + GetAssignmentToCsvItem(customVariable, element, (string)customVariable.DefaultValue);
}
else
{
variableAssignment = null;
}
}
}
string formatString = null;
bool needsToBeProperty = (customVariable.SetByDerived && !customVariable.IsShared) || customVariable.CreatesProperty || customVariable.CreatesEvent
|| IsVariableWholeNumberWithVelocity(customVariable);
needsToBeProperty = needsToBeProperty & !customVariable.GetIsVariableState();
EventCodeGenerator.TryGenerateEventsForVariable(codeBlock, customVariable, element);
string memberType = GetMemberTypeFor(customVariable, element);
if (needsToBeProperty)
{
// If the variable
// creates an event
// then it needs to have
// custom code (it can't be
// an automatic property).
bool isWholeNumberWithVelocity = IsVariableWholeNumberWithVelocity(customVariable);
if (customVariable.CreatesEvent || isWholeNumberWithVelocity || customVariable.DefaultValue != null )
{
string variableToAssignInProperty = "base." + customVariable.Name;
// create a field for this, unless it's defined by base - then the base creates a field for it
if (!isExposing && !customVariable.DefinedByBase)
{
variableToAssignInProperty = "m" + customVariable.Name;
// First we make the field that will get set here:
//.........这里部分代码省略.........
示例14: WritePropertyHeader
private static ICodeBlock WritePropertyHeader(ICodeBlock codeBlock, CustomVariable customVariable, string customVariableType)
{
ICodeBlock prop;
bool needsToCloseIf = false;
if (customVariableType == "Microsoft.Xna.Framework.Color")
{
codeBlock.Line("#if XNA3 || SILVERLIGHT");
prop = codeBlock.Property(customVariable.Name, Public: true,
Override: customVariable.DefinedByBase,
Virtual: (customVariable.SetByDerived && !customVariable.IsShared),
Type: "Microsoft.Xna.Framework.Graphics.Color");
prop.PreCodeLines.RemoveAt(1); // get rid of its opening bracket
prop.PostCodeLines.Clear();
prop.End();
codeBlock.Line("#else");
needsToCloseIf = true;
}
prop = codeBlock.Property(customVariable.Name, Public: true,
Override: customVariable.DefinedByBase,
Virtual: (customVariable.SetByDerived && !customVariable.IsShared),
Type: customVariableType);
if (needsToCloseIf)
{
prop.PreCodeLines.Insert(1, new CodeLine("#endif"));
}
return prop;
}