It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I was wondering how can I find all the names of functions that are in the program?
Any built in method for this?
Or any hint to how can I find?
stack trace or something like that?
var allMethods = typeof(AnyClass).Assembly
.GetTypes()
.SelectMany(type => type.GetMethods());
var allMethodNames = allMethods.Select(method => method.Name);
Console.WriteLine( string.Join(Environment.NewLine, allMethodNames) );
In order to inspect many assemblies, use next code:
Assembly[] assembliesToInspect = {
typeof(AnyClass).Assembly,
typeof(ClassFromAnotherAssembly).Assembly
};
var allMethods = assembliesToInspect.SelectMany(assembly => assembly.GetTypes())
.SelectMany(type => type.GetMethods());
You can use reflection to open your program or dll and enumerate all types and for each type enumerate all their public methods.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
My problem is with Xml file, which to look :
This isn't work.
IEnumerable<XElement> stepsList = doc.Elements();
XML file
<OneGoal>
<Goal>100000</Goal>
<StepOne>ewewewe</StepOne>
<StepTwo>wee</StepTwo>
<StepThree>MY</StepThree>
<StepFour>wwwww</StepFour>
<StepFive>ddddw</StepFive>
<StepSix>fcd</StepSix>
<StepSeven>blblblfl</StepSeven>
<StepEight>z dwadddddsssssssssssss</StepEight>
<StepNine>radwds</StepNine>
<StepTen>
blblblblblblb
</StepTen>
<DateDay>18</DateDay>
<DateMonth>7</DateMonth>
<DateYear>2019</DateYear>
</OneGoal>
I want all elements to IEnumberable . Earlier all elements have name 'step'.
How about converting your flat xml to Dictionary<string,string>?
var dict = XDocument.Parse(xml)
.Element("OneGoal")
.Elements()
.ToDictionary(e => e.Name.LocalName, e => e.Value);
Console.WriteLine(dict["StepOne"]);
Use XDocument to load from a file or parse from a string.
var stepList = doc.Descendants();
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am looking for something like PHP's associative arrays that supports nesting too. For instance, I am creating a Dictionary Object like following:
System.Collections.Specialized.OrderedDictionary userRoles = new System.Collections.Specialized.OrderedDictionary();
userRoles["UserId"] = "120202";
userRoles["UserName"] = "Jhon Doe";
// 2D array Like
userRoles["UserRoles"][0] = "CAN_EDIT_LIST";
userRoles["UserRoles"][1] = "CAN_EDIT_PAGE";
Then I would like to access them by KeyNames instead of index values. Is it possible?
OrderedDictionary uses objects for both keys and values.
To achieve nesting, just set the value to be another dictionary:
userRoles["UserRoles"] = new Dictionary();
Then you can use:
((Dictionary())userRoles["UserRoles"])["MyKey"] = "My Value";
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How can I do the following in C# :
var re = /^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$/;
re.test('2013/03/05 15:22:00'); // returns true
You can use the Regex.IsMatch instead (docs).
Regex.IsMatch("2013/03/05 15:22:00", #"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$"); // true if match
The below code should get you where you want to be.
Regex rx = new Regex(#"^\d{4}(\/\d{2}){2} \d{2}(:\d{2}){2}$");
String test = "2013/03/05 15:22:00";
if (rx.IsMatch(test))
{
//Test String matches
}
else
{
//Test String does not match
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How do i find SiteMap.RootNode.ChildNames title's value equel 'test' in one line?
I don't write linq it doesn't work.
protected SiteMapNodeCollection getParentNodeTitle()
{
SiteMap.RootNode.ChildNames
}
This should do the trick:
var mySiteMap = new SiteMap();
/* Lots of code for populating your SiteMap here */
var nodeTitledTest = mySiteMap.RootNode.ChildNodes.Where(x => x.Title == "test").FirstOrDefault();
This will return the first node with a title equal to "test" or null if no such node could be found.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to put this string in my resources:
Environment.CurrentDirectory + \\Server Files\\
But whenever I load the string, the Environment.CurrentDirectory part is shown as normal text instead of the current directory path :(.
Example:
Console.WriteLine(Resources.ServerFilesLocation); // Doesn't give me a path, but just plain text.
Any runtime environment value cannot be stored as a string in resources. What you should do is create a layer between. Something like:
static class ResourceManager
{
public static string ServerFilesLocation {
get {
return String.Format(Resources.ServerFilesDirectory, Environment.CurrentDirectory);
// ServerFilesDirectory = "{0}\\Server Files\\" or something similar
}
}
}
And use it like: Console.WriteLine(ResourceManager.ServerFilesLocation);