本文整理汇总了C#中System.Windows.Documents.Block.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Block.ToString方法的具体用法?C# Block.ToString怎么用?C# Block.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.Block
的用法示例。
在下文中一共展示了Block.ToString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: translateComparisons
//method to convert comparison names into the proper symbols
private static string translateComparisons(Block b)
{
if (b.ToString().Contains("AND") || b.ToString().Contains("OR"))
{
return b.ToString().ToLower();
}
switch (b.ToString())
{
case "COMPARISON-greater":
return ">";
case "COMPARISON-less":
return "<";
case "COMPARISON-greaterequal":
return ">=";
case "COMPARISON-lessequal":
return "<=";
case "COMPARISON-equal":
return "==";
case "COMPARISON-notequal":
return "!=";
case "ASSIGNMENT":
return "=";
default:
return "error";
}
}
示例2: AddBlock
/// <summary>
/// Convert an flow document paragraph into its html representation.
/// </summary>
/// <param name="block">Flow document block.</param>
/// <param name="htmlWriter">XmlTextWriter producing resulting html.</param>
/// <param name="conversionResult">Conversion result to store error and warning messages. Can be null.</param>
/// <remarks>
/// List, Paragraph, Table are supported Block elements. Section is not supported.
/// </remarks>
private static void AddBlock(Block block, XmlTextWriter htmlWriter, ValidationResult conversionResult)
{
if (block is List)
{
AddList(block as List, htmlWriter, conversionResult);
}
else if (block is Paragraph)
{
AddParagraph(block as Paragraph, htmlWriter, conversionResult);
}
else if (block is Table)
{
AddTable(block as Table, htmlWriter, conversionResult);
}
else
{
// not supported: Section
if (conversionResult != null)
{
conversionResult.AddMessage(new ConversionMessage(ModelValidationViolationType.Warning,
"AddBlock: Unknown block element: " + block.ToString()));
}
}
}
示例3: checkSpecialLoop
//checks if block is a loop which will require no parens, i.e. for/wait for
private static bool checkSpecialLoop(Block b)
{
if (b.ToString().Contains("FOR"))
{
return true;
}
else
{
return false;
}
}
示例4: translateRobotFunctions
//these are methods that convert block formats into their objective G counterparts, mostly used for robot functions
#region Translation Methods
//method to translate robot functions into code
public static string translateRobotFunctions(Block b)
{
string functName = b.ToString();
switch (functName)
{
case "DRIVE":
return "method drive " + readSocket(b);
//break;
case "DRIVEDISTANCE":
return "method driveDistance " + readSocket(b);
// break;
case "TURN":
return "method turn " + readSocket(b);
//break;
case "TURNDEGREES":
return "method turnAngle " + readSocket(b);
//break;
case "TURNTOBEARING":
return "method turnToBearing " + readSocket(b);
//break;
case "CHECKRANGE":
return "method getSonars " + readSocket(b);
//break;
case "GETBEARING":
return "method getBearing ()";
//break;
case "STOP":
return "method stop ()";
//break;
default:
Debug.WriteLine("ERROR: METHOD NOT RECOGNIZED");
return "";
//break;
}
}
示例5: readSocket
//method to read socket values and place them into parentheses
public static String readSocket(Block source)
{
if (source.flag_hasSocks)
{
String plaintext =""; //string that will become the output
ListBox socket; //listbox to be checked for values
bool parenCheck = checkLocation(source); //bool to see if socket needs parentheses
bool specialLoop = checkSpecialLoop(source); //bool to see if socket is in for/wait for loops, which have special outputs
//adding opening bracket or paren if necessary
if (source.ToString().Equals("ASSIGNMENT") || source.ToString().Equals("RETURN"))
{
plaintext = " ";
}
else if (parenCheck || source.flag_isCustom)
{
plaintext = " ( ";
}
else
{
plaintext = "[ ";
}
//getting all sockets in the block
List<int> locations = socketFinder(source);
foreach (int i in locations)
{
socket = socketMole(source, i);
//ensuring that the socket contains a block
if (socket.Items.Count > 0)
{
Block infoCube = (Block)socket.Items.ElementAt(0);
//handling nested conditions, logic statements, and methods since they have unique styles
if (infoCube.flag_transformer)
{
if (infoCube.flag_isCustom)
{
plaintext += "method "+ infoCube.metadataList[1] + readSocket(infoCube);
}
else
{
plaintext += readSocket(infoCube) + " ";
}
}
//handling blocks with text
else if (infoCube.flag_isConstant && infoCube.flag_hasSocks && !infoCube.flag_robotOnly)
{
plaintext += (infoCube.ToString()).ToLower();
int slot = textFinder(infoCube);
//general case
if (!specialLoop)
{
//handling string blocks
if (infoCube.ToString().Contains("STRING"))
{
plaintext += (" \"" + textReader(infoCube, slot) + "\" ").ToLower();
}
//handling other, numerical blocks
else
{
plaintext += (" " + textReader(infoCube, slot) + " ").ToLower();
}
}
//case of for/wait for
else
{
if(source.ToString().Contains("WAIT"))
{
return " " + textReader(infoCube, slot) + ";";
}
else{
return " " + textReader(infoCube, slot);
}
}
}
//handling robot functions and constants
else if (infoCube.flag_robotOnly && (infoCube.flag_hasSocks || infoCube.ToString().Contains("GETBEARING")))
{
plaintext += translateRobotFunctions(infoCube);
}
//handling blocks with comboboxes or non-text constants
else if ((infoCube.flag_isRobotConstant || infoCube.flag_isConstant) && !infoCube.flag_hasSocks)
{
//infinity block case, to be placed into for/wait for
if (specialLoop)
{
return " -1";
}
//handling any combobox blocks
else
{
ComboBox cb = (ComboBox)infoCube.innerPane.Children.ElementAt(1);
//differentiating between the combobox types since bearing/range, direction, and others have different processes
if (infoCube.ToString().Contains("BEARING") || source.ToString().Contains("RANGE"))
//.........这里部分代码省略.........
示例6: textTransfer
//method to transfer textbox data
public static Block textTransfer(Block source, Block destination)
{
int location = textFinder(source);
if (location != -1)
{
//accounting for transferring comboboxes
if (source.ToString().Contains("DIRECTION"))
{
ComboBox x = (ComboBox)source.innerPane.Children.ElementAt(location);
int selection = x.SelectedIndex;
//copying the combobox and selection options since stupid silverlight apparently has no simple method for it that doesn't crash after opening the new box...
List<TextBlock> itemCopies = new List<TextBlock>();
for (int i = 0; i < x.Items.Count; i++)
{
x.SelectedIndex = i;
TextBlock temp = new TextBlock();
temp.Text = ((TextBlock)x.SelectionBoxItem).Text;
itemCopies.Add(temp);
}
//creating and inserting new block's combobox
ComboBox y = new ComboBox();
y.ItemsSource = itemCopies;
y.SelectedIndex = selection;//x.SelectedIndex;
destination.innerPane.Children.Add(y);
}
else
{
String text = textReader(source, location);
int dstLocation = textFinder(destination);
TextBox x = (TextBox)destination.innerPane.Children.ElementAt(dstLocation);
x.Text = text;
}
}
return destination;
}
示例7: socketFinder
//method to find and return the indices of the sockets in a block
public static List<int> socketFinder(Block source)
{
List<int> socketList = new List<int>();
List<System.Windows.UIElement> components;
//checking for logic-style blocks
if (!(source.innerPane.Children.ElementAt(0) is TextBlock))
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(0);
components = innards.Children.ToList();
}
//checking for assignment blocks and diverting accordingly
else if (source.ToString().Contains("ASSIGN") && source.innerPane.Children.Count > 2)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(2);
components = innards.Children.ToList();
}
//checking for method blocks
else if (source.flag_isCustom && source.flag_transformer)
{
//checking if in main panel or socket, based on the presence of the line number
if (source.innerPane.Children.Count == 4)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(3);
components = innards.Children.ToList();
}
else
{
//accounting for a method with no parameters
if (source.innerPane.Children.ElementAt(2) is TextBlock)
{
components = new List<UIElement>();
}
else
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(2);
components = innards.Children.ToList();
}
}
}
//all other cases
else
{
components = source.innerPane.Children.ToList();
}
//cycling through and grabbing any actual sockets in the block
for (int i = 0; i < components.Count; i++)
{
if (components.ElementAt(i) is SocketDragDropTarget)
{
socketList.Add(i);
}
}
return socketList;
}
示例8: socketMole
//these are methods used to locate blocks and sockets, as well as performing potential transfers
#region Socket Location and Transfer Methods
//method to tunnel into the block and return the socket that is at the given position
public static ListBox socketMole(Block source, int i)
{
List<System.Windows.UIElement> components;
//checking for methods
if (source.flag_isCustom && source.flag_transformer)
{
//checking if in main panel or socket based on whether the line number is present
if (source.innerPane.Children.Count == 4)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(3);
components = innards.Children.ToList();
}
else
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(2);
components = innards.Children.ToList();
}
}
//checking for assignment blocks and diverting accordingly
else if (source.ToString().Contains("ASSIGN"))
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(2);
components = innards.Children.ToList();
}
//checking for logic-style blocks
else if (source.flag_transformer)
{
//accounting for situations where the block is already transformed
if (source.innerPane.Children.ElementAt(0) is StackPanel)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(0);
components = innards.Children.ToList();
}
else
{
i++;
components = source.innerPane.Children.ToList();
}
}
else
{
components = source.innerPane.Children.ToList();
}
//getting the socket to be returned
SocketDragDropTarget SDDT = (SocketDragDropTarget)components.ElementAt(i);
ListBox listBox = (ListBox)SDDT.Content;
return listBox;
}
示例9: AddToSocket
public static void AddToSocket(Block source, int i, Block child)
{
List<System.Windows.UIElement> components;
//checking for logic-style blocks
if (!(source.innerPane.Children.ElementAt(0) is TextBlock))
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(0);
components = innards.Children.ToList();
}
//checking for assignment blocks and diverting accordingly
else if (source.ToString().Contains("ASSIGN") && source.innerPane.Children.Count > 2)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(2);
components = innards.Children.ToList();
}
//checking for method blocks
else if (source.flag_isCustom && source.flag_transformer)
{
//checking if in main panel or socket
if (source.innerPane.Children.Count == 4)
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(3);
components = innards.Children.ToList();
}
else
{
if (source.innerPane.Children.ElementAt(2) is TextBlock)
{
components = new List<UIElement>();
}
else
{
StackPanel innards = (StackPanel)source.innerPane.Children.ElementAt(2);
components = innards.Children.ToList();
}
}
}
else
{
components = source.innerPane.Children.ToList();
}
SocketDragDropTarget SDDT = (SocketDragDropTarget)components.ElementAt(i);
ListBox listBox = (ListBox)SDDT.Content;
SDDT.ResizeAndAdd(listBox, child);
}
示例10: directionalCombos
//method to change combo boxes in directional blocks
private static void directionalCombos(Block Parent, Block copyBlock)
{
ComboBox cb = (ComboBox)copyBlock.innerPane.Children.ElementAt(2);
//if turn, remove front, rear, backwards and forwards
if (Parent.ToString().Contains("TURN"))
{
Debug.WriteLine(copyBlock.innerPane.Children.ElementAt(2));
cb.Items.RemoveAt(3);
cb.Items.RemoveAt(2);
cb.Items.RemoveAt(1);
cb.Items.RemoveAt(0);
cb.SelectedItem = cb.Items.ElementAt(0);
}
//if drive, remove front,rear, left and right
else if (Parent.ToString().Contains("DRIVE"))
{
Debug.WriteLine(copyBlock.innerPane.Children.ElementAt(2));
cb.Items.RemoveAt(5);
cb.Items.RemoveAt(4);
cb.Items.RemoveAt(3);
cb.Items.RemoveAt(2);
}
//if distance, remove backwards and forwards
else if (Parent.ToString().Contains("RANGE"))
{
Debug.WriteLine(copyBlock.innerPane.Children.ElementAt(2));
cb.Items.RemoveAt(1);
cb.Items.RemoveAt(0);
cb.SelectedIndex = 0;
}
}
示例11: WriteSockets
//method to write the socket xml data
private static void WriteSockets(XmlWriter writer, Block b)
{
List<int> socketList = SocketReader.socketFinder(b);
//writing data from text boxes and combo boxes
if((b.flag_isConstant || b.flag_isRobotConstant )&& !b.ToString().Contains("RANGE"))
{
//handling basic text
if (b.flag_hasSocks )
{
int slot = SocketReader.textFinder(b);
writer.WriteStartElement("VALUE");
writer.WriteString(SocketReader.textReader(b, slot));
writer.WriteEndElement();
}
else if (b.Text.Equals("GETBEARING") || b.Text.Equals("INFINITY")) //getBearing and infinity both dont have any metadata
{
}
//handling combo boxes
else
{
ComboBox cb = (ComboBox)b.innerPane.Children.ElementAt(1);
writer.WriteStartElement("INDEX");
writer.WriteString(cb.SelectedIndex.ToString());
writer.WriteEndElement();
}
}
//handling standard sockets
else
{
foreach (int location in socketList)
{
writer.WriteStartElement("SOCKET");
ListBox socket = SocketReader.socketMole(b, location);
//ensuring the socket isn't empty
if (socket.Items.Count > 0)
{
Block infosphere = (Block)socket.Items.ElementAt(0);
//checking if block is a variable or method
if (infosphere.flag_isCustom)
{
//if (infosphere.Name.Equals("VARIABLE"))
// {
writer.WriteStartElement("BLOCK");
writer.WriteAttributeString("type", infosphere.Text); //type of block
// writer.WriteStartElement("VARIABLE");
//}
// else if (infosphere.Name.Equals("METHOD"))
// {
// writer.WriteStartElement("METHOD");
// }
writer.WriteStartElement("name");
writer.WriteString(infosphere.metadataList[1]); //name of variable
writer.WriteEndElement();
}
else
{
writer.WriteStartElement("BLOCK");
writer.WriteAttributeString("type", infosphere.Text); //type of block
//writer.WriteStartElement(infosphere.ToString());
}
WriteSockets(writer, infosphere);
writer.WriteEndElement();
}
writer.WriteEndElement();
}
}
}